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

@@ -18,17 +18,15 @@ namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
public class HealBellTests
{
/// <summary>
/// Creates a mocked party member with a mocked <see cref="IPokemon.Volatile"/> set and
/// <see cref="IPokemon.BattleData"/>, optionally active on the battlefield and with a named ability.
/// Creates a mocked party member with a mocked <see cref="IBattlePokemon.Volatile"/> set, optionally
/// active on the battlefield and with a named ability.
/// </summary>
private static IPokemon CreatePartyMember(bool onBattlefield = false, string? abilityName = null)
private static IBattlePokemon CreatePartyMember(bool onBattlefield = false, string? abilityName = null)
{
var pokemon = Substitute.For<IPokemon>();
var pokemon = Substitute.For<IBattlePokemon>();
var volatileSet = Substitute.For<IScriptSet>();
pokemon.Volatile.Returns(volatileSet);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.IsOnBattlefield.Returns(onBattlefield);
pokemon.BattleData.Returns(battleData);
pokemon.IsOnBattlefield.Returns(onBattlefield);
if (abilityName != null)
{
var ability = Substitute.For<IAbility>();
@@ -44,23 +42,21 @@ public class HealBellTests
/// in the battle. Returns the script, the executing move and the user (which is the move's target in
/// most tests, as Heal Bell targets the user's side).
/// </summary>
private static (HealBell script, IExecutingMove move, IPokemon user) CreateTestSetup(
params IPokemon?[] otherPartyMembers)
private static (HealBell script, IExecutingMove move, IBattlePokemon user) CreateTestSetup(
params IBattlePokemon?[] otherPartyMembers)
{
var script = new HealBell();
var user = CreatePartyMember(true);
var members = new List<IPokemon?> { user };
var members = new List<IBattlePokemon?> { user };
members.AddRange(otherPartyMembers);
var party = Substitute.For<IPokemonParty>();
party.GetEnumerator().Returns(_ => members.GetEnumerator());
var battleParty = Substitute.For<IBattleParty>();
battleParty.Party.Returns(party);
battleParty.BattlePokemon.Returns(members);
var battle = Substitute.For<IBattle>();
battle.Parties.Returns(new[] { battleParty });
user.BattleData!.Battle.Returns(battle);
user.Battle.Returns(battle);
var move = Substitute.For<IExecutingMove>();
move.User.Returns(user);
@@ -69,9 +65,9 @@ public class HealBellTests
}
/// <summary>
/// Helper that checks whether a mocked Pokémon received a <see cref="IPokemon.ClearStatus"/> call.
/// Helper that checks whether a mocked Pokémon received a <see cref="IBattlePokemon.ClearStatus"/> call.
/// </summary>
private static bool ReceivedClearStatus(IPokemon pokemon) =>
private static bool ReceivedClearStatus(IBattlePokemon pokemon) =>
pokemon.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "ClearStatus");
/// <summary>
@@ -115,24 +111,6 @@ public class HealBellTests
await Assert.That(ReceivedClearStatus(strayTarget)).IsFalse();
}
/// <summary>
/// Technical test: outside of battle the user has no <see cref="IPokemon.BattleData"/>; the script
/// does nothing and does not throw.
/// </summary>
[Test]
public async Task OnSecondaryEffect_UserHasNoBattleData_DoesNothing()
{
// Arrange
var (script, move, user) = CreateTestSetup();
user.BattleData.Returns((IPokemonBattleData?)null);
// Act
script.OnSecondaryEffect(move, user, 0);
// Assert
await Assert.That(ReceivedClearStatus(user)).IsFalse();
}
/// <summary>
/// Bulbapedia (Generation VI, still applicable in Gen VII): "Inactive Pokémon are healed regardless of
/// Abilities." A party member with Soundproof that is not on the battlefield is still cured.