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;
///
/// Tests for the 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 volatile; this move
/// script is responsible for attaching that volatile to the user.
///
public class GrudgeTests
{
private static (Grudge script, IExecutingMove move, IPokemon user, IScriptSet userVolatile) CreateTestSetup()
{
var script = new Grudge();
var move = Substitute.For();
var user = Substitute.For();
var userVolatile = Substitute.For();
user.Volatile.Returns(userVolatile);
move.User.Returns(user);
return (script, move, user, userVolatile);
}
///
/// Bulbapedia: "When Grudge is used" the user starts bearing a grudge — the "grudge" volatile is
/// attached to the user.
///
[Test]
public async Task OnSecondaryEffect_Always_AddsGrudgeVolatileToUser()
{
// Arrange
var (script, move, _, userVolatile) = CreateTestSetup();
// Act
script.OnSecondaryEffect(move, Substitute.For(), 0);
// Assert
userVolatile.Received(1).StackOrAdd(new StringKey("grudge"), Arg.Any>());
await Assert.That(userVolatile.ReceivedCalls().Any(c => c.GetMethodInfo().Name == "StackOrAdd")).IsTrue();
}
///
/// 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 script that
/// implements this.
///
[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(), 0);
// Assert
var call = userVolatile.ReceivedCalls().First(c => c.GetMethodInfo().Name == "StackOrAdd");
var instantiation = (Func