Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -17,14 +17,15 @@ namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
|
||||
public class DestinyBondTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a mocked user whose <see cref="IPokemon.Volatile"/> is a real <see cref="ScriptSet"/> so
|
||||
/// Creates a mocked user whose <see cref="IBattlePokemon.Volatile"/> is a real <see cref="ScriptSet"/> so
|
||||
/// the volatile added by the move can be inspected.
|
||||
/// </summary>
|
||||
private static (DestinyBond script, IExecutingMove move, IPokemon user, ScriptSet userVolatile) CreateTestSetup()
|
||||
private static (DestinyBond script, IExecutingMove move, IBattlePokemon user, ScriptSet userVolatile)
|
||||
CreateTestSetup()
|
||||
{
|
||||
var script = new DestinyBond();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
var userVolatile = new ScriptSet(user);
|
||||
user.Volatile.Returns(userVolatile);
|
||||
user.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
||||
@@ -36,7 +37,7 @@ public class DestinyBondTests
|
||||
/// Creates a fainting Pokémon whose battle's <see cref="BattleChoiceQueue.LastRanChoice"/> is a move
|
||||
/// choice made by the given attacker.
|
||||
/// </summary>
|
||||
private static IPokemon CreateFaintingPokemonAttackedBy(IPokemon attacker)
|
||||
private static IBattlePokemon CreateFaintingPokemonAttackedBy(IBattlePokemon attacker)
|
||||
{
|
||||
var moveChoice = Substitute.For<IMoveChoice>();
|
||||
moveChoice.User.Returns(attacker);
|
||||
@@ -45,10 +46,8 @@ public class DestinyBondTests
|
||||
|
||||
var battle = Substitute.For<IBattle>();
|
||||
battle.ChoiceQueue.Returns(queue);
|
||||
var battleData = Substitute.For<IPokemonBattleData>();
|
||||
battleData.Battle.Returns(battle);
|
||||
var pokemon = Substitute.For<IPokemon>();
|
||||
pokemon.BattleData.Returns(battleData);
|
||||
var pokemon = Substitute.For<IBattlePokemon>();
|
||||
pokemon.Battle.Returns(battle);
|
||||
return pokemon;
|
||||
}
|
||||
|
||||
@@ -61,7 +60,7 @@ public class DestinyBondTests
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, _, userVolatile) = CreateTestSetup();
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var target = Substitute.For<IBattlePokemon>();
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
@@ -119,7 +118,7 @@ public class DestinyBondTests
|
||||
{
|
||||
// Arrange
|
||||
var effect = new DestinyBondEffect();
|
||||
var attacker = Substitute.For<IPokemon>();
|
||||
var attacker = Substitute.For<IBattlePokemon>();
|
||||
attacker.BoostedStats.Returns(new StatisticSet<uint>(100, 1, 1, 1, 1, 1));
|
||||
var pokemon = CreateFaintingPokemonAttackedBy(attacker);
|
||||
|
||||
@@ -141,7 +140,7 @@ public class DestinyBondTests
|
||||
{
|
||||
// Arrange
|
||||
var effect = new DestinyBondEffect();
|
||||
var attacker = Substitute.For<IPokemon>();
|
||||
var attacker = Substitute.For<IBattlePokemon>();
|
||||
attacker.BoostedStats.Returns(new StatisticSet<uint>(100, 1, 1, 1, 1, 1));
|
||||
var pokemon = CreateFaintingPokemonAttackedBy(attacker);
|
||||
|
||||
@@ -162,7 +161,7 @@ public class DestinyBondTests
|
||||
{
|
||||
// Arrange
|
||||
var effect = new DestinyBondEffect();
|
||||
var attacker = Substitute.For<IPokemon>();
|
||||
var attacker = Substitute.For<IBattlePokemon>();
|
||||
attacker.BoostedStats.Returns(new StatisticSet<uint>(100, 1, 1, 1, 1, 1));
|
||||
var pokemon = CreateFaintingPokemonAttackedBy(attacker);
|
||||
|
||||
@@ -181,7 +180,7 @@ public class DestinyBondTests
|
||||
public async Task OnBeforeMove_UserMovesAgain_RemovesDestinyBondEffect()
|
||||
{
|
||||
// Arrange
|
||||
var user = Substitute.For<IPokemon>();
|
||||
var user = Substitute.For<IBattlePokemon>();
|
||||
var userVolatile = new ScriptSet(user);
|
||||
user.GetScripts().Returns(_ => new ScriptIterator(new List<IEnumerable<ScriptContainer>>()));
|
||||
var effect = new DestinyBondEffect();
|
||||
@@ -194,19 +193,4 @@ public class DestinyBondTests
|
||||
// Assert
|
||||
await Assert.That(userVolatile.Contains(ScriptUtils.ResolveName<DestinyBondEffect>())).IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: fainting without battle data (outside of battle) does nothing and does not throw.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnFaint_NoBattleData_DoesNotThrow()
|
||||
{
|
||||
// Arrange
|
||||
var effect = new DestinyBondEffect();
|
||||
var pokemon = Substitute.For<IPokemon>();
|
||||
pokemon.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act & Assert
|
||||
await Assert.That(() => effect.OnFaint(pokemon, DamageSource.MoveDamage)).ThrowsNothing();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user