using PkmnLib.Dynamic.Models; using PkmnLib.Dynamic.ScriptHandling; using PkmnLib.Dynamic.ScriptHandling.Registry; using PkmnLib.Plugin.Gen7.Scripts.Moves; using PkmnLib.Plugin.Gen7.Scripts.Pokemon; namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves; /// /// Tests for the move script. /// Gen VII Bulbapedia behavior: "Fake Out inflicts damage and always makes the target flinch, unless it has /// the Ability Inner Focus or Shield Dust." and "Fake Out will fail if not used on the first turn the user /// is out." /// public class FakeOutTests { /// /// Creates a fully mocked test setup where the user switched in on the given turn and the battle is /// currently on the given turn. /// private static (FakeOut script, IExecutingMove move) CreateStopSetup(uint switchInTurn, uint currentTurn) { var script = new FakeOut(); var move = Substitute.For(); var battle = Substitute.For(); battle.CurrentTurnNumber.Returns(currentTurn); var user = Substitute.For(); move.User.Returns(user); user.SwitchInTurn.Returns(switchInTurn); user.Battle.Returns(battle); return (script, move); } /// /// Bulbapedia: "Fake Out will fail if not used on the first turn the user is out." — on the first turn /// the user is on the field (its switch-in turn), the move is not stopped. This includes Pokémon sent /// out later in the battle, as the check is against the turn the user came out, not the battle's first /// turn. /// [Test, Arguments(1u, 1u), Arguments(5u, 5u)] public async Task StopBeforeMove_FirstTurnOnField_MoveNotStopped(uint switchInTurn, uint currentTurn) { // Arrange var (script, move) = CreateStopSetup(switchInTurn, currentTurn); var stop = false; // Act script.StopBeforeMove(move, ref stop); // Assert await Assert.That(stop).IsFalse(); } /// /// Bulbapedia: "Fake Out will fail if not used on the first turn the user is out." — on any later turn /// the move is stopped. /// [Test, Arguments(1u, 2u), Arguments(1u, 10u), Arguments(4u, 5u)] public async Task StopBeforeMove_LaterTurnOnField_MoveStopped(uint switchInTurn, uint currentTurn) { // Arrange var (script, move) = CreateStopSetup(switchInTurn, currentTurn); var stop = false; // Act script.StopBeforeMove(move, ref stop); // Assert await Assert.That(stop).IsTrue(); } /// /// Bulbapedia: "Fake Out inflicts damage and always makes the target flinch" — the secondary effect puts /// a on the target. /// [Test] public async Task OnSecondaryEffect_AddsFlinchEffectToTarget() { // Arrange var script = new FakeOut(); var move = Substitute.For(); var target = Substitute.For(); target.GetScripts().Returns(_ => new ScriptIterator(Array.Empty>())); IScriptSet volatileSet = new ScriptSet(target); target.Volatile.Returns(volatileSet); // Act script.OnSecondaryEffect(move, target, 0); // Assert await Assert.That(volatileSet.Contains(ScriptUtils.ResolveName())).IsTrue(); } }