Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -19,12 +19,12 @@ public class GravityTests
|
||||
/// Creates a fully mocked test setup for Gravity tests. The battle's volatile script set is a
|
||||
/// substitute so the addition of the battle-wide gravity script can be inspected.
|
||||
/// </summary>
|
||||
private static (Gravity script, IExecutingMove move, IPokemon target, IBattle battle, IScriptSet battleVolatile)
|
||||
CreateTestSetup(params IReadOnlyList<IPokemon?>[] sidePokemon)
|
||||
private static (Gravity script, IExecutingMove move, IBattlePokemon target, IBattle battle, IScriptSet
|
||||
battleVolatile) CreateTestSetup(params IReadOnlyList<IBattlePokemon?>[] sidePokemon)
|
||||
{
|
||||
var script = new Gravity();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
move.User.Returns(Substitute.For<IPokemon>());
|
||||
move.User.Returns(Substitute.For<IBattlePokemon>());
|
||||
|
||||
var battle = Substitute.For<IBattle>();
|
||||
var battleVolatile = Substitute.For<IScriptSet>();
|
||||
@@ -37,11 +37,9 @@ public class GravityTests
|
||||
}).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, battleVolatile);
|
||||
}
|
||||
|
||||
@@ -49,9 +47,9 @@ public class GravityTests
|
||||
/// Creates a mocked Pokémon with a real <see cref="ScriptSet"/> as its volatile set, so effects can
|
||||
/// be attached and their removal inspected.
|
||||
/// </summary>
|
||||
private static (IPokemon pokemon, ScriptSet volatileSet) CreateFieldPokemon()
|
||||
private static (IBattlePokemon pokemon, ScriptSet volatileSet) CreateFieldPokemon()
|
||||
{
|
||||
var pokemon = Substitute.For<IPokemon>();
|
||||
var pokemon = Substitute.For<IBattlePokemon>();
|
||||
pokemon.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
||||
var volatileSet = new ScriptSet(pokemon);
|
||||
pokemon.Volatile.Returns(volatileSet);
|
||||
@@ -106,7 +104,7 @@ public class GravityTests
|
||||
// Arrange
|
||||
var (pokemon, volatileSet) = CreateFieldPokemon();
|
||||
volatileSet.Add(new ChargeFlyEffect(pokemon));
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IPokemon?> { pokemon });
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IBattlePokemon?> { pokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -125,7 +123,7 @@ public class GravityTests
|
||||
// Arrange
|
||||
var (pokemon, volatileSet) = CreateFieldPokemon();
|
||||
volatileSet.Add(new ChargeBounceEffect(pokemon));
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IPokemon?> { pokemon });
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IBattlePokemon?> { pokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -145,7 +143,7 @@ public class GravityTests
|
||||
// Arrange
|
||||
var (pokemon, volatileSet) = CreateFieldPokemon();
|
||||
volatileSet.Add(new ChargeSkyDropEffect(pokemon));
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IPokemon?> { pokemon });
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IBattlePokemon?> { pokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -164,7 +162,7 @@ public class GravityTests
|
||||
// Arrange
|
||||
var (pokemon, volatileSet) = CreateFieldPokemon();
|
||||
volatileSet.Add(new TelekinesisEffect());
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IPokemon?> { pokemon });
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IBattlePokemon?> { pokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -183,7 +181,7 @@ public class GravityTests
|
||||
// Arrange
|
||||
var (pokemon, volatileSet) = CreateFieldPokemon();
|
||||
volatileSet.Add(new MagnetRiseEffect());
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IPokemon?> { pokemon });
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IBattlePokemon?> { pokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -204,8 +202,8 @@ public class GravityTests
|
||||
allyVolatile.Add(new ChargeFlyEffect(allyPokemon));
|
||||
var (opposingPokemon, opposingVolatile) = CreateFieldPokemon();
|
||||
opposingVolatile.Add(new ChargeFlyEffect(opposingPokemon));
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IPokemon?> { allyPokemon },
|
||||
new List<IPokemon?> { opposingPokemon });
|
||||
var (script, move, target, _, _) = CreateTestSetup(new List<IBattlePokemon?> { allyPokemon },
|
||||
new List<IBattlePokemon?> { opposingPokemon });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -222,7 +220,7 @@ public class GravityTests
|
||||
public async Task OnSecondaryEffect_EmptyPokemonSlot_IsSkipped()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, target, _, battleVolatile) = CreateTestSetup(new List<IPokemon?> { null });
|
||||
var (script, move, target, _, battleVolatile) = CreateTestSetup(new List<IBattlePokemon?> { null });
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -230,22 +228,4 @@ public class GravityTests
|
||||
// Assert
|
||||
await Assert.That(battleVolatile.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "StackOrAdd")).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 (script, move, target, _, battleVolatile) = CreateTestSetup();
|
||||
target.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(battleVolatile.ReceivedCalls().Any()).IsFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user