Files
PkmnLib.NET/Plugins/PkmnLib.Plugin.Gen7.Tests/Scripts/Moves/FeintTests.cs
Deukhoofd d2a82b5fe3
All checks were successful
Build / Build (push) Successful in 3m12s
Many more tests and fixes
2026-08-27 17:11:12 +02:00

187 lines
7.3 KiB
C#

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;
using PkmnLib.Plugin.Gen7.Scripts.Side;
namespace PkmnLib.Plugin.Gen7.Tests.Scripts.Moves;
/// <summary>
/// Tests for the <see cref="Feint"/> move script.
/// Gen VII Bulbapedia behavior: Feint strikes a target that has used Protect or Detect, "lifting the effects
/// of Protect or Detect for the remainder of the turn." Generation VI onwards: "Feint hits a target even if
/// it is protected by Mat Block, Spiky Shield, King's Shield, Baneful Bunker, Obstruct, Silk Trap, or Burning
/// Bulwark and removes that protection for the rest of the turn." and "Feint removes Crafty Shield and Mat
/// Block from the target's team."
/// </summary>
public class FeintTests
{
/// <summary>
/// Creates a fully mocked test setup where the target has a real <see cref="ScriptSet"/> as its volatile
/// script set.
/// </summary>
private static (Feint script, IExecutingMove move, IPokemon target, IScriptSet volatileSet) CreateTestSetup()
{
var script = new Feint();
var move = Substitute.For<IExecutingMove>();
var target = Substitute.For<IPokemon>();
target.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
IScriptSet volatileSet = new ScriptSet(target);
target.Volatile.Returns(volatileSet);
return (script, move, target, volatileSet);
}
/// <summary>
/// Extends the test setup with a battle side that has a real <see cref="ScriptSet"/> as its volatile
/// scripts, so side-wide protections such as <see cref="CraftyShieldEffect"/> can be attached.
/// </summary>
private static IScriptSet AttachSide(IPokemon target)
{
var side = Substitute.For<IBattleSide>();
side.GetScripts().Returns(_ => new ScriptIterator(Array.Empty<IEnumerable<ScriptContainer>>()));
IScriptSet sideScripts = new ScriptSet(side);
side.VolatileScripts.Returns(sideScripts);
var battleData = Substitute.For<IPokemonBattleData>();
battleData.BattleSide.Returns(side);
target.BattleData.Returns(battleData);
return sideScripts;
}
/// <summary>
/// Bulbapedia: Feint strikes "a target that has used Protect or Detect during that turn, lifting the
/// effects of Protect or Detect for the remainder of the turn." — the target's
/// <see cref="ProtectionEffectScript"/> is removed before the hit.
/// </summary>
[Test]
public async Task OnBeforeHit_TargetUsedProtect_ProtectionEffectRemoved()
{
// Arrange
var (script, move, target, volatileSet) = CreateTestSetup();
volatileSet.Add(new ProtectionEffectScript());
// Act
script.OnBeforeHit(move, target, 0);
// Assert
await Assert.That(volatileSet.Contains(ScriptUtils.ResolveName<ProtectionEffectScript>())).IsFalse();
}
/// <summary>
/// Bulbapedia (Generation V onward): "Feint can now inflict damage even if the target has not used
/// Protect or Detect" — with no protection on the target, the hook simply does nothing and does not
/// throw.
/// </summary>
[Test]
public async Task OnBeforeHit_TargetNotProtected_DoesNothing()
{
// Arrange
var (script, move, target, volatileSet) = CreateTestSetup();
// Act
script.OnBeforeHit(move, target, 0);
// Assert
await Assert.That(volatileSet.Count).IsEqualTo(0);
}
/// <summary>
/// Bulbapedia (Generation VI onwards): "Feint hits a target even if it is protected by Mat Block,
/// Spiky Shield, King's Shield, Baneful Bunker, Obstruct, Silk Trap, or Burning Bulwark and removes that
/// protection for the rest of the turn." — a target under Spiky Shield has its
/// <see cref="SpikyShieldEffect"/> removed.
/// </summary>
[Test]
public async Task OnBeforeHit_TargetUnderSpikyShield_ProtectionEffectRemoved()
{
// Arrange
var (script, move, target, volatileSet) = CreateTestSetup();
volatileSet.Add(new SpikyShieldEffect());
// Act
script.OnBeforeHit(move, target, 0);
// Assert
await Assert.That(volatileSet.Contains(ScriptUtils.ResolveName<SpikyShieldEffect>())).IsFalse();
}
/// <summary>
/// Bulbapedia (Generation VI onwards): "Feint hits a target even if it is protected by Mat Block,
/// Spiky Shield, King's Shield, Baneful Bunker, Obstruct, Silk Trap, or Burning Bulwark and removes that
/// protection for the rest of the turn." — a target under King's Shield has its <see cref="KingsShieldEffect"/>
/// effect removed.
/// </summary>
[Test]
public async Task OnBeforeHit_TargetUnderKingsShield_ProtectionEffectRemoved()
{
// Arrange
var (script, move, target, volatileSet) = CreateTestSetup();
volatileSet.Add(new KingsShieldEffect());
// Act
script.OnBeforeHit(move, target, 0);
// Assert
await Assert.That(volatileSet.Contains(ScriptUtils.ResolveName<KingsShieldEffect>())).IsFalse();
}
/// <summary>
/// Bulbapedia (Generation VI onwards): "Feint hits a target even if it is protected by Mat Block,
/// Spiky Shield, King's Shield, Baneful Bunker, Obstruct, Silk Trap, or Burning Bulwark and removes that
/// protection for the rest of the turn." — a target under Baneful Bunker has its
/// <see cref="BanefulBunkerEffect"/> removed.
/// </summary>
[Test]
public async Task OnBeforeHit_TargetUnderBanefulBunker_ProtectionEffectRemoved()
{
// Arrange
var (script, move, target, volatileSet) = CreateTestSetup();
volatileSet.Add(new BanefulBunkerEffect());
// Act
script.OnBeforeHit(move, target, 0);
// Assert
await Assert.That(volatileSet.Contains(ScriptUtils.ResolveName<BanefulBunkerEffect>())).IsFalse();
}
/// <summary>
/// Bulbapedia (Generation VI onwards): "Feint removes Crafty Shield and Mat Block from the target's
/// team." — the <see cref="CraftyShieldEffect"/> is removed from the target's side.
/// </summary>
[Test]
public async Task OnBeforeHit_CraftyShieldOnTargetSide_SideEffectRemoved()
{
// Arrange
var (script, move, target, _) = CreateTestSetup();
var sideScripts = AttachSide(target);
sideScripts.Add(new CraftyShieldEffect());
// Act
script.OnBeforeHit(move, target, 0);
// Assert
await Assert.That(sideScripts.Contains(ScriptUtils.ResolveName<CraftyShieldEffect>())).IsFalse();
}
/// <summary>
/// Bulbapedia (Generation VI onwards): "Feint removes Crafty Shield and Mat Block from the target's
/// team." — the <see cref="MatBlockEffect"/> is removed from the target's side.
/// </summary>
[Test]
public async Task OnBeforeHit_MatBlockOnTargetSide_SideEffectRemoved()
{
// Arrange
var (script, move, target, _) = CreateTestSetup();
var sideScripts = AttachSide(target);
sideScripts.Add(new MatBlockEffect());
// Act
script.OnBeforeHit(move, target, 0);
// Assert
await Assert.That(sideScripts.Contains(ScriptUtils.ResolveName<MatBlockEffect>())).IsFalse();
}
}