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)call.GetArguments()[1]!; await Assert.That(instantiation() is GrudgeEffect).IsTrue(); } /// /// Bulbapedia: the grudge is borne by the user, not the target — the target's volatile script set is /// left untouched. /// [Test] public async Task OnSecondaryEffect_Always_DoesNotAddVolatileToTarget() { // Arrange var (script, move, _, _) = CreateTestSetup(); var target = Substitute.For(); var targetVolatile = Substitute.For(); target.Volatile.Returns(targetVolatile); // Act script.OnSecondaryEffect(move, target, 0); // Assert await Assert.That(targetVolatile.ReceivedCalls().Any()).IsFalse(); } }