ajout d'un peu de couverture de code
This commit was merged in pull request #11.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -14,4 +14,6 @@
|
|||||||
|
|
||||||
bin
|
bin
|
||||||
obj
|
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
|
||||||
21
src/LittleTown.Core.Tests/ExceptionTesting.cs
Normal file
21
src/LittleTown.Core.Tests/ExceptionTesting.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
|
using AutoMapper.Internal;
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
<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="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.2" />
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
<EnableNETAnalyzers>true</EnableNETAnalyzers>
|
||||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||||
<AnalysisMode>All</AnalysisMode>
|
<AnalysisMode>All</AnalysisMode>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -9,23 +9,50 @@ namespace LittleTown.StaticDataAcces;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class StaticDataGetter : IStaticDataGetter
|
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/>
|
/// <inheritdoc/>
|
||||||
public Board GetBoard(int version)
|
public Board GetBoard(int version)
|
||||||
{
|
{
|
||||||
|
Board board = JsonSerializer.Deserialize<Board>(_boardData) ?? throw new JsonException("Cannot deserialize Board");
|
||||||
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");
|
|
||||||
return board;
|
return board;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public ICollection<Building> GetBuildings()
|
public ICollection<Building> GetBuildings()
|
||||||
{
|
{
|
||||||
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Buildings.json");
|
List<Building> buildings = JsonSerializer.Deserialize<List<Building>>(_buildingData) ?? throw new JsonException("Cannot deserialize Buildings");
|
||||||
string data = System.IO.File.ReadAllText(path);
|
|
||||||
List<Building> buildings = JsonSerializer.Deserialize<List<Building>>(data) ?? throw new JsonException("Cannot deserialize Buildings");
|
|
||||||
|
|
||||||
return buildings;
|
return buildings;
|
||||||
}
|
}
|
||||||
@@ -33,9 +60,7 @@ public class StaticDataGetter : IStaticDataGetter
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public ICollection<Objective> GetObjectives()
|
public ICollection<Objective> GetObjectives()
|
||||||
{
|
{
|
||||||
string path = Path.Combine(Environment.CurrentDirectory, "../../../../LittleTown.StaticDataAccess/Data/Objectives.json");
|
List<Objective> objectives = JsonSerializer.Deserialize<List<Objective>>(_objectivesData) ?? throw new JsonException("Cannot deserialize Objectives");
|
||||||
string data = System.IO.File.ReadAllText(path);
|
|
||||||
List<Objective> objectives = JsonSerializer.Deserialize<List<Objective>>(data) ?? throw new JsonException("Cannot deserialize Objectives");
|
|
||||||
|
|
||||||
return objectives;
|
return objectives;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user