Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -30,30 +30,28 @@ public class LastResortTests
|
||||
/// <summary>
|
||||
/// Creates a mocked user in battle that knows the given moves.
|
||||
/// </summary>
|
||||
private static IPokemon CreateUser(params ILearnedMove?[] moves)
|
||||
private static IBattlePokemon CreateUser(params ILearnedMove?[] moves)
|
||||
{
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
user.Moves.Returns(moves);
|
||||
var battle = Substitute.For<IBattle>();
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.Battle.Returns(battle);
|
||||
user.BattleData.Returns(battleData);
|
||||
user.Battle.Returns(battle);
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the battle's previous turn choices, one inner array per turn (oldest first).
|
||||
/// </summary>
|
||||
private static void SetPreviousTurns(IPokemon user, params ITurnChoice[][] turns)
|
||||
private static void SetPreviousTurns(IBattlePokemon user, params ITurnChoice[][] turns)
|
||||
{
|
||||
user.BattleData!.Battle.PreviousTurnChoices.Returns(turns.Select(IReadOnlyList<ITurnChoice> (t) => t).ToList());
|
||||
user.Battle.PreviousTurnChoices.Returns(turns.Select(IReadOnlyList<ITurnChoice> (t) => t).ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs <see cref="LastResort.PreventMoveSelection"/> for the user selecting the given Last Resort
|
||||
/// move and returns whether the selection was prevented.
|
||||
/// </summary>
|
||||
private static bool RunPreventMoveSelection(IPokemon user, ILearnedMove lastResort)
|
||||
private static bool RunPreventMoveSelection(IBattlePokemon user, ILearnedMove lastResort)
|
||||
{
|
||||
var script = new LastResort();
|
||||
var choice = new MoveChoice(user, lastResort, 0, 0);
|
||||
@@ -153,11 +151,11 @@ public class LastResortTests
|
||||
var tackle = CreateLearnedMove("tackle");
|
||||
var lastResort = CreateLearnedMove("last_resort");
|
||||
var user = CreateUser(tackle, lastResort);
|
||||
var ally = Substitute.For<IPokemon>();
|
||||
var ally = Substitute.For<IBattlePokemon>();
|
||||
SetPreviousTurns(user, [new MoveChoice(user, tackle, 0, 0)], [new SwitchChoice(user, ally)],
|
||||
[new SwitchChoice(ally, user)]);
|
||||
// The user re-entered the field during turn 3, after all three recorded turns' choices were made.
|
||||
user.BattleData!.SwitchInTurn.Returns(3u);
|
||||
user.SwitchInTurn.Returns(3u);
|
||||
|
||||
// Act
|
||||
var prevent = RunPreventMoveSelection(user, lastResort);
|
||||
@@ -200,7 +198,7 @@ public class LastResortTests
|
||||
var tackle = CreateLearnedMove("tackle");
|
||||
var lastResort = CreateLearnedMove("last_resort");
|
||||
var user = CreateUser(tackle, lastResort);
|
||||
var other = Substitute.For<IPokemon>();
|
||||
var other = Substitute.For<IBattlePokemon>();
|
||||
SetPreviousTurns(user, [new MoveChoice(other, tackle, 0, 0)]);
|
||||
|
||||
// Act
|
||||
@@ -209,25 +207,4 @@ public class LastResortTests
|
||||
// Assert
|
||||
await Assert.That(prevent).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: outside of battle (no <see cref="IPokemon.BattleData"/>) the selection is prevented
|
||||
/// instead of throwing.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task PreventMoveSelection_NoBattleData_SelectionPrevented()
|
||||
{
|
||||
// Arrange
|
||||
var tackle = CreateLearnedMove("tackle");
|
||||
var lastResort = CreateLearnedMove("last_resort");
|
||||
var user = Substitute.For<IPokemon>();
|
||||
user.Moves.Returns([tackle, lastResort]);
|
||||
user.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act
|
||||
var prevent = RunPreventMoveSelection(user, lastResort);
|
||||
|
||||
// Assert
|
||||
await Assert.That(prevent).IsTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user