Move all battle state from IPokemon to an ephemeral IBattlePokemon wrapper
This commit is contained in:
@@ -41,8 +41,8 @@ public class BugBiteTests
|
||||
/// real resolver with a single registered item script constructor for <see cref="BerryEffectName"/>, so
|
||||
/// eating a Berry runs a <see cref="RecordingItemScript"/> that the test can inspect.
|
||||
/// </summary>
|
||||
private static (BugBite bugBite, IExecutingMove move, IPokemon target, IHitData hitData, List<RecordingItemScript>
|
||||
createdItemScripts) CreateTestSetup(IItem? targetHeldItem, bool canSteal = true)
|
||||
private static (BugBite bugBite, IExecutingMove move, IBattlePokemon target, IHitData hitData,
|
||||
List<RecordingItemScript> createdItemScripts) CreateTestSetup(IItem? targetHeldItem, bool canSteal = true)
|
||||
{
|
||||
var bugBite = new BugBite();
|
||||
|
||||
@@ -66,17 +66,14 @@ public class BugBiteTests
|
||||
dynamicLibrary.ScriptResolver.Returns(resolver);
|
||||
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);
|
||||
var move = Substitute.For<IExecutingMove>();
|
||||
move.User.Returns(user);
|
||||
move.Battle.Returns(battle);
|
||||
|
||||
var target = Substitute.For<IPokemon>();
|
||||
var target = Substitute.For<IBattlePokemon>();
|
||||
target.HeldItem.Returns(targetHeldItem);
|
||||
if (targetHeldItem != null && canSteal)
|
||||
{
|
||||
@@ -111,7 +108,7 @@ public class BugBiteTests
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "If the target is holding a Berry, the user will eat the Berry and gain its effect."
|
||||
/// Eating the Berry removes it from the target via <see cref="IPokemon.ForceSetHeldItem"/>.
|
||||
/// Eating the Berry removes it from the target via <see cref="IBattlePokemon.ForceSetHeldItem"/>.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_TargetHoldsBerry_BerryIsRemovedFromTarget()
|
||||
@@ -202,7 +199,7 @@ public class BugBiteTests
|
||||
|
||||
/// <summary>
|
||||
/// Bulbapedia: "Bug Bite will not consume the Berry of a target that has the Ability Sticky Hold."
|
||||
/// When the Berry cannot be stolen (<see cref="IPokemon.TryStealHeldItem"/> returns false, as with
|
||||
/// When the Berry cannot be stolen (<see cref="IBattlePokemon.TryStealHeldItem"/> returns false, as with
|
||||
/// Sticky Hold), the target keeps its Berry and the effect fails.
|
||||
/// </summary>
|
||||
[Test]
|
||||
@@ -219,25 +216,4 @@ public class BugBiteTests
|
||||
await Assert.That(createdItemScripts.Count).IsEqualTo(0);
|
||||
await Assert.That(hitData.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Fail")).IsTrue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the user has no <see cref="IPokemon.BattleData"/>, the script does nothing: no Berry is eaten
|
||||
/// and the hit is not failed.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task OnSecondaryEffect_UserHasNoBattleData_DoesNothing()
|
||||
{
|
||||
// Arrange
|
||||
var (bugBite, move, target, hitData, _) = CreateTestSetup(CreateBerry());
|
||||
var user = Substitute.For<IPokemon>();
|
||||
user.BattleData.Returns((IPokemonBattleData?)null);
|
||||
move.User.Returns(user);
|
||||
|
||||
// Act
|
||||
bugBite.OnSecondaryEffect(move, target, 0);
|
||||
|
||||
// Assert
|
||||
await Assert.That(target.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "ForceSetHeldItem")).IsFalse();
|
||||
await Assert.That(hitData.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "Fail")).IsFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user