Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -15,14 +15,12 @@ public class FlameBurstTests
|
||||
/// <summary>
|
||||
/// Creates a mocked battle Pokémon that lives in <paramref name="battle"/> on the given side and position.
|
||||
/// </summary>
|
||||
private static IPokemon CreateBattlePokemon(IBattle battle, byte sideIndex, byte position, uint maxHp = 100)
|
||||
private static IBattlePokemon CreateBattlePokemon(IBattle battle, byte sideIndex, byte position, uint maxHp = 100)
|
||||
{
|
||||
var pokemon = Substitute.For<IPokemon>();
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.Battle.Returns(battle);
|
||||
battleData.SideIndex.Returns(sideIndex);
|
||||
battleData.Position.Returns(position);
|
||||
pokemon.BattleData.Returns(battleData);
|
||||
var pokemon = Substitute.For<IBattlePokemon>();
|
||||
pokemon.Battle.Returns(battle);
|
||||
pokemon.SideIndex.Returns(sideIndex);
|
||||
pokemon.Position.Returns(position);
|
||||
pokemon.BoostedStats.Returns(new StatisticSet<uint>(maxHp, 0, 0, 0, 0, 0));
|
||||
pokemon.MaxHealth.Returns(maxHp);
|
||||
return pokemon;
|
||||
@@ -31,7 +29,7 @@ public class FlameBurstTests
|
||||
/// <summary>
|
||||
/// Configures the two sides of <paramref name="battle"/> with the given Pokémon lists.
|
||||
/// </summary>
|
||||
private static void SetSides(IBattle battle, List<IPokemon?> side0Pokemon, List<IPokemon?> side1Pokemon)
|
||||
private static void SetSides(IBattle battle, List<IBattlePokemon?> side0Pokemon, List<IBattlePokemon?> side1Pokemon)
|
||||
{
|
||||
var side0 = Substitute.For<IBattleSide>();
|
||||
side0.Pokemon.Returns(side0Pokemon);
|
||||
@@ -44,8 +42,8 @@ public class FlameBurstTests
|
||||
/// Creates a fully mocked double battle: the user and its ally on side 0, the target and its ally on
|
||||
/// side 1. Flame Burst is used by the user against the target.
|
||||
/// </summary>
|
||||
private static (FlameBurst script, IExecutingMove move, IPokemon user, IPokemon userAlly, IPokemon target, IPokemon
|
||||
targetAlly) CreateDoubleBattleSetup(uint targetAllyMaxHp = 160)
|
||||
private static (FlameBurst script, IExecutingMove move, IBattlePokemon user, IBattlePokemon userAlly, IBattlePokemon
|
||||
target, IBattlePokemon targetAlly) CreateDoubleBattleSetup(uint targetAllyMaxHp = 160)
|
||||
{
|
||||
var script = new FlameBurst();
|
||||
var battle = Substitute.For<IBattle>();
|
||||
@@ -66,7 +64,7 @@ public class FlameBurstTests
|
||||
/// <summary>
|
||||
/// Helper to extract the damage amount from a Pokémon's received Damage calls, or 0 if none was received.
|
||||
/// </summary>
|
||||
private static uint GetDamageAmount(IPokemon pokemon)
|
||||
private static uint GetDamageAmount(IBattlePokemon pokemon)
|
||||
{
|
||||
var call = pokemon.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "Damage");
|
||||
return call != null ? (uint)call.GetArguments()[0]! : 0;
|
||||
@@ -75,7 +73,7 @@ public class FlameBurstTests
|
||||
/// <summary>
|
||||
/// Helper to extract the damage source from a Pokémon's received Damage calls.
|
||||
/// </summary>
|
||||
private static DamageSource? GetDamageSource(IPokemon pokemon)
|
||||
private static DamageSource? GetDamageSource(IBattlePokemon pokemon)
|
||||
{
|
||||
var call = pokemon.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "Damage");
|
||||
return call != null ? (DamageSource)call.GetArguments()[1]! : null;
|
||||
@@ -84,7 +82,7 @@ public class FlameBurstTests
|
||||
/// <summary>
|
||||
/// Helper that checks whether a Pokémon received any Damage call.
|
||||
/// </summary>
|
||||
private static bool WasDamaged(IPokemon pokemon) =>
|
||||
private static bool WasDamaged(IBattlePokemon pokemon) =>
|
||||
pokemon.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Damage");
|
||||
|
||||
/// <summary>
|
||||
@@ -266,23 +264,4 @@ public class FlameBurstTests
|
||||
// Act & Assert
|
||||
await Assert.That(() => script.OnSecondaryEffect(move, target, 0)).ThrowsNothing();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: when no battle data is available the script does nothing instead of throwing.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_NoBattleData_DoesNotThrow()
|
||||
{
|
||||
// Arrange
|
||||
var script = new FlameBurst();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var user = Substitute.For<IPokemon>();
|
||||
user.BattleData.Returns((IPokemonBattleData?)null);
|
||||
move.User.Returns(user);
|
||||
var target = Substitute.For<IPokemon>();
|
||||
target.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act & Assert
|
||||
await Assert.That(() => script.OnSecondaryEffect(move, target, 0)).ThrowsNothing();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user