89 lines
3.3 KiB
C#
89 lines
3.3 KiB
C#
using PkmnLib.Dynamic.Models;
|
|
using PkmnLib.Dynamic.ScriptHandling;
|
|
using PkmnLib.Plugin.Gen7.Scripts.Moves;
|
|
using PkmnLib.Plugin.Gen7.Scripts.Pokemon;
|
|
using PkmnLib.Static.Utils;
|
|
|
|
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
|
|
|
|
/// <summary>
|
|
/// Tests for the <see cref="Grudge"/> move script.
|
|
/// Gen VII Bulbapedia behavior: "When Grudge is used, if the user faints as the direct result of an
|
|
/// attack, the move which causes the user to faint will lose all of its PP."
|
|
/// The fainting-and-PP-drain logic itself lives in the <see cref="GrudgeEffect"/> volatile; this move
|
|
/// script is responsible for attaching that volatile to the user.
|
|
/// </summary>
|
|
public class GrudgeTests
|
|
{
|
|
private static (Grudge script, IExecutingMove move, IPokemon user, IScriptSet userVolatile) CreateTestSetup()
|
|
{
|
|
var script = new Grudge();
|
|
var move = Substitute.For<IExecutingMove>();
|
|
|
|
var user = Substitute.For<IPokemon>();
|
|
var userVolatile = Substitute.For<IScriptSet>();
|
|
user.Volatile.Returns(userVolatile);
|
|
move.User.Returns(user);
|
|
|
|
return (script, move, user, userVolatile);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: "When Grudge is used" the user starts bearing a grudge — the "grudge" volatile is
|
|
/// attached to the user.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnSecondaryEffect_Always_AddsGrudgeVolatileToUser()
|
|
{
|
|
// Arrange
|
|
var (script, move, _, userVolatile) = CreateTestSetup();
|
|
|
|
// Act
|
|
script.OnSecondaryEffect(move, Substitute.For<IPokemon>(), 0);
|
|
|
|
// Assert
|
|
userVolatile.Received(1).StackOrAdd(new StringKey("grudge"), Arg.Any<Func<Script?>>());
|
|
await Assert.That(userVolatile.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "StackOrAdd")).IsTrue();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: "the move which causes the user to faint will lose all of its PP" — the instantiation
|
|
/// function passed to the volatile script set creates the <see cref="GrudgeEffect"/> script that
|
|
/// implements this.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnSecondaryEffect_GrudgeInstantiation_CreatesGrudgeEffectScript()
|
|
{
|
|
// Arrange
|
|
var (script, move, user, userVolatile) = CreateTestSetup();
|
|
user.Library.Returns(LibraryHelpers.LoadLibrary());
|
|
|
|
// Act
|
|
script.OnSecondaryEffect(move, Substitute.For<IPokemon>(), 0);
|
|
|
|
// Assert
|
|
var call = userVolatile.ReceivedCalls().First(c => c.GetMethodInfo().Name == "StackOrAdd");
|
|
var instantiation = (Func<Script?>)call.GetArguments()[1]!;
|
|
await Assert.That(instantiation() is GrudgeEffect).IsTrue();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bulbapedia: the grudge is borne by the user, not the target — the target's volatile script set is
|
|
/// left untouched.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task OnSecondaryEffect_Always_DoesNotAddVolatileToTarget()
|
|
{
|
|
// Arrange
|
|
var (script, move, _, _) = CreateTestSetup();
|
|
var target = Substitute.For<IPokemon>();
|
|
var targetVolatile = Substitute.For<IScriptSet>();
|
|
target.Volatile.Returns(targetVolatile);
|
|
|
|
// Act
|
|
script.OnSecondaryEffect(move, target, 0);
|
|
|
|
// Assert
|
|
await Assert.That(targetVolatile.ReceivedCalls().Any()).IsFalse();
|
|
}
|
|
} |