Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper

This commit is contained in:
2026-08-28 15:20:26 +02:00
parent 942be8eaeb
commit 8a2733a0a9
859 changed files with 4408 additions and 5331 deletions

View File

@@ -12,8 +12,8 @@ namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
/// </summary>
public class FloralHealingTests
{
private static (FloralHealing script, IExecutingMove move, IPokemon target) CreateTestSetup(uint maxHp,
string? terrainName = null, bool isFainted = false, bool hasBattleData = true)
private static (FloralHealing script, IExecutingMove move, IBattlePokemon target) CreateTestSetup(uint maxHp,
string? terrainName = null, bool isFainted = false)
{
var script = new FloralHealing();
var move = Substitute.For<IExecutingMove>();
@@ -21,19 +21,10 @@ public class FloralHealingTests
var battle = Substitute.For<IBattle>();
battle.TerrainName.Returns(terrainName == null ? null : new StringKey?(new StringKey(terrainName)));
var target = Substitute.For<IPokemon>();
var target = Substitute.For<IBattlePokemon>();
target.IsFainted.Returns(isFainted);
target.BoostedStats.Returns(new StatisticSet<uint>(maxHp, 0, 0, 0, 0, 0));
if (hasBattleData)
{
var battleData = Substitute.For<IPokemonBattleData>();
battleData.Battle.Returns(battle);
target.BattleData.Returns(battleData);
}
else
{
target.BattleData.Returns((IPokemonBattleData?)null);
}
target.Battle.Returns(battle);
return (script, move, target);
}
@@ -41,7 +32,7 @@ public class FloralHealingTests
/// <summary>
/// Helper to extract the heal amount from the target's received Heal calls.
/// </summary>
private static uint? GetHealAmount(IPokemon target)
private static uint? GetHealAmount(IBattlePokemon target)
{
var call = target.ReceivedCalls().FirstOrDefault(c => c.GetMethodInfo().Name == "Heal");
return call != null ? (uint)call.GetArguments()[0]! : null;
@@ -116,7 +107,7 @@ public class FloralHealingTests
/// <summary>
/// Bulbapedia: Floral Healing "restores" HP of the target; a fainted Pokémon can no longer be healed,
/// so no heal is applied when the target <see cref="IPokemon.IsFainted"/>.
/// so no heal is applied when the target <see cref="IBattlePokemon.IsFainted"/>.
/// </summary>
[Test]
public async Task OnSecondaryEffect_TargetFainted_DoesNotHeal()
@@ -130,21 +121,4 @@ public class FloralHealingTests
// Assert
await Assert.That(target.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Heal")).IsFalse();
}
/// <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_DoesNotHeal()
{
// Arrange
var (script, move, target) = CreateTestSetup(100, hasBattleData: false);
// Act
script.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(target.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Heal")).IsFalse();
}
}