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,8 +18,8 @@ public class BurnUpTests
/// <see cref="TypeLibrary"/> with "fire" and "water" registered. The user is a Water-type, optionally
/// also carrying the Fire type.
/// </summary>
private static (BurnUp burnUp, IExecutingMove move, IPokemon user, IPokemon target, IHitData hitData, TypeIdentifier
fireType) CreateTestSetup(bool userIsFireType, bool userIsFrozen = false)
private static (BurnUp burnUp, IExecutingMove move, IBattlePokemon user, IBattlePokemon target, IHitData hitData,
TypeIdentifier fireType) CreateTestSetup(bool userIsFireType, bool userIsFrozen = false)
{
var burnUp = new BurnUp();
@@ -33,11 +33,9 @@ public class BurnUpTests
dynamicLibrary.StaticLibrary.Returns(staticLibrary);
var battle = Substitute.For<IBattle>();
battle.Library.Returns(dynamicLibrary);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.Battle.Returns(battle);
var user = Substitute.For<IPokemon>();
user.BattleData.Returns(battleData);
var user = Substitute.For<IBattlePokemon>();
user.Battle.Returns(battle);
user.Types.Returns(userIsFireType
? new List<TypeIdentifier> { fireType, waterType }
: new List<TypeIdentifier> { waterType });
@@ -46,7 +44,7 @@ public class BurnUpTests
var move = Substitute.For<IExecutingMove>();
move.User.Returns(user);
var target = Substitute.For<IPokemon>();
var target = Substitute.For<IBattlePokemon>();
var hitData = Substitute.For<IHitData>();
move.GetHitData(target, 0).Returns(hitData);
@@ -54,9 +52,9 @@ public class BurnUpTests
}
/// <summary>
/// Helper that checks whether <see cref="IPokemon.RemoveType"/> was called with the given type.
/// Helper that checks whether <see cref="IBattlePokemon.RemoveType"/> was called with the given type.
/// </summary>
private static bool ReceivedRemoveType(IPokemon user, TypeIdentifier type) =>
private static bool ReceivedRemoveType(IBattlePokemon user, TypeIdentifier type) =>
user.ReceivedCalls().Any(c =>
c.GetMethodInfo().Name == "RemoveType" && type.Equals((TypeIdentifier)c.GetArguments()[0]!));
@@ -177,23 +175,4 @@ public class BurnUpTests
// Assert
await Assert.That(user.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "ClearStatus")).IsFalse();
}
/// <summary>
/// If the user has no <see cref="IPokemon.BattleData"/>, the script does nothing: no type is removed
/// and the hit is not failed.
/// </summary>
[Test]
public async Task OnSecondaryEffect_UserHasNoBattleData_DoesNothing()
{
// Arrange
var (burnUp, move, user, target, hitData, _) = CreateTestSetup(true);
user.BattleData.Returns((IPokemonBattleData?)null);
// Act
burnUp.OnSecondaryEffect(move, target, 0);
// Assert
await Assert.That(user.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "RemoveType")).IsFalse();
await Assert.That(hitData.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Fail")).IsFalse();
}
}