65 lines
2.3 KiB
C#
65 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Text.Json;
|
|
using PkmnLib.Dynamic.Models;
|
|
using PkmnLib.Static.Species;
|
|
using PkmnLib.Tests.Integration.Models;
|
|
|
|
namespace PkmnLib.Tests.Integration;
|
|
|
|
public class IntegrationTestRunner
|
|
{
|
|
private static IEnumerable TestCases
|
|
{
|
|
get
|
|
{
|
|
var files = Directory.GetFiles("Integration/Tests", "*.json");
|
|
var serializerOptions = new JsonSerializerOptions
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
};
|
|
foreach (var file in files)
|
|
{
|
|
var json = File.ReadAllText(file);
|
|
var test = JsonSerializer.Deserialize<IntegrationTestModel>(json, serializerOptions)!;
|
|
yield return new TestCaseData(test).SetName(test.Name).SetDescription(test.Description);
|
|
}
|
|
}
|
|
}
|
|
|
|
[TestCaseSource(nameof(TestCases))]
|
|
public void RunIntegrationTest(IntegrationTestModel test)
|
|
{
|
|
var library = LibraryHelpers.LoadLibrary();
|
|
|
|
var parties = test.BattleSetup.Parties.Select(IBattleParty (x) =>
|
|
{
|
|
var party = new PokemonParty(6);
|
|
for (var index = 0; index < x.Pokemon.Length; index++)
|
|
{
|
|
var pokemon = x.Pokemon[index];
|
|
Assert.That(library.StaticLibrary.Species.TryGet(pokemon.Species, out var species), Is.True);
|
|
var mon = new PokemonImpl(library, species!, species!.GetDefaultForm(), new AbilityIndex
|
|
{
|
|
IsHidden = false,
|
|
Index = 0,
|
|
},
|
|
pokemon.Level, 0, Gender.Genderless, 0, "hardy");
|
|
foreach (var move in pokemon.Moves)
|
|
{
|
|
mon.LearnMove(move, MoveLearnMethod.Unknown, 255);
|
|
}
|
|
|
|
party.SwapInto(mon, index);
|
|
}
|
|
|
|
return new BattlePartyImpl(party, x.Indices.Select(y => new ResponsibleIndex(y[0], y[1])).ToArray());
|
|
}).ToArray();
|
|
var battle = new BattleImpl(library, parties, test.BattleSetup.CanFlee, test.BattleSetup.NumberOfSides,
|
|
test.BattleSetup.PositionsPerSide);
|
|
|
|
foreach (var action in test.Actions)
|
|
{
|
|
action.Execute(battle);
|
|
}
|
|
}
|
|
} |