Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -17,13 +17,13 @@ public class FlareBlitzTests
|
||||
/// Creates a fully mocked test setup for Flare Blitz tests, where the hit dealt
|
||||
/// <paramref name="damage"/> damage to the target.
|
||||
/// </summary>
|
||||
private static (FlareBlitz script, IExecutingMove move, IPokemon user, IPokemon target, IBattleRandom random)
|
||||
CreateTestSetup(uint damage, Script[]? moveScripts = null)
|
||||
private static (FlareBlitz script, IExecutingMove move, IBattlePokemon user, IBattlePokemon target, IBattleRandom
|
||||
random) CreateTestSetup(uint damage, Script[]? moveScripts = null)
|
||||
{
|
||||
var script = new FlareBlitz();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
var target = Substitute.For<IBattlePokemon>();
|
||||
|
||||
var hitData = Substitute.For<IHitData>();
|
||||
hitData.Damage.Returns(damage);
|
||||
@@ -32,9 +32,7 @@ public class FlareBlitzTests
|
||||
var battle = Substitute.For<IBattle>();
|
||||
var random = Substitute.For<IBattleRandom>();
|
||||
battle.Random.Returns(random);
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.Battle.Returns(battle);
|
||||
target.BattleData.Returns(battleData);
|
||||
target.Battle.Returns(battle);
|
||||
|
||||
// RunScriptHook iterates the move's scripts; give the mock a real iterator so the hook pass runs
|
||||
// (empty unless the test attaches scripts such as Rock Head).
|
||||
@@ -50,7 +48,7 @@ public class FlareBlitzTests
|
||||
/// <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;
|
||||
@@ -59,7 +57,7 @@ public class FlareBlitzTests
|
||||
/// <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;
|
||||
@@ -68,7 +66,7 @@ public class FlareBlitzTests
|
||||
/// <summary>
|
||||
/// Helper that checks whether a Pokémon received a SetStatus call for the given status.
|
||||
/// </summary>
|
||||
private static bool ReceivedSetStatus(IPokemon pokemon, string status) =>
|
||||
private static bool ReceivedSetStatus(IBattlePokemon pokemon, string status) =>
|
||||
pokemon.ReceivedCalls().Any(c =>
|
||||
c.GetMethodInfo().Name == "SetStatus" && (StringKey)c.GetArguments()[0]! == new StringKey(status));
|
||||
|
||||
@@ -212,23 +210,4 @@ public class FlareBlitzTests
|
||||
// Assert
|
||||
await Assert.That(ReceivedSetStatus(target, "burned")).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: when the target has no <see cref="IPokemon.BattleData"/>, the script does nothing;
|
||||
/// no recoil is taken and no burn is rolled.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_TargetHasNoBattleData_NoRecoilOrBurn()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, user, target, _) = CreateTestSetup(90);
|
||||
target.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(user.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Damage")).IsFalse();
|
||||
await Assert.That(ReceivedSetStatus(target, "burned")).IsFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user