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 battleData = Substitute.For();
battleData.Battle.Returns(battle);
battleData.SwitchInTurn.Returns(switchInTurn);
var user = Substitute.For();
user.BattleData.Returns(battleData);
move.User.Returns(user);
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();
}
///
/// Technical test: without battle data on the user (outside of battle) the first-turn check does nothing
/// and the move is not stopped.
///
[Test]
public async Task StopBeforeMove_UserHasNoBattleData_MoveNotStopped()
{
// Arrange
var script = new FakeOut();
var move = Substitute.For();
var user = Substitute.For();
user.BattleData.Returns((IPokemonBattleData?)null);
move.User.Returns(user);
var stop = false;
// Act
script.StopBeforeMove(move, ref stop);
// Assert
await Assert.That(stop).IsFalse();
}
///
/// 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();
}
}