Update TUnit, warning cleanup
Some checks failed
Build / Build (push) Failing after 35s

This commit is contained in:
2026-07-05 13:24:22 +02:00
parent 16a1990486
commit cc091d5327
61 changed files with 113 additions and 190 deletions

View File

@@ -3,14 +3,14 @@
"isRoot": true,
"tools": {
"husky": {
"version": "0.7.2",
"version": "0.9.1",
"commands": [
"husky"
],
"rollForward": false
},
"jetbrains.resharper.globaltools": {
"version": "2025.1.1",
"version": "2026.1.4",
"commands": [
"jb"
],

View File

@@ -27,4 +27,4 @@ jobs:
- name: Build
run: dotnet build PkmnLib.NET.slnx -c Release --nologo --verbosity quiet -p:NoWarn=CS1591
- name: Test
run: dotnet test PkmnLib.NET.slnx -c Release --nologo --no-restore --no-build -- --disable-logo
run: dotnet test --solution PkmnLib.NET.slnx -c Release --nologo --no-restore --no-build -- --disable-logo

View File

@@ -7,7 +7,6 @@
"command": "dotnet",
"args": [
"test",
"PkmnLib.NET.sln",
"--verbosity",
"minimal"
]
@@ -21,7 +20,7 @@
"args": [
"jb",
"cleanupcode",
"PkmnLib.NET.sln",
"PkmnLib.NET.slnx",
"--profile=Built-in: Reformat & Apply Syntax Style",
"--include=${args}"
],

View File

@@ -1,6 +1,5 @@
using System.CommandLine;
using System.CommandLine.Parsing;
using System.Reflection;
using PkmnLib.Dynamic.AI;
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Plugin.Gen7;
@@ -14,7 +13,7 @@ internal static class Program
{
private static List<PokemonAI>? _availableAIs;
internal static LoggingLevelSwitch LogLevelSwitch { get; } = new(LogEventLevel.Information);
internal static LoggingLevelSwitch LogLevelSwitch { get; } = new();
private static Task<int> Main(string[] args)
{

View File

@@ -2,7 +2,6 @@ using System.Collections.Concurrent;
using PkmnLib.Dynamic.AI;
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Models;
using PkmnLib.Plugin.Gen7;
using PkmnLib.Static.Species;
using PkmnLib.Static.Utils;
using Serilog;
@@ -184,10 +183,10 @@ public static class TestCommandRunner
throw new InvalidOperationException("Both Pokémon must be non-null to proceed with the battle.");
}
var taskAiOne = !battle.HasForcedTurn(pokemon1!, out var choice1)
var taskAiOne = !battle.HasForcedTurn(pokemon1, out var choice1)
? Task.Run(() => ai1.GetChoice(battle, pokemon1))
: Task.FromResult(choice1);
var taskAiTwo = !battle.HasForcedTurn(pokemon2!, out var choice2)
var taskAiTwo = !battle.HasForcedTurn(pokemon2, out var choice2)
? Task.Run(() => ai2.GetChoice(battle, pokemon2))
: Task.FromResult(choice2);
await Task.WhenAll(taskAiOne, taskAiTwo);

View File

@@ -9,6 +9,7 @@
<WarningsAsErrors>nullable</WarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>
<ImplicitUsings>enable</ImplicitUsings>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup>
<ItemGroup>

View File

@@ -3,22 +3,22 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommandLineParser" Version="2.9.1"/>
<PackageVersion Include="iluvadev.ConsoleProgressBar" Version="1.1.0"/>
<PackageVersion Include="PcgRandom" Version="1.2.0"/>
<PackageVersion Include="Serilog" Version="4.3.0"/>
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0"/>
<PackageVersion Include="ShellProgressBar" Version="5.2.0"/>
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0"/>
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta5.25306.1"/>
<PackageVersion Include="System.Text.Json" Version="8.0.5"/>
<PackageVersion Include="CSPath" Version="0.0.4"/>
<PackageVersion Include="coverlet.collector" Version="6.0.4"/>
<PackageVersion Include="NSubstitute" Version="5.3.0"/>
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17"/>
<PackageVersion Include="System.Linq.Async" Version="6.0.1"/>
<PackageVersion Include="TUnit" Version="0.25.21"/>
<PackageVersion Include="PolySharp" Version="1.15"/>
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0"/>
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="iluvadev.ConsoleProgressBar" Version="1.1.0" />
<PackageVersion Include="PcgRandom" Version="1.2.0" />
<PackageVersion Include="Serilog" Version="4.3.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="ShellProgressBar" Version="5.2.0" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta5.25306.1" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="CSPath" Version="0.0.4" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="TUnit" Version="1.58.0" />
<PackageVersion Include="PolySharp" Version="1.15" />
<PackageVersion Include="JetBrains.Annotations" Version="2026.2.0" />
</ItemGroup>
</Project>

View File

@@ -2,7 +2,7 @@ namespace PkmnLib.Dynamic.AI;
public static class AILogging
{
public static Action<string> LogHandler { get; set; } = message => { };
public static Action<string> LogHandler { get; set; } = _ => { };
public static void LogInformation(string message) => LogHandler(message);
}

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.AI;

View File

@@ -1,7 +1,7 @@
using PkmnLib.Dynamic.Events;
using PkmnLib.Dynamic.Models;
using PkmnLib.Static.Species;
namespace PkmnLib.Dynamic.Models;
namespace PkmnLib.Dynamic.Events;
public class DisplaySpeciesChangeEvent : IEventData
{

View File

@@ -226,20 +226,20 @@ public class SerializedMoves
/// <summary>
/// The moves the Pokémon can learn by leveling up.
/// </summary>
public SerializedLevelMove[]? LevelMoves { get; set; } = null!;
public SerializedLevelMove[]? LevelMoves { get; set; }
/// <summary>
/// The moves the Pokémon can learn by breeding.
/// </summary>
public string[]? EggMoves { get; set; } = null!;
public string[]? EggMoves { get; set; }
/// <summary>
/// The moves the Pokémon can learn by tutoring.
/// </summary>
public string[]? TutorMoves { get; set; } = null!;
public string[]? TutorMoves { get; set; }
/// <summary>
/// The moves the Pokémon can learn by TM.
/// </summary>
public string[]? Machine { get; set; } = null!;
public string[]? Machine { get; set; }
}

View File

@@ -1,7 +1,6 @@
using PkmnLib.Dynamic.AI.Explicit;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Static.Libraries;
namespace PkmnLib.Dynamic.Libraries;

View File

@@ -136,7 +136,7 @@ public interface IBattle : IScriptSource, IDeepCloneable, IDisposable
/// <summary>
/// Sets the current weather for the battle. If null is passed, this clears the weather.
/// A duration can be passed to set the duration of the weather in turns. This duration can be modified by
/// other scripts before the weather is set through the <see cref="Script.ChangeWeatherDuration"/> script hook.
/// other scripts before the weather is set through the <see cref="IScriptChangeWeatherDuration"/> script hook.
/// </summary>
bool SetWeather(StringKey? weatherName, int duration, EventBatchId batchId = default);
@@ -369,18 +369,18 @@ public class BattleImpl : ScriptSource, IBattle
return true;
bool IsValidForForcedTurn(ITurnChoice forcedChoice, ITurnChoice choiceToCheck)
bool IsValidForForcedTurn(ITurnChoice forcedChoiceInner, ITurnChoice choiceToCheck)
{
// If the forced choice is a move choice, we can only use it if the move is the same
if (forcedChoice is IMoveChoice forcedMove && choiceToCheck is IMoveChoice moveChoice)
if (forcedChoiceInner is IMoveChoice forcedMove && choiceToCheck is IMoveChoice moveChoiceInner)
{
return forcedMove.ChosenMove.MoveData.Name == moveChoice.ChosenMove.MoveData.Name;
return forcedMove.ChosenMove.MoveData.Name == moveChoiceInner.ChosenMove.MoveData.Name;
}
if (forcedChoice is IPassChoice && choiceToCheck is IPassChoice)
if (forcedChoiceInner is IPassChoice && choiceToCheck is IPassChoice)
{
return true; // Both are pass choices, so they are valid
}
return forcedChoice.Equals(choiceToCheck);
return forcedChoiceInner.Equals(choiceToCheck);
}
}

View File

@@ -25,7 +25,7 @@ public class BattleChoiceQueue : IDeepCloneable
/// <inheritdoc cref="BattleChoiceQueue"/>
public BattleChoiceQueue(ITurnChoice[] choices)
{
Array.Sort(choices, TurnChoiceComparer.Instance!);
Array.Sort(choices, TurnChoiceComparer.Instance);
_choices = choices;
}
@@ -144,7 +144,7 @@ public class BattleChoiceQueue : IDeepCloneable
/// </summary>
public void Remove(ITurnChoice choice)
{
var index = Array.FindIndex(_choices, _currentIndex, x => x == choice);
var index = Array.FindIndex(_choices, _currentIndex, x => Equals(x, choice));
if (index == -1)
return;
_choices[index] = null;

View File

@@ -47,5 +47,6 @@ public class FleeTurnChoice : TurnChoice, IFleeChoice
/// <inheritdoc />
public override int GetHashCode() =>
// ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
User?.GetHashCode() ?? 0;
}

View File

@@ -51,5 +51,6 @@ public class PassChoice : TurnChoice, IPassChoice
/// <inheritdoc />
public override int GetHashCode() =>
// ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
User?.GetHashCode() ?? 0;
}

View File

@@ -60,5 +60,6 @@ public class SwitchChoice : TurnChoice, ISwitchChoice
/// <inheritdoc />
public override int GetHashCode() =>
// ReSharper disable twice ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
User?.GetHashCode() ?? 0 ^ SwitchTo?.GetHashCode() ?? 0;
}

View File

@@ -1,9 +1,5 @@
using System.Diagnostics;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.Models.Choices;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Static;
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;
namespace PkmnLib.Dynamic.ScriptHandling;

View File

@@ -8,7 +8,7 @@ namespace PkmnLib.Dynamic.ScriptHandling;
public class ScriptIterator : IEnumerable<ScriptContainer>
{
private readonly IReadOnlyList<IEnumerable<ScriptContainer>> _scripts;
private int _currentIndex = 0;
private int _currentIndex;
/// <inheritdoc cref="ScriptIterator"/>
public ScriptIterator(IReadOnlyList<IEnumerable<ScriptContainer>> scripts)

View File

@@ -1,51 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PkmnLib.Static", "PkmnLib.Static\PkmnLib.Static.csproj", "{312782DA-1066-4490-BD0E-DF4DF8713B4A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PkmnLib.Tests", "PkmnLib.Tests\PkmnLib.Tests.csproj", "{42DE3095-0468-4827-AF5C-691C94BA7F92}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PkmnLib.Dynamic", "PkmnLib.Dynamic\PkmnLib.Dynamic.csproj", "{D0CBA9A9-7288-41B4-B76B-CB4F20036AB2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PkmnLib.Plugin.Gen7", "Plugins\PkmnLib.Plugin.Gen7\PkmnLib.Plugin.Gen7.csproj", "{FA5380F0-28CC-4AEC-8963-814B347A89BA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{63C1B450-DC26-444A-AEBD-15979F3EEE53}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PkmnLib.Plugin.Gen7.Tests", "Plugins\PkmnLib.Plugin.Gen7.Tests\PkmnLib.Plugin.Gen7.Tests.csproj", "{FBB53861-081F-4DAC-B006-79EE238D0DFC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFiles", "SolutionFiles", "{2B99ADF8-10E2-4A3D-906F-27DC8E312A79}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{312782DA-1066-4490-BD0E-DF4DF8713B4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{312782DA-1066-4490-BD0E-DF4DF8713B4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{312782DA-1066-4490-BD0E-DF4DF8713B4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{312782DA-1066-4490-BD0E-DF4DF8713B4A}.Release|Any CPU.Build.0 = Release|Any CPU
{42DE3095-0468-4827-AF5C-691C94BA7F92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{42DE3095-0468-4827-AF5C-691C94BA7F92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{42DE3095-0468-4827-AF5C-691C94BA7F92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{42DE3095-0468-4827-AF5C-691C94BA7F92}.Release|Any CPU.Build.0 = Release|Any CPU
{D0CBA9A9-7288-41B4-B76B-CB4F20036AB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0CBA9A9-7288-41B4-B76B-CB4F20036AB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0CBA9A9-7288-41B4-B76B-CB4F20036AB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0CBA9A9-7288-41B4-B76B-CB4F20036AB2}.Release|Any CPU.Build.0 = Release|Any CPU
{FA5380F0-28CC-4AEC-8963-814B347A89BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA5380F0-28CC-4AEC-8963-814B347A89BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA5380F0-28CC-4AEC-8963-814B347A89BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA5380F0-28CC-4AEC-8963-814B347A89BA}.Release|Any CPU.Build.0 = Release|Any CPU
{FBB53861-081F-4DAC-B006-79EE238D0DFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBB53861-081F-4DAC-B006-79EE238D0DFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBB53861-081F-4DAC-B006-79EE238D0DFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBB53861-081F-4DAC-B006-79EE238D0DFC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FA5380F0-28CC-4AEC-8963-814B347A89BA} = {63C1B450-DC26-444A-AEBD-15979F3EEE53}
{FBB53861-081F-4DAC-B006-79EE238D0DFC} = {63C1B450-DC26-444A-AEBD-15979F3EEE53}
EndGlobalSection
EndGlobal

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Libraries.DataLoaders;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling.Registry;
namespace PkmnLib.Tests.Dataloader;

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Libraries.DataLoaders;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling.Registry;
namespace PkmnLib.Tests.Dataloader;

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Libraries.DataLoaders;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling.Registry;
namespace PkmnLib.Tests.Dataloader;

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Libraries.DataLoaders;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Static.Libraries;
namespace PkmnLib.Tests.Dataloader;

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Libraries.DataLoaders;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling.Registry;
namespace PkmnLib.Tests.Dataloader;

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Libraries.DataLoaders;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Static.Libraries;
namespace PkmnLib.Tests.Dataloader;
@@ -70,9 +69,9 @@ public class SpeciesDataloaderTests
await Assert.That(species).IsNotNull();
await Assert.That(species!.TryGetForm("arceus_fighting", out var form)).IsTrue();
await Assert.That(form).IsNotNull();
await Assert.That(form!.Types).HasCount().EqualTo(1);
await Assert.That(form.Types[0].Name).IsEqualTo("fighting");
await Assert.That(form.Flags).IsEqualTo(species.GetDefaultForm().Flags);
await Assert.That(form!.Types).Count().IsEqualTo(1);
await Assert.That(form.Types[0].Name.ToString()).IsEqualTo("fighting");
await Assert.That(form.Flags).IsEquivalentTo(species.GetDefaultForm().Flags);
await Assert.That(form.BaseStats).IsEqualTo(species.GetDefaultForm().BaseStats);
}
}

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Libraries.DataLoaders;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling.Registry;
namespace PkmnLib.Tests.Dataloader;

View File

@@ -21,8 +21,8 @@ public class ChoiceQueueTests
choice2.Speed.Returns((uint)50);
var queue = new BattleChoiceQueue([choice1, choice2]);
await Assert.That(queue.Dequeue()).IsEqualTo(choice1);
await Assert.That(queue.Dequeue()).IsEqualTo(choice2);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice1);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice2);
}
[Test]
@@ -41,8 +41,8 @@ public class ChoiceQueueTests
choice2.Speed.Returns((uint)50);
var queue = new BattleChoiceQueue([choice1, choice2]);
await Assert.That(queue.Dequeue()).IsEqualTo(choice2);
await Assert.That(queue.Dequeue()).IsEqualTo(choice1);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice2);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice1);
}
[Test]
@@ -69,7 +69,7 @@ public class ChoiceQueueTests
var queue = new BattleChoiceQueue([choice1, choice2, choice3, choice4]);
var result = queue.MovePokemonChoiceNext(pokemon3);
await Assert.That(result).IsTrue();
await Assert.That(queue.Dequeue()).IsEqualTo(choice3);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice3);
}
[Test]
@@ -97,7 +97,7 @@ public class ChoiceQueueTests
queue.Dequeue();
var result = queue.MovePokemonChoiceNext(pokemon1);
await Assert.That(result).IsFalse();
await Assert.That(queue.Dequeue()).IsEqualTo(choice2);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice2);
}
[Test]
@@ -124,10 +124,10 @@ public class ChoiceQueueTests
var queue = new BattleChoiceQueue([choice1, choice2, choice3, choice4]);
var result = queue.MovePokemonChoiceLast(pokemon2);
await Assert.That(result).IsTrue();
await Assert.That(queue.Dequeue()).IsEqualTo(choice1);
await Assert.That(queue.Dequeue()).IsEqualTo(choice3);
await Assert.That(queue.Dequeue()).IsEqualTo(choice4);
await Assert.That(queue.Dequeue()).IsEqualTo(choice2);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice1);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice3);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice4);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice2);
}
[Test]
@@ -155,8 +155,8 @@ public class ChoiceQueueTests
queue.Dequeue();
var result = queue.MovePokemonChoiceLast(pokemon1);
await Assert.That(result).IsFalse();
await Assert.That(queue.Dequeue()).IsEqualTo(choice2);
await Assert.That(queue.Dequeue()).IsEqualTo(choice3);
await Assert.That(queue.Dequeue()).IsEqualTo(choice4);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice2);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice3);
await Assert.That((IMoveChoice)queue.Dequeue()!).IsEqualTo(choice4);
}
}

View File

@@ -1,4 +1,3 @@
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Models;
using PkmnLib.Static;
using PkmnLib.Static.Species;
@@ -13,7 +12,7 @@ public class PokemonStatBoostTests
var library = LibraryHelpers.LoadLibrary();
if (!library.StaticLibrary.Species.TryGet("bulbasaur", out var species))
throw new InvalidOperationException("Failed to load bulbasaur species.");
return new PokemonImpl(library, species!, species!.GetDefaultForm(), new AbilityIndex
return new PokemonImpl(library, species, species.GetDefaultForm(), new AbilityIndex
{
Index = 0,
IsHidden = false,

View File

@@ -32,10 +32,10 @@ public class SerializationTests
await Assert.That(data.Gender).IsEqualTo(Gender.Male);
await Assert.That(data.Coloring).IsEqualTo((byte)0);
await Assert.That(data.HeldItem).IsNull();
await Assert.That(data.CurrentHealth).IsEqualTo((ushort)29);
await Assert.That(data.CurrentHealth).IsEqualTo((uint)29);
await Assert.That(data.Happiness).IsEqualTo((byte)70);
await Assert.That(data.Moves).HasCount().EqualTo(4);
await Assert.That(data.Moves).Count().IsEqualTo(4);
await Assert.That(data.Moves[0]).IsNotNull();
await Assert.That(data.Moves[0]!.MoveName).IsEqualTo("tackle");
await Assert.That(data.Moves[0]!.LearnMethod).IsEqualTo(MoveLearnMethod.LevelUp);
@@ -93,7 +93,7 @@ public class SerializationTests
await Assert.That(pokemon.EffortValues).IsEqualTo(new EffortValueStatisticSet(0, 0, 0, 0, 0, 0));
await Assert.That(pokemon.Nature.Name.ToString()).IsEqualTo("hardy");
await Assert.That(pokemon.Nickname).IsEqualTo("foo");
await Assert.That(pokemon.Moves).HasCount().EqualTo(4);
await Assert.That(pokemon.Moves).Count().IsEqualTo(4);
await Assert.That(pokemon.Moves[0]).IsNotNull();
await Assert.That(pokemon.Moves[0]!.MoveData.Name.ToString()).IsEqualTo("tackle");
await Assert.That(pokemon.Moves[0]!.LearnMethod).IsEqualTo(MoveLearnMethod.LevelUp);
@@ -153,7 +153,7 @@ public class SerializationTests
await Assert.That(deserialized.Nature).IsEqualTo("hardy");
await Assert.That(deserialized.Nickname).IsEqualTo("foo");
await Assert.That(deserialized.Moves).HasCount().EqualTo(4);
await Assert.That(deserialized.Moves).Count().IsEqualTo(4);
await Assert.That(deserialized.Moves[0]).IsNotNull();
await Assert.That(deserialized.Moves[0]!.MoveName).IsEqualTo("tackle");
await Assert.That(deserialized.Moves[0]!.LearnMethod).IsEqualTo(MoveLearnMethod.LevelUp);

View File

@@ -58,7 +58,7 @@ public class IntegrationTestRunner
}
await TestContext.Current!.OutputWriter.WriteLineAsync("File: " + $"file://{test.FileName}");
TestContext.Current.AddArtifact(new Artifact
TestContext.Current.Output.AttachArtifact(new Artifact
{
File = new FileInfo(test.FileName),
DisplayName = test.Name,

View File

@@ -2,7 +2,6 @@ using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Pcg;
using PkmnLib.Dynamic.Models;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Static;
using PkmnLib.Static.Species;
@@ -60,7 +59,7 @@ public class DeepCloneTests
var clonePrivateValue =
clone.GetType().GetProperty("PrivateValue", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(clone);
await Assert.That(clonePrivateValue).IsEqualTo(1);
await Assert.That((int)clonePrivateValue!).IsEqualTo(1);
}
[Test]
@@ -72,7 +71,7 @@ public class DeepCloneTests
await Assert.That(clone).IsNotEqualTo(obj);
var clonePrivateField =
clone.GetType().GetField("_privateField", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(clone);
await Assert.That(clonePrivateField).IsEqualTo(1);
await Assert.That((int)clonePrivateField!).IsEqualTo(1);
}
[Test]
@@ -119,8 +118,8 @@ public class DeepCloneTests
var clone = battle.DeepClone();
await Assert.That(clone).IsNotEqualTo(battle);
await Assert.That(clone.Sides[0].Pokemon[0]).IsNotEqualTo(battle.Sides[0].Pokemon[0]);
await Assert.That(clone.Sides[1].Pokemon[0]).IsNotEqualTo(battle.Sides[1].Pokemon[0]);
await Assert.That(clone.Sides[0].Pokemon[0]).IsNotEqualTo(battle.Sides[0].Pokemon[0]!);
await Assert.That(clone.Sides[1].Pokemon[0]).IsNotEqualTo(battle.Sides[1].Pokemon[0]!);
await Assert.That(clone.Sides[0].Pokemon[0]!.Species).IsEqualTo(battle.Sides[0].Pokemon[0]!.Species);
await Assert.That(clone.Sides[1].Pokemon[0]!.Species).IsEqualTo(battle.Sides[1].Pokemon[0]!.Species);
@@ -129,21 +128,21 @@ public class DeepCloneTests
var pokemon = clone.Sides[0].Pokemon[0]!;
await Assert.That(pokemon).IsNotNull();
await Assert.That(pokemon).IsNotEqualTo(battle.Sides[0].Pokemon[0]);
await Assert.That(pokemon).IsNotEqualTo(battle.Sides[0].Pokemon[0]!);
await Assert.That(pokemon.BattleData).IsNotNull();
await Assert.That(pokemon.BattleData).IsNotEqualTo(battle.Sides[0].Pokemon[0]!.BattleData);
await Assert.That(pokemon.BattleData!.Battle).IsEqualTo(clone);
await Assert.That(pokemon.BattleData).IsNotEqualTo(battle.Sides[0].Pokemon[0]!.BattleData!);
await Assert.That(pokemon.BattleData!.Battle).IsEqualTo((IBattle)clone);
await Assert.That(pokemon.BattleData!.SeenOpponents).Contains(clone.Sides[1].Pokemon[0]!);
await Assert.That(pokemon.BattleData!.SeenOpponents).DoesNotContain(battle.Sides[1].Pokemon[0]!);
await Assert.That(pokemon.StatBoost.Defense).IsEqualTo((sbyte)2);
await Assert.That(pokemon.Volatile.Get<ChargeBounceEffect>()).IsNotNull();
await Assert.That(pokemon.Volatile.Get<ChargeBounceEffect>()).IsNotEqualTo(
battle.Sides[0].Pokemon[0]!.Volatile.Get<ChargeBounceEffect>());
battle.Sides[0].Pokemon[0]!.Volatile.Get<ChargeBounceEffect>()!);
var ownerGetter =
typeof(ChargeBounceEffect).GetField("_owner", BindingFlags.NonPublic | BindingFlags.Instance)!;
var owner = ownerGetter.GetValue(pokemon.Volatile.Get<ChargeBounceEffect>()!);
await Assert.That(owner).IsEqualTo(pokemon);
await Assert.That((IPokemon)owner!).IsEqualTo(pokemon);
pokemon.Volatile.Remove<ChargeBounceEffect>();
await Assert.That(pokemon.Volatile.Get<ChargeBounceEffect>()).IsNull();

View File

@@ -1,5 +1,4 @@
using PkmnLib.Static;
using TUnit.Assertions.AssertConditions.Throws;
namespace PkmnLib.Tests.Static;

View File

@@ -3,7 +3,6 @@ using System.Text.Json;
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Plugin.Gen7.Common;
using PkmnLib.Static.Moves;
using PkmnLib.Static.Utils;

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.Events;
using PkmnLib.Dynamic.Models;
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Plugin.Gen7.Scripts.Abilities;
using PkmnLib.Static.Species;
using PkmnLib.Static.Utils;
@@ -333,7 +332,7 @@ public class AftermathTests
aftermath.OnFaint(target, DamageSource.MoveDamage);
// Assert
await Assert.That(GetDamageSource(user)).IsEqualTo(DamageSource.Misc);
await Assert.That(GetDamageSource(user)!.Value).IsEqualTo(DamageSource.Misc);
}
/// <summary>

View File

@@ -1,6 +1,5 @@
using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using Assembly = System.Reflection.Assembly;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts;

View File

@@ -22,7 +22,7 @@ public class AcrobaticsTests
acrobatics.ChangeBasePower(move, target, 0, ref basePower);
// Assert
await Assert.That(basePower).IsEqualTo((byte)20);
await Assert.That(basePower).IsEqualTo((ushort)20);
}
[Test]
@@ -41,7 +41,7 @@ public class AcrobaticsTests
acrobatics.ChangeBasePower(move, target, 0, ref basePower);
// Assert
await Assert.That(basePower).IsEqualTo((byte)10);
await Assert.That(basePower).IsEqualTo((ushort)10);
}
[Test]

View File

@@ -77,7 +77,7 @@ public class BatonPassTests
script.OnSecondaryEffect(move, user, 0);
// Assert
side.Received(1).SwapPokemon((byte)1, toSwitch);
side.Received(1).SwapPokemon(1, toSwitch);
}
/// <summary>

View File

@@ -85,7 +85,7 @@ public class BeakBlastTests
// Assert
await Assert.That(capturedEvent).IsNotNull();
await Assert.That(capturedEvent!.Message).IsEqualTo("beak_blast_charge");
await Assert.That(capturedEvent.Parameters!["user"]).IsEqualTo(user);
await Assert.That((IPokemon)capturedEvent.Parameters!["user"]).IsEqualTo(user);
}
/// <summary>

View File

@@ -70,7 +70,7 @@ public class BellyDrumTests
script.OnSecondaryEffect(move, user, 0);
// Assert
await Assert.That(GetDamageCall(user)).IsEqualTo((expectedDeduction, DamageSource.Misc, true));
await Assert.That(GetDamageCall(user)!.Value).IsEqualTo((expectedDeduction, DamageSource.Misc, true));
}
/// <summary>

View File

@@ -45,7 +45,7 @@ public class BestowTests
script.OnSecondaryEffect(move, target, 0);
// Assert
target.Received(1).ForceSetHeldItem(userItem);
_ = target.Received(1).ForceSetHeldItem(userItem);
}
/// <summary>
@@ -115,7 +115,7 @@ public class BestowTests
script.OnSecondaryEffect(move, target, 0);
// Assert
target.DidNotReceive().ForceSetHeldItem(Arg.Any<IItem>());
_ = target.DidNotReceive().ForceSetHeldItem(Arg.Any<IItem>());
}
/// <summary>

View File

@@ -135,7 +135,7 @@ public class BideTests
script.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(GetDamageAmount(attacker)).IsEqualTo(expectedDamage);
await Assert.That(GetDamageAmount(attacker)!.Value).IsEqualTo(expectedDamage);
}
/// <summary>
@@ -154,7 +154,7 @@ public class BideTests
script.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(GetDamageSource(attacker)).IsEqualTo(DamageSource.MoveDamage);
await Assert.That(GetDamageSource(attacker)!.Value).IsEqualTo(DamageSource.MoveDamage);
}
/// <summary>

View File

@@ -126,7 +126,7 @@ public class BindTests
effect!.OnEndTurn(target, Substitute.For<IBattle>());
// Assert
await Assert.That(GetDamageAmount(target)).IsEqualTo(expectedDamage);
await Assert.That(GetDamageAmount(target)!.Value).IsEqualTo(expectedDamage);
}
/// <summary>
@@ -193,7 +193,7 @@ public class BindTests
effect!.OnEndTurn(target, Substitute.For<IBattle>());
// Assert
await Assert.That(GetDamageAmount(target)).IsEqualTo(expectedDamage);
await Assert.That(GetDamageAmount(target)!.Value).IsEqualTo(expectedDamage);
}
/// <summary>

View File

@@ -3,7 +3,6 @@ using PkmnLib.Dynamic.ScriptHandling;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Plugin.Gen7.Scripts.Side;
using PkmnLib.Static.Utils;
using TUnit.Assertions.AssertConditions.Throws;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;

View File

@@ -2,7 +2,6 @@ using PkmnLib.Dynamic.Models;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Static;
using PkmnLib.Static.Utils;
using TUnit.Assertions.AssertConditions.Throws;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;

View File

@@ -80,7 +80,7 @@ public class DrainTests
drain.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(GetHealAmount(user)).IsEqualTo(50u);
await Assert.That(GetHealAmount(user)!.Value).IsEqualTo(50u);
}
/// <summary>
@@ -97,7 +97,7 @@ public class DrainTests
drain.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(GetHealAmount(user)).IsEqualTo(expectedHeal);
await Assert.That(GetHealAmount(user)!.Value).IsEqualTo(expectedHeal);
}
/// <summary>
@@ -115,7 +115,7 @@ public class DrainTests
drain.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(GetHealAmount(user)).IsEqualTo(1u);
await Assert.That(GetHealAmount(user)!.Value).IsEqualTo(1u);
}
/// <summary>
@@ -132,7 +132,7 @@ public class DrainTests
drain.OnSecondaryEffect(move, target, 0);
// Assert - 65% of 100 damage
await Assert.That(GetHealAmount(user)).IsEqualTo(65u);
await Assert.That(GetHealAmount(user)!.Value).IsEqualTo(65u);
}
/// <summary>
@@ -149,7 +149,7 @@ public class DrainTests
drain.OnSecondaryEffect(move, target, 0);
// Assert - user takes the 50 HP it would have gained, and is not healed
await Assert.That(GetDamageAmount(user)).IsEqualTo(50u);
await Assert.That(GetDamageAmount(user)!.Value).IsEqualTo(50u);
await Assert.That(user.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Heal")).IsFalse();
}
@@ -167,7 +167,7 @@ public class DrainTests
drain.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(GetDamageSource(user)).IsEqualTo(DamageSource.Misc);
await Assert.That(GetDamageSource(user)!.Value).IsEqualTo(DamageSource.Misc);
}
/// <summary>
@@ -184,7 +184,7 @@ public class DrainTests
drain.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(GetDamageAmount(user)).IsEqualTo(65u);
await Assert.That(GetDamageAmount(user)!.Value).IsEqualTo(65u);
}
/// <summary>
@@ -238,6 +238,6 @@ public class DrainTests
drain.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(GetHealAmount(user)).IsEqualTo(50u);
await Assert.That(GetHealAmount(user)!.Value).IsEqualTo(50u);
}
}

View File

@@ -9,7 +9,7 @@ namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
public class HiddenPowerTests
{
public record TestCaseData(IndividualValueStatisticSet Ivs, StringKey ExpectedType, byte ExpectedPower)
public record TestCaseData(IndividualValueStatisticSet Ivs, StringKey ExpectedType, ushort ExpectedPower)
{
/// <inheritdoc />
public override string ToString() =>

View File

@@ -86,6 +86,6 @@ public class MultiAttackTests
multiAttack.ChangeMoveType(move, target, 0, ref typeIdentifier);
// Assert
await Assert.That(typeIdentifier!.Value.Name).IsEqualTo(test.ExpectedTypeName);
await Assert.That(typeIdentifier!.Value.Name.ToString()).IsEqualTo(test.ExpectedTypeName);
}
}

View File

@@ -1,5 +1,4 @@
using PkmnLib.Dynamic.AI.Explicit;
using PkmnLib.Plugin.Gen7.Scripts.Moves;
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
using PkmnLib.Plugin.Gen7.Scripts.Side;
using PkmnLib.Plugin.Gen7.Scripts.Status;

View File

@@ -1,5 +1,3 @@
using PkmnLib.Plugin.Gen7.Common;
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>

View File

@@ -6,7 +6,7 @@ namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <see href="https://bulbapedia.bulbagarden.net/wiki/RKS_System_(Ability)">Bulbapedia - RKS System</see>
/// </summary>
[Script(ScriptCategory.Ability, "rks_system")]
public class RKSSystem : Script, IScriptOnAfterHeldItemChange
public class RksSystem : Script, IScriptOnAfterHeldItemChange
{
/// <inheritdoc />
public void OnAfterHeldItemChange(IPokemon pokemon, IItem? previous, IItem? item)

View File

@@ -1,5 +1,3 @@
using PkmnLib.Plugin.Gen7.Common;
namespace PkmnLib.Plugin.Gen7.Scripts.Abilities;
/// <summary>

View File

@@ -6,7 +6,7 @@ public class KnockOff : Script, IScriptOnSecondaryEffect
/// <inheritdoc />
public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)
{
if (!target.TryStealHeldItem(out var item))
if (!target.TryStealHeldItem(out _))
{
move.GetHitData(target, hit).Fail();
}

View File

@@ -3,7 +3,7 @@ using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;
[Script(ScriptCategory.Move, "magma_storm")]
public class MagmaStorm : MultiHitMove
public class MagmaStorm : MultiHitMove, IScriptOnSecondaryEffect
{
/// <inheritdoc />
public void OnSecondaryEffect(IExecutingMove move, IPokemon target, byte hit)

View File

@@ -1,5 +1,4 @@
using PkmnLib.Plugin.Gen7.Scripts.Utils;
using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Scripts.Moves;

View File

@@ -1,5 +1,3 @@
using PkmnLib.Plugin.Gen7.Common;
namespace PkmnLib.Plugin.Gen7.Scripts.Pokemon;
[Script(ScriptCategory.Pokemon, "protect")]

View File

@@ -30,7 +30,7 @@ public class PursuitEffect : Script, IScriptOnSwitchOut
var choiceQueue = battleData.Battle.ChoiceQueue;
var choice = choiceQueue?.FirstOrDefault(x => x == _choice);
var choice = choiceQueue?.FirstOrDefault(x => Equals(x, _choice));
if (choice == null)
return;
choiceQueue!.Remove(choice);

View File

@@ -1,5 +1,3 @@
using PkmnLib.Plugin.Gen7.Common;
namespace PkmnLib.Plugin.Gen7.Scripts.Status;
[Script(ScriptCategory.Status, "frozen")]

View File

@@ -1,8 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
[Script(ScriptCategory.Weather, "desolate_lands")]
public class DesolateLands : HarshSunlight, IScriptFailMove, IScriptOnEndTurn, IScriptOnSwitchOut,
IScriptPreventWeatherChange
public class DesolateLands : HarshSunlight, IScriptFailMove, IScriptOnSwitchOut, IScriptPreventWeatherChange
{
private readonly HashSet<IPokemon> _placers = [];

View File

@@ -1,7 +1,7 @@
namespace PkmnLib.Plugin.Gen7.Scripts.Weather;
[Script(ScriptCategory.Weather, "primordial_sea")]
public class PrimordialSea : Rain, IScriptFailMove, IScriptOnEndTurn, IScriptOnSwitchOut, IScriptPreventWeatherChange
public class PrimordialSea : Rain, IScriptFailMove, IScriptOnSwitchOut, IScriptPreventWeatherChange
{
private HashSet<IPokemon> _placers = new();

5
global.json Normal file
View File

@@ -0,0 +1,5 @@
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}