Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -54,12 +54,13 @@ public class InfestationTests
|
||||
/// <see cref="CustomTriggers.ModifyBind"/> trigger pass runs over them (the Grip Claw / Binding Band
|
||||
/// stand-in).
|
||||
/// </summary>
|
||||
private static (Infestation script, IExecutingMove move, IPokemon user, IPokemon target, ScriptSet targetVolatile,
|
||||
IBattleRandom random, IHitData hitData) CreateTestSetup(uint targetMaxHp = 80, params Script[] userScripts)
|
||||
private static (Infestation script, IExecutingMove move, IBattlePokemon user, IBattlePokemon target, ScriptSet
|
||||
targetVolatile, IBattleRandom random, IHitData hitData) CreateTestSetup(uint targetMaxHp = 80,
|
||||
params Script[] userScripts)
|
||||
{
|
||||
var script = new Infestation();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
var containers = userScripts.Select(IEnumerable<ScriptContainer> (s) => new ScriptContainer(s)).ToArray();
|
||||
user.GetScripts().Returns(_ => new ScriptIterator(containers));
|
||||
move.User.Returns(user);
|
||||
@@ -67,11 +68,9 @@ public class InfestationTests
|
||||
var random = Substitute.For<IBattleRandom>();
|
||||
var battle = Substitute.For<IBattle>();
|
||||
battle.Random.Returns(random);
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.Battle.Returns(battle);
|
||||
user.BattleData.Returns(battleData);
|
||||
user.Battle.Returns(battle);
|
||||
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var target = Substitute.For<IBattlePokemon>();
|
||||
target.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
||||
var targetVolatile = new ScriptSet(target);
|
||||
target.Volatile.Returns(targetVolatile);
|
||||
@@ -86,7 +85,7 @@ public class InfestationTests
|
||||
/// <summary>
|
||||
/// Helper to extract the damage amount from a Pokémon's received Damage calls.
|
||||
/// </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]! : null;
|
||||
@@ -185,7 +184,7 @@ public class InfestationTests
|
||||
public async Task OnEndTurn_TrappedPokemon_TakesOneEighthOfMaxHpAsDamage(uint maxHealth, uint expectedDamage)
|
||||
{
|
||||
// Arrange
|
||||
var owner = Substitute.For<IPokemon>();
|
||||
var owner = Substitute.For<IBattlePokemon>();
|
||||
owner.BoostedStats.Returns(new StatisticSet<uint>(maxHealth, 1, 1, 1, 1, 1));
|
||||
var effect = new InfestationEffect(owner, 4, 1f / 8f);
|
||||
|
||||
@@ -204,7 +203,7 @@ public class InfestationTests
|
||||
public async Task OnEndTurn_TrappedPokemon_DamageIsIndirect()
|
||||
{
|
||||
// Arrange
|
||||
var owner = Substitute.For<IPokemon>();
|
||||
var owner = Substitute.For<IBattlePokemon>();
|
||||
owner.BoostedStats.Returns(new StatisticSet<uint>(80, 1, 1, 1, 1, 1));
|
||||
var effect = new InfestationEffect(owner, 4, 1f / 8f);
|
||||
|
||||
@@ -223,7 +222,7 @@ public class InfestationTests
|
||||
public async Task PreventSelfSwitch_TrappedPokemon_CannotSwitchOut()
|
||||
{
|
||||
// Arrange
|
||||
var effect = new InfestationEffect(Substitute.For<IPokemon>(), 4, 1f / 8f);
|
||||
var effect = new InfestationEffect(Substitute.For<IBattlePokemon>(), 4, 1f / 8f);
|
||||
var prevent = false;
|
||||
|
||||
// Act
|
||||
@@ -240,7 +239,7 @@ public class InfestationTests
|
||||
public async Task PreventSelfRunAway_TrappedPokemon_CannotFlee()
|
||||
{
|
||||
// Arrange
|
||||
var effect = new InfestationEffect(Substitute.For<IPokemon>(), 4, 1f / 8f);
|
||||
var effect = new InfestationEffect(Substitute.For<IBattlePokemon>(), 4, 1f / 8f);
|
||||
var prevent = false;
|
||||
|
||||
// Act
|
||||
@@ -293,21 +292,4 @@ public class InfestationTests
|
||||
// Assert
|
||||
await Assert.That(targetVolatile.Contains(new StringKey("infestation"))).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: if the user has no <see cref="IPokemon.BattleData"/>, no effect is applied.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_UserHasNoBattleData_NoEffectAdded()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, user, target, targetVolatile, _, _) = CreateTestSetup();
|
||||
user.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(targetVolatile.Count).IsEqualTo(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user