Skip to content

Commit

Permalink
New test project created with a few to test the factory pattern and s…
Browse files Browse the repository at this point in the history
…ome of the object's implementations, such as a pokemon receiving damage or a trainer not having any pokemons left to battle.
  • Loading branch information
JustAn0therDev committed May 19, 2020
1 parent 7d7e47f commit 56835cc
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 2 deletions.
17 changes: 17 additions & 0 deletions PokemonAdventureGame.Tests/Battletests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace PokemonAdventureGame.Tests
{
public class BattleTests
{
[Theory]
[InlineData(3)]
public void ShouldNotBeNull(object something)
{
Assert.NotNull(something);
}
}
}
16 changes: 16 additions & 0 deletions PokemonAdventureGame.Tests/PokemonAdventureGame.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PokemonAdventureGame\PokemonAdventureGame.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using PokemonAdventureGame.Interfaces;
using PokemonAdventureGame.Factories;
using System;
using Xunit;
using PokemonAdventureGame.Trainers;
using PokemonAdventureGame.BattleSystem;

namespace PokemonAdventureGame.Tests
{
public class BattleTests
{
private static readonly ITrainer _trainer = TrainerFactory.CreateTrainer<Player>();
private static readonly ITrainer _enemyTrainer = TrainerFactory.CreateTrainer<Gary>();

[Fact]
public void BattleObjectShouldNotBeNull()
{
Battle battle = new Battle(_trainer, _enemyTrainer);
Assert.NotNull(battle);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\PokemonAdventureGame\PokemonAdventureGame.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using PokemonAdventureGame.Factories;
using PokemonAdventureGame.Interfaces;
using PokemonAdventureGame.Pokemon;
using Xunit;

namespace PokemonAdventureGame.Tests
{
public class PokemonFactoryTests
{
[Fact]
public void PikachuCreationShouldNotReturnNull()
=> Assert.NotNull(PokemonFactory.CreatePokemon<Pikachu>());

[Fact]
public void EeveeCreationShouldNotReturnNull()
=> Assert.NotNull(PokemonFactory.CreatePokemon<Eevee>());

[Fact]
public void PokemonShouldFaint()
{
IPokemon pokemon = PokemonFactory.CreatePokemon<Pikachu>();
pokemon.ReceiveDamage(pokemon.HealthPoints);
Assert.True(pokemon.HasFainted());
}

[Fact]
public void PokemonShouldReceiveDamage()
{
IPokemon pokemon = PokemonFactory.CreatePokemon<Eevee>();
pokemon.ReceiveDamage(10);
Assert.True(pokemon.CurrentHealthPoints < pokemon.HealthPoints);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Xunit;
using PokemonAdventureGame.Factories;
using PokemonAdventureGame.Trainers;
using PokemonAdventureGame.Interfaces;
using System.Linq;

namespace PokemonAdventureGame.Tests
{
public class TrainerFactoryTests
{
[Fact]
public void TrainerPlayerCreationShouldNotReturnNull()
=> Assert.NotNull(TrainerFactory.CreateTrainer<Player>());

[Fact]
public void TrainerGaryCreationShouldNotReturnNull()
=> Assert.NotNull(TrainerFactory.CreateTrainer<Gary>());

[Fact]
public void TrainerShouldNotHaveAnyPokemonLeftToBattle()
{
ITrainer trainer = TrainerFactory.CreateTrainer<Player>();
trainer.PokemonTeam.ForEach(pkmn => pkmn.SetAsFainted());
Assert.False(trainer.HasAvailablePokemon());
}

[Fact]
public void ShouldSetChosenPokemonAsCurrent()
{
ITrainer trainer = TrainerFactory.CreateTrainer<Gary>();
trainer.PokemonTeam.First().SetAsCurrent();
Assert.True(trainer.PokemonTeam.First().Current);
}
}
}
8 changes: 7 additions & 1 deletion PokemonAdventureGame.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokemonAdventureGame", "PokemonAdventureGame\PokemonAdventureGame.csproj", "{191746C5-B1B1-4EC4-BFD1-CAD5D6E28319}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PokemonAdventureGame", "PokemonAdventureGame\PokemonAdventureGame.csproj", "{191746C5-B1B1-4EC4-BFD1-CAD5D6E28319}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokemonAdventureGame.Tests", "PokemonAdventureGame.Tests\PokemonAdventureGame.Tests\PokemonAdventureGame.Tests.csproj", "{CEDFC14E-84C6-40F3-86A1-6B20F46F7CDE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{191746C5-B1B1-4EC4-BFD1-CAD5D6E28319}.Debug|Any CPU.Build.0 = Debug|Any CPU
{191746C5-B1B1-4EC4-BFD1-CAD5D6E28319}.Release|Any CPU.ActiveCfg = Release|Any CPU
{191746C5-B1B1-4EC4-BFD1-CAD5D6E28319}.Release|Any CPU.Build.0 = Release|Any CPU
{CEDFC14E-84C6-40F3-86A1-6B20F46F7CDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEDFC14E-84C6-40F3-86A1-6B20F46F7CDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEDFC14E-84C6-40F3-86A1-6B20F46F7CDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEDFC14E-84C6-40F3-86A1-6B20F46F7CDE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions PokemonAdventureGame/PokemonAdventureGame.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsTestProject>false</IsTestProject>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion PokemonAdventureGame/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace PokemonAdventureGame
{
class Program
{
static void Main()
static void Main(string [] args)
{
try
{
Expand Down

0 comments on commit 56835cc

Please sign in to comment.