Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -24,12 +24,12 @@ public class FlowerShieldTests
|
||||
library.StaticLibrary.Types.TryGetTypeIdentifier("water", out WaterType);
|
||||
}
|
||||
|
||||
private static (FlowerShield script, IExecutingMove move, IPokemon target, IBattle battle) CreateTestSetup(
|
||||
params IReadOnlyList<IPokemon?>[] sidePokemon)
|
||||
private static (FlowerShield script, IExecutingMove move, IBattlePokemon target, IBattle battle) CreateTestSetup(
|
||||
params IReadOnlyList<IBattlePokemon?>[] sidePokemon)
|
||||
{
|
||||
var script = new FlowerShield();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
move.User.Returns(user);
|
||||
|
||||
var library = LibraryHelpers.LoadLibrary();
|
||||
@@ -43,23 +43,21 @@ public class FlowerShieldTests
|
||||
}).ToArray();
|
||||
battle.Sides.Returns(sides);
|
||||
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.Battle.Returns(battle);
|
||||
var target = Substitute.For<IPokemon>();
|
||||
target.BattleData.Returns(battleData);
|
||||
var target = Substitute.For<IBattlePokemon>();
|
||||
|
||||
target.Battle.Returns(battle);
|
||||
return (script, move, target, battle);
|
||||
}
|
||||
|
||||
private static IPokemon CreatePokemon(TypeIdentifier type, bool isFainted = false)
|
||||
private static IBattlePokemon CreatePokemon(TypeIdentifier type, bool isFainted = false)
|
||||
{
|
||||
var pokemon = Substitute.For<IPokemon>();
|
||||
var pokemon = Substitute.For<IBattlePokemon>();
|
||||
pokemon.Types.Returns(new[] { type });
|
||||
pokemon.IsFainted.Returns(isFainted);
|
||||
return pokemon;
|
||||
}
|
||||
|
||||
private static bool ReceivedStatBoost(IPokemon pokemon) =>
|
||||
private static bool ReceivedStatBoost(IBattlePokemon pokemon) =>
|
||||
pokemon.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "ChangeStatBoost");
|
||||
|
||||
/// <summary>
|
||||
@@ -68,7 +66,7 @@ public class FlowerShieldTests
|
||||
/// the trailing <see cref="EventBatchId"/> parameter cannot be bound by <c>Arg.Any</c> (its
|
||||
/// parameterless constructor initializes a fresh id, so it never equals the matcher's default value).
|
||||
/// </summary>
|
||||
private static object?[]? GetStatBoostArgs(IPokemon pokemon)
|
||||
private static object?[]? GetStatBoostArgs(IBattlePokemon pokemon)
|
||||
{
|
||||
var call = pokemon.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "ChangeStatBoost");
|
||||
return call?.GetArguments();
|
||||
@@ -83,7 +81,7 @@ public class FlowerShieldTests
|
||||
{
|
||||
// Arrange
|
||||
var grassPokemon = CreatePokemon(GrassType);
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IPokemon?> { grassPokemon });
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IBattlePokemon?> { grassPokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -107,8 +105,8 @@ public class FlowerShieldTests
|
||||
// Arrange
|
||||
var allyGrass = CreatePokemon(GrassType);
|
||||
var opposingGrass = CreatePokemon(GrassType);
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IPokemon?> { allyGrass },
|
||||
new List<IPokemon?> { opposingGrass });
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IBattlePokemon?> { allyGrass },
|
||||
new List<IBattlePokemon?> { opposingGrass });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -127,7 +125,7 @@ public class FlowerShieldTests
|
||||
{
|
||||
// Arrange
|
||||
var waterPokemon = CreatePokemon(WaterType);
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IPokemon?> { waterPokemon });
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IBattlePokemon?> { waterPokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -145,7 +143,7 @@ public class FlowerShieldTests
|
||||
{
|
||||
// Arrange
|
||||
var faintedGrass = CreatePokemon(GrassType, true);
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IPokemon?> { faintedGrass });
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IBattlePokemon?> { faintedGrass });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -167,7 +165,7 @@ public class FlowerShieldTests
|
||||
user.Types.Returns(new[] { GrassType });
|
||||
user.IsFainted.Returns(false);
|
||||
var side = Substitute.For<IBattleSide>();
|
||||
side.Pokemon.Returns(new List<IPokemon?> { user });
|
||||
side.Pokemon.Returns(new List<IBattlePokemon?> { user });
|
||||
battle.Sides.Returns(new[] { side });
|
||||
|
||||
// Act
|
||||
@@ -195,7 +193,7 @@ public class FlowerShieldTests
|
||||
var flyingGrassVolatile = new ScriptSet(flyingGrass);
|
||||
flyingGrassVolatile.Add(new ChargeFlyEffect(flyingGrass));
|
||||
flyingGrass.Volatile.Returns(flyingGrassVolatile);
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IPokemon?> { flyingGrass });
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IBattlePokemon?> { flyingGrass });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -213,7 +211,7 @@ public class FlowerShieldTests
|
||||
{
|
||||
// Arrange
|
||||
var waterPokemon = CreatePokemon(WaterType);
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IPokemon?> { waterPokemon });
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IBattlePokemon?> { waterPokemon });
|
||||
var hitData = Substitute.For<IHitData>();
|
||||
move.GetHitData(target, 0).Returns(hitData);
|
||||
|
||||
@@ -232,7 +230,7 @@ public class FlowerShieldTests
|
||||
{
|
||||
// Arrange
|
||||
var grassPokemon = CreatePokemon(GrassType);
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IPokemon?> { null, grassPokemon });
|
||||
var (script, move, target, _) = CreateTestSetup(new List<IBattlePokemon?> { null, grassPokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -240,24 +238,4 @@ public class FlowerShieldTests
|
||||
// Assert
|
||||
await Assert.That(ReceivedStatBoost(grassPokemon)).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: when the target has no <see cref="IPokemon.BattleData"/> (it is not in a battle),
|
||||
/// the script does nothing instead of throwing.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_NullBattleData_DoesNothing()
|
||||
{
|
||||
// Arrange
|
||||
var grassPokemon = CreatePokemon(GrassType);
|
||||
var (script, move, _, _) = CreateTestSetup(new List<IPokemon?> { grassPokemon });
|
||||
var target = Substitute.For<IPokemon>();
|
||||
target.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(ReceivedStatBoost(grassPokemon)).IsFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user