Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -39,8 +39,9 @@ public class EncoreTests
|
||||
/// Creates a fully mocked test setup where the target's volatile scripts are a real
|
||||
/// <see cref="ScriptSet"/> and its last used move is the given one (or none).
|
||||
/// </summary>
|
||||
private static (Encore script, IExecutingMove move, IPokemon target, IScriptSet targetVolatile, IHitData hitData)
|
||||
CreateTestSetup(string? lastUsedMove, bool lastMoveIsReplacement = false, bool lastMoveCantRepeat = false)
|
||||
private static (Encore script, IExecutingMove move, IBattlePokemon target, IScriptSet targetVolatile, IHitData
|
||||
hitData) CreateTestSetup(string? lastUsedMove, bool lastMoveIsReplacement = false,
|
||||
bool lastMoveCantRepeat = false)
|
||||
{
|
||||
var script = new Encore();
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
@@ -52,16 +53,14 @@ public class EncoreTests
|
||||
var battle = Substitute.For<IBattle>();
|
||||
battle.Library.Returns(library);
|
||||
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var target = Substitute.For<IBattlePokemon>();
|
||||
target.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
|
||||
IScriptSet targetVolatile = new ScriptSet(target);
|
||||
target.Volatile.Returns(targetVolatile);
|
||||
var targetBattleData = Substitute.For<IPokemonBattleData>();
|
||||
// Create the choice before the Returns call; configuring substitutes inside Returns is not allowed.
|
||||
var lastMoveChoice = lastUsedMove == null ? null : CreateMoveChoice(lastUsedMove, lastMoveCantRepeat);
|
||||
targetBattleData.LastMoveChoice.Returns(lastMoveChoice);
|
||||
targetBattleData.Battle.Returns(battle);
|
||||
target.BattleData.Returns(targetBattleData);
|
||||
target.LastMoveChoice.Returns(lastMoveChoice);
|
||||
target.Battle.Returns(battle);
|
||||
if (lastMoveChoice != null)
|
||||
miscLibrary.IsReplacementChoice(lastMoveChoice).Returns(lastMoveIsReplacement);
|
||||
|
||||
@@ -165,25 +164,6 @@ public class EncoreTests
|
||||
await Assert.That(moveData!.HasFlag(MoveFlags.CantRepeat)).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Technical test: without battle data on the target (outside of battle) the effect does nothing and
|
||||
/// does not throw.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_TargetHasNoBattleData_DoesNothing()
|
||||
{
|
||||
// Arrange
|
||||
var (script, move, target, targetVolatile, hitData) = CreateTestSetup("tackle");
|
||||
target.BattleData.Returns((IPokemonBattleData?)null);
|
||||
|
||||
// Act
|
||||
script.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
hitData.DidNotReceive().Fail();
|
||||
await Assert.That(targetVolatile.Contains(ScriptUtils.ResolveName<EncoreEffect>())).IsFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "Duration standardized to exactly 3 turns" (Generation V onward). After two
|
||||
/// end-of-turn ticks the effect is still active.
|
||||
@@ -192,7 +172,7 @@ public class EncoreTests
|
||||
public async Task OnEndTurn_TwoTurnsPassed_EffectStillActive()
|
||||
{
|
||||
// Arrange
|
||||
var owner = Substitute.For<IPokemon>();
|
||||
var owner = Substitute.For<IBattlePokemon>();
|
||||
owner.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
|
||||
IScriptSet ownerVolatile = new ScriptSet(owner);
|
||||
var effect = new EncoreEffect(owner, new StringKey("tackle"), 3);
|
||||
@@ -214,7 +194,7 @@ public class EncoreTests
|
||||
public async Task OnEndTurn_ThreeTurnsPassed_EffectRemovesItself()
|
||||
{
|
||||
// Arrange
|
||||
var owner = Substitute.For<IPokemon>();
|
||||
var owner = Substitute.For<IBattlePokemon>();
|
||||
owner.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
|
||||
IScriptSet ownerVolatile = new ScriptSet(owner);
|
||||
var effect = new EncoreEffect(owner, new StringKey("tackle"), 3);
|
||||
|
||||
Reference in New Issue
Block a user