ajout de la commande de creation de match
This commit was merged in pull request #7.
This commit is contained in:
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Giants.Infrastructure", "Sr
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Giants.Application", "Src\Giants.Application\Giants.Application.csproj", "{1EF04517-2D31-4130-A687-7954A5431312}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Giants.Application", "Src\Giants.Application\Giants.Application.csproj", "{1EF04517-2D31-4130-A687-7954A5431312}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Giants.Application.Tests", "Tests\Giants.Application.Tests\Giants.Application.Tests.csproj", "{7A23A70F-68C9-4463-A980-E7597A621FDD}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -40,11 +42,16 @@ Global
|
|||||||
{1EF04517-2D31-4130-A687-7954A5431312}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{1EF04517-2D31-4130-A687-7954A5431312}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{1EF04517-2D31-4130-A687-7954A5431312}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{1EF04517-2D31-4130-A687-7954A5431312}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{1EF04517-2D31-4130-A687-7954A5431312}.Release|Any CPU.Build.0 = Release|Any CPU
|
{1EF04517-2D31-4130-A687-7954A5431312}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7A23A70F-68C9-4463-A980-E7597A621FDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7A23A70F-68C9-4463-A980-E7597A621FDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7A23A70F-68C9-4463-A980-E7597A621FDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7A23A70F-68C9-4463-A980-E7597A621FDD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{A7B8B752-2AE9-4FB2-8F51-733F96C4CFD0} = {824D17BD-3CFE-498A-967D-3F42DF5EE92D}
|
{A7B8B752-2AE9-4FB2-8F51-733F96C4CFD0} = {824D17BD-3CFE-498A-967D-3F42DF5EE92D}
|
||||||
{30032CBC-0B7B-4BF3-9682-C506460F0FE6} = {F34871C1-07BB-4012-A310-3FFDD6DC7DBA}
|
{30032CBC-0B7B-4BF3-9682-C506460F0FE6} = {F34871C1-07BB-4012-A310-3FFDD6DC7DBA}
|
||||||
{E6B2C76F-9CE2-4ADA-97F9-CEE24D48B65F} = {824D17BD-3CFE-498A-967D-3F42DF5EE92D}
|
{E6B2C76F-9CE2-4ADA-97F9-CEE24D48B65F} = {824D17BD-3CFE-498A-967D-3F42DF5EE92D}
|
||||||
{1EF04517-2D31-4130-A687-7954A5431312} = {824D17BD-3CFE-498A-967D-3F42DF5EE92D}
|
{1EF04517-2D31-4130-A687-7954A5431312} = {824D17BD-3CFE-498A-967D-3F42DF5EE92D}
|
||||||
|
{7A23A70F-68C9-4463-A980-E7597A621FDD} = {F34871C1-07BB-4012-A310-3FFDD6DC7DBA}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ namespace Giants.Application;
|
|||||||
public class MatchRepositoryMock : IMatchRepository
|
public class MatchRepositoryMock : IMatchRepository
|
||||||
{
|
{
|
||||||
private readonly IHexagonalGrid _gridLayout;
|
private readonly IHexagonalGrid _gridLayout;
|
||||||
|
private static int _lastId = 1;
|
||||||
|
|
||||||
|
private Dictionary<int, Match> _matchs = new Dictionary<int, Match>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// constructeur
|
/// constructeur
|
||||||
@@ -22,10 +25,31 @@ public class MatchRepositoryMock : IMatchRepository
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public Match? GetMatch(int matchId)
|
public Match? GetMatch(int matchId)
|
||||||
{
|
{
|
||||||
Match result = new Match(_gridLayout);
|
if (_matchs.TryGetValue(matchId, out Match? found))
|
||||||
|
{
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public Match CreateMatch()
|
||||||
|
{
|
||||||
|
Match result = new Match(_gridLayout)
|
||||||
|
{
|
||||||
|
Id = _lastId++
|
||||||
|
};
|
||||||
|
|
||||||
|
AddStaticData(result);
|
||||||
|
|
||||||
|
_matchs.Add(result.Id, result);
|
||||||
|
|
||||||
// Ajout des données statiques
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddStaticData(Match match)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
11
Src/Giants.Core/Src/Commands/BaseCommandResult.cs
Normal file
11
Src/Giants.Core/Src/Commands/BaseCommandResult.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Giants.Core.Commands;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Class de base des resultats de commande. Chaque commande doit retourner un resultat quand elle
|
||||||
|
/// s'execute et les données de ce resultat est propre a la commande
|
||||||
|
/// </summary>
|
||||||
|
public abstract class BaseCommandResult
|
||||||
|
{
|
||||||
|
/// <summary> indique si le resultat est un success (true) ou un echec(false) </summary>
|
||||||
|
public bool Success { get; init; } = false;
|
||||||
|
}
|
||||||
17
Src/Giants.Core/Src/Commands/CommandBase.cs
Normal file
17
Src/Giants.Core/Src/Commands/CommandBase.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace Giants.Core.Commands;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base des commande permettant d'agir sur le modele
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Le type de resultat que retourne cette commande </typeparam>
|
||||||
|
public abstract class BaseCommand<T> where T : BaseCommandResult
|
||||||
|
{
|
||||||
|
protected abstract T LocalExecute();
|
||||||
|
|
||||||
|
/// <summary> Executer la commande, si nécessaire il faut avoir rempli les parametres en amont </summary>
|
||||||
|
public T Execute()
|
||||||
|
{
|
||||||
|
// C'est ici que sera validé l'exécution
|
||||||
|
return LocalExecute();
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Src/Giants.Core/Src/Commands/NewMatchCommand.cs
Normal file
38
Src/Giants.Core/Src/Commands/NewMatchCommand.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using Giants.Core.Interfaces;
|
||||||
|
|
||||||
|
namespace Giants.Core.Commands;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Commande permettant de créer un nouveau match
|
||||||
|
/// </summary>
|
||||||
|
public class NewMatchCommand : BaseCommand<NewMatchResult>
|
||||||
|
{
|
||||||
|
private readonly IMatchRepository _repo;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// constructeur
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repo">le repository de match</param>
|
||||||
|
public NewMatchCommand(IMatchRepository repo)
|
||||||
|
{
|
||||||
|
_repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
protected override sealed NewMatchResult LocalExecute()
|
||||||
|
{
|
||||||
|
var match = _repo.CreateMatch();
|
||||||
|
|
||||||
|
return new NewMatchResult()
|
||||||
|
{
|
||||||
|
Match = match,
|
||||||
|
Success = match != null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NewMatchResult : BaseCommandResult
|
||||||
|
{
|
||||||
|
/// <summary> Le match créé si success </summary>
|
||||||
|
public Match? Match { get; init; }
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ namespace Giants.Core;
|
|||||||
public class Match
|
public class Match
|
||||||
{
|
{
|
||||||
#region données statiques
|
#region données statiques
|
||||||
|
public int Id { get; init; }
|
||||||
IHexagonalGrid _grid;
|
IHexagonalGrid _grid;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -11,4 +11,10 @@ public interface IMatchRepository
|
|||||||
/// <param name="matchId">L'id unique du match a récupérer</param>
|
/// <param name="matchId">L'id unique du match a récupérer</param>
|
||||||
/// <returns>le match s'il existe ou null dans le cas contraire</returns>
|
/// <returns>le match s'il existe ou null dans le cas contraire</returns>
|
||||||
Match? GetMatch(int matchId);
|
Match? GetMatch(int matchId);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Créer un match avec un ID unique
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>le nouveau match a son état initial</returns>
|
||||||
|
Match? CreateMatch();
|
||||||
}
|
}
|
||||||
32
Tests/Giants.Application.Tests/ApplicationTests.cs
Normal file
32
Tests/Giants.Application.Tests/ApplicationTests.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
namespace Giants.Core.Tests;
|
||||||
|
|
||||||
|
using Giants.Application;
|
||||||
|
using Giants.Core.Commands;
|
||||||
|
using Giants.Core.Interfaces;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
public class ApplicationTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ApplicationCreationExample()
|
||||||
|
{
|
||||||
|
GiantApplication app = new GiantApplication();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TryingServiceInjection()
|
||||||
|
{
|
||||||
|
// creation des instances
|
||||||
|
IMatchRepository matchRepository = new MatchRepositoryMock();
|
||||||
|
|
||||||
|
var serviceCollection = new ServiceCollection();
|
||||||
|
serviceCollection.AddScoped(repo => matchRepository);
|
||||||
|
|
||||||
|
// Ajout des commandes disponibles
|
||||||
|
serviceCollection.AddScoped<NewMatchCommand>();
|
||||||
|
|
||||||
|
//Test d'injection
|
||||||
|
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||||
|
NewMatchCommand? command = serviceProvider.GetService<NewMatchCommand>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||||
|
<PackageReference Include="xunit" Version="2.9.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Src\Giants.Application\Giants.Application.csproj" />
|
||||||
|
<ProjectReference Include="..\..\Src\Giants.Core\Giants.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
namespace Giants.Core.Tests;
|
|
||||||
|
|
||||||
using Giants.Application;
|
|
||||||
|
|
||||||
public class ApplicationTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void ApplicationCreationExample()
|
|
||||||
{
|
|
||||||
GiantApplication app = new GiantApplication();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
34
Tests/Giants.Core.Tests/Commands/NewMatchCommandTest.cs
Normal file
34
Tests/Giants.Core.Tests/Commands/NewMatchCommandTest.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
namespace Giants.Core.Tests;
|
||||||
|
|
||||||
|
using Giants.Application;
|
||||||
|
using Giants.Core.Commands;
|
||||||
|
using Giants.Core.Interfaces;
|
||||||
|
|
||||||
|
public class NewMatchCommandTest
|
||||||
|
{
|
||||||
|
private readonly IMatchRepository _repo = new MatchRepositoryMock();
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateBasicMatch()
|
||||||
|
{
|
||||||
|
NewMatchCommand command = new NewMatchCommand(_repo);
|
||||||
|
NewMatchResult result = command.Execute();
|
||||||
|
Assert.True(result.Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TwoNewMatchShouldHaveDifferentID()
|
||||||
|
{
|
||||||
|
NewMatchCommand command = new NewMatchCommand(_repo);
|
||||||
|
NewMatchResult result = command.Execute();
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.NotNull(result.Match);
|
||||||
|
|
||||||
|
NewMatchCommand command2 = new NewMatchCommand(_repo);
|
||||||
|
NewMatchResult result2 = command2.Execute();
|
||||||
|
Assert.True(result2.Success);
|
||||||
|
Assert.NotNull(result2.Match);
|
||||||
|
|
||||||
|
Assert.NotEqual(result.Match.Id, result2.Match.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user