-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 Created failed test to verify the bug
- Loading branch information
1 parent
87a98c8
commit cca2f06
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
PokemonAdventureGame.Tests/PokemonAdventureGame.Tests/Battles/BattleTestUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using PokemonAdventureGame.Interfaces; | ||
using PokemonAdventureGame.Pokemon; | ||
using PokemonAdventureGame.PokemonTeam; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace PokemonAdventureGame.Tests.Battles | ||
{ | ||
public static class BattleTestUtils | ||
{ | ||
public static void FaintPokemon<TPokemon>(ITrainer trainer) | ||
where TPokemon : IPokemon | ||
{ | ||
TrainerPokemon pokemon = trainer.PokemonTeam.FirstOrDefault(x => x.Pokemon is Gyarados); | ||
FaintSpecificPokemon(pokemon); | ||
} | ||
|
||
public static void FaintSpecificPokemon(TrainerPokemon pokemon) | ||
{ | ||
pokemon.Pokemon.ReceiveDamage(9999); | ||
pokemon.SetAsFainted(); | ||
} | ||
|
||
public static IPokemon GetCurrentPokemonForBattle(ITrainer trainer) | ||
{ | ||
// This will set the "Current" property to true for the first available Pokemon. | ||
_ = trainer.GetNextAvailablePokemon(); | ||
|
||
// This will return the Pokemon that will be used in the battle. | ||
// NOTE: This might return a different instance of the Pokemon | ||
// than "GetNextAvailablePokemon" when multiple of the same are in the team. | ||
return trainer.GetCurrentPokemon(); | ||
} | ||
|
||
public static void AssertPokemonAndNotFainted<TPokemon>(IPokemon pokemon) | ||
where TPokemon : IPokemon | ||
{ | ||
//string pokemonName = typeof(TPokemon).Name; | ||
//Assert.Equal(pokemonName, pokemon?.GetType().Name); | ||
Assert.False(pokemon.HasFainted()); | ||
Assert.IsType<TPokemon>(pokemon); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
PokemonAdventureGame.Tests/PokemonAdventureGame.Tests/Battles/LanceBattleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using PokemonAdventureGame.Factories; | ||
using PokemonAdventureGame.Interfaces; | ||
using PokemonAdventureGame.Pokemon; | ||
using PokemonAdventureGame.PokemonTeam; | ||
using PokemonAdventureGame.Trainers; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace PokemonAdventureGame.Tests.Battles | ||
{ | ||
public class LanceBattleTests | ||
{ | ||
[Fact] | ||
public void LanceFirstPokemon() | ||
{ | ||
ITrainer trainer = TrainerFactory.CreateTrainer<Lance>(); | ||
|
||
IPokemon currentPokemon = BattleTestUtils.GetCurrentPokemonForBattle(trainer); | ||
|
||
BattleTestUtils.AssertPokemonAndNotFainted<Gyarados>(currentPokemon); | ||
} | ||
|
||
[Fact] | ||
public void LanceSecondPokemon() | ||
{ | ||
ITrainer trainer = TrainerFactory.CreateTrainer<Lance>(); | ||
|
||
// Simulate Gyarados fainting | ||
TrainerPokemon gyarados = trainer.PokemonTeam.FirstOrDefault(x => x.Pokemon is Gyarados); | ||
gyarados.Fainted = true; | ||
|
||
// Check next Pokemon is Dragonite | ||
IPokemon currentPokemon = BattleTestUtils.GetCurrentPokemonForBattle(trainer); | ||
|
||
BattleTestUtils.AssertPokemonAndNotFainted<Dragonite>(currentPokemon); | ||
} | ||
|
||
[Fact] | ||
public void LanceThirdPokemon() | ||
{ | ||
ITrainer trainer = TrainerFactory.CreateTrainer<Lance>(); | ||
|
||
// Simulate Gyarados fainting | ||
BattleTestUtils.FaintPokemon<Gyarados>(trainer); | ||
|
||
// Simulate first Dragonite fainting | ||
TrainerPokemon firstDragonite = trainer.PokemonTeam.FirstOrDefault(x => x.Pokemon is Dragonite); | ||
BattleTestUtils.FaintSpecificPokemon(firstDragonite); | ||
|
||
// Check next Pokemon is Dragonite | ||
IPokemon currentPokemon = BattleTestUtils.GetCurrentPokemonForBattle(trainer); | ||
|
||
BattleTestUtils.AssertPokemonAndNotFainted<Dragonite>(currentPokemon); | ||
} | ||
|
||
[Fact] | ||
public void LanceAllDragoniteDown() | ||
{ | ||
ITrainer trainer = TrainerFactory.CreateTrainer<Lance>(); | ||
|
||
// Simulate Gyarados fainting | ||
BattleTestUtils.FaintPokemon<Gyarados>(trainer); | ||
|
||
// Simulate all Dragonites fainting | ||
trainer.PokemonTeam | ||
.Where(x => x.Pokemon is Dragonite) | ||
.ToList() | ||
.ForEach(x => BattleTestUtils.FaintSpecificPokemon(x)); | ||
|
||
// Check next Pokemon is Dragonite | ||
IPokemon currentPokemon = BattleTestUtils.GetCurrentPokemonForBattle(trainer); | ||
|
||
BattleTestUtils.AssertPokemonAndNotFainted<Aerodactyl>(currentPokemon); | ||
} | ||
} | ||
} |