Compare commits
1 Commits
f6005f3d81
...
e918b26d6c
| Author | SHA1 | Date | |
|---|---|---|---|
| e918b26d6c |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -14,4 +14,6 @@
|
||||
|
||||
bin
|
||||
obj
|
||||
|
||||
report
|
||||
tools/
|
||||
TestResults
|
||||
6
documentation/Coverage.adoc
Normal file
6
documentation/Coverage.adoc
Normal file
@@ -0,0 +1,6 @@
|
||||
Pour générer la couverture en local il faut installer l'outil :
|
||||
- dotnet tool install -g dotnet-reportgenerator-globaltool
|
||||
- dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
|
||||
|
||||
Pour le lancer
|
||||
- reportgenerator "-reports:src/**/TestResults/**/coverage.cobertura.xml" "-targetdir:./report" "-reporttypes:Html"
|
||||
13
scripts/windows/generateCoverage.ps1
Normal file
13
scripts/windows/generateCoverage.ps1
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
#supprimer les dossiers de tests précédents
|
||||
get-childitem -Include TestResults -Recurse -force | Remove-Item -Force -Recurse
|
||||
|
||||
#lancer les tests
|
||||
dotnet test ./src/LittleTown.sln --configuration Release --verbosity normal --logger trx --collect:"XPlat Code Coverage" --logger:"trx;LogFileName=test_results.xml"
|
||||
|
||||
#générer le rapport html
|
||||
reportgenerator "-reports:src/**/TestResults/**/coverage.cobertura.xml" "-targetdir:./report" "-reporttypes:Html"
|
||||
|
||||
#ouvrir le fichier html
|
||||
report/index.html
|
||||
37
src/LittleTown.Core.Tests/ExceptionTesting.cs
Normal file
37
src/LittleTown.Core.Tests/ExceptionTesting.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using LittleTown.Core.Exceptions;
|
||||
using LittleTown.StaticDataAcces;
|
||||
|
||||
namespace LittleTown.Core.Tests;
|
||||
|
||||
public class ExceptionTesting
|
||||
{
|
||||
[Fact]
|
||||
public void ExceptionForStaticData()
|
||||
{
|
||||
StaticDataGetter getter = new StaticDataGetter("null", "null", "null");
|
||||
|
||||
|
||||
Assert.Throws<JsonException>(() => getter.GetBoard(1));
|
||||
Assert.Throws<JsonException>(() => getter.GetObjectives());
|
||||
Assert.Throws<JsonException>(() => getter.GetBuildings());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NombreDeJoueurMauvaisDansMatch()
|
||||
{
|
||||
StaticDataGetter getter = new();
|
||||
|
||||
Match match2Player = new Match(getter);
|
||||
match2Player.AddPlayer("Player1");
|
||||
match2Player.AddPlayer("Player2");
|
||||
|
||||
Type type = match2Player.GetType();
|
||||
|
||||
PropertyInfo? prop = type?.BaseType?.GetProperty("_players");
|
||||
|
||||
prop?.SetValue(match2Player, new Dictionary<string, PlayerZone>(), null);
|
||||
Assert.Throws<MatchConfigException>(() => match2Player.Init());
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="Microsoft.CodeCoverage" Version="17.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
<AnalysisMode>All</AnalysisMode>
|
||||
<DebugType>full</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -9,23 +9,50 @@ namespace LittleTown.StaticDataAcces;
|
||||
/// </summary>
|
||||
public class StaticDataGetter : IStaticDataGetter
|
||||
{
|
||||
string _boardData = "";
|
||||
string _buildingData = "";
|
||||
string _objectivesData = "";
|
||||
|
||||
/// <summary>
|
||||
/// Constructeur avec les chemin des fichiers de données
|
||||
/// </summary>
|
||||
/// <param name="boardData">structure json definissant le plateau</param>
|
||||
/// <param name="buildingData">structure json definissant les building</param>
|
||||
/// <param name="objectivesData">structure json definissant les objectifs</param>
|
||||
public StaticDataGetter(string boardData, string buildingData, string objectivesData)
|
||||
{
|
||||
_boardData = boardData;
|
||||
_objectivesData = objectivesData;
|
||||
_buildingData = buildingData;
|
||||
}
|
||||
|
||||
/// <summary> Constructeur avec les chemins par défaut, à utiliser pour les tests seulement </summary>
|
||||
public StaticDataGetter()
|
||||
{
|
||||
string boardPath = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Board1.json");
|
||||
string buildingPath = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Buildings.json");
|
||||
string objectivesPath = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Objectives.json");
|
||||
ReadFiles(boardPath, buildingPath, objectivesPath);
|
||||
}
|
||||
|
||||
private void ReadFiles(string boardPath, string buildingPath, string objectivesPath)
|
||||
{
|
||||
_boardData = File.ReadAllText(boardPath);
|
||||
_buildingData = File.ReadAllText(buildingPath);
|
||||
_objectivesData = File.ReadAllText(objectivesPath);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Board GetBoard(int version)
|
||||
{
|
||||
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Board1.json");
|
||||
string data = File.ReadAllText(path);
|
||||
Board board = JsonSerializer.Deserialize<Board>(data) ?? throw new JsonException("Cannot deserialize Board");
|
||||
Board board = JsonSerializer.Deserialize<Board>(_boardData) ?? throw new JsonException("Cannot deserialize Board");
|
||||
return board;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICollection<Building> GetBuildings()
|
||||
{
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Buildings.json");
|
||||
string data = System.IO.File.ReadAllText(path);
|
||||
List<Building> buildings = JsonSerializer.Deserialize<List<Building>>(data) ?? throw new JsonException("Cannot deserialize Buildings");
|
||||
List<Building> buildings = JsonSerializer.Deserialize<List<Building>>(_buildingData) ?? throw new JsonException("Cannot deserialize Buildings");
|
||||
|
||||
return buildings;
|
||||
}
|
||||
@@ -33,9 +60,7 @@ public class StaticDataGetter : IStaticDataGetter
|
||||
/// <inheritdoc/>
|
||||
public ICollection<Objective> GetObjectives()
|
||||
{
|
||||
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Objectives.json");
|
||||
string data = System.IO.File.ReadAllText(path);
|
||||
List<Objective> objectives = JsonSerializer.Deserialize<List<Objective>>(data) ?? throw new JsonException("Cannot deserialize Objectives");
|
||||
List<Objective> objectives = JsonSerializer.Deserialize<List<Objective>>(_objectivesData) ?? throw new JsonException("Cannot deserialize Objectives");
|
||||
|
||||
return objectives;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user