From cfd98c241207c8f7ef7fa397e0929c12aef4c067 Mon Sep 17 00:00:00 2001 From: Maxence Lanone Date: Mon, 10 Apr 2023 20:22:58 +0200 Subject: [PATCH] :clown_face: je sais pas ce que je commit --- Sources/Model/Game.cs | 27 +++++++------- Sources/Stub/Stub/StubData.Games.cs | 8 ++--- Sources/Tests/ModelTest/Test_Stub.cs | 3 +- Sources/Tests/Test_Model/TestGame.cs | 41 ++++++++++++++++++++++ Sources/Tests/Test_Model/Test_Model.csproj | 8 ++--- 5 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 Sources/Tests/Test_Model/TestGame.cs diff --git a/Sources/Model/Game.cs b/Sources/Model/Game.cs index 3a69f74..46f753e 100644 --- a/Sources/Model/Game.cs +++ b/Sources/Model/Game.cs @@ -22,10 +22,10 @@ namespace Model private List turns; public ReadOnlyDictionary Grilles { get; private set; } - private readonly Dictionary grilles; + private Dictionary grilles; public ReadOnlyDictionary Scores { get; private set; } - private readonly Dictionary scores; + private Dictionary scores; public GameMode GameMode { get; set; } @@ -42,9 +42,9 @@ namespace Model // Id = id; //} - public Game(DateTime date, Player ?owner, GameMode gameMode, int id = 0) + public Game(Player ?owner, GameMode gameMode, int id = 0) { - Date = date; + Date = DateTime.Now; // Creation list de player + ajout d'une player owner dans la liste players = new(); @@ -54,17 +54,16 @@ namespace Model turns = new(); Turns = new ReadOnlyCollection(turns); - if(grilles != null) - { - Grilles = new ReadOnlyDictionary(new Dictionary()); - grilles.Add(owner, new Grille()); - } + Grilles = new ReadOnlyDictionary(new Dictionary()); + grilles ??= new Dictionary(); + grilles.Add(owner, new Grille()); + + + Scores = new ReadOnlyDictionary(new Dictionary()); - if(scores != null) - { - Scores = new ReadOnlyDictionary(new Dictionary()); - scores.Add(owner, 0); - } + scores ??= new Dictionary(); + scores.Add(owner, 0); + GameMode = gameMode; Id = id; } diff --git a/Sources/Stub/Stub/StubData.Games.cs b/Sources/Stub/Stub/StubData.Games.cs index c5e4a85..67af397 100644 --- a/Sources/Stub/Stub/StubData.Games.cs +++ b/Sources/Stub/Stub/StubData.Games.cs @@ -13,10 +13,10 @@ namespace Stub { private List games = new() { - new Game(new DateTime(), new Player("Aurélien",0),new GameMode(),1), - new Game(new DateTime(), new Player("Maxence",1),new GameMode(),2), - new Game(new DateTime(), new Player("Théo",2),new GameMode(),3), - new Game(new DateTime(), new Player("Zakariya",3),new GameMode(),4), + new Game(new Player("Aurélien",0),new GameMode(),1), + new Game(new Player("Maxence",1),new GameMode(),2), + new Game(new Player("Théo",2),new GameMode(),3), + new Game(new Player("Zakariya",3),new GameMode(),4), }; public class GamesManager : IGamesManager diff --git a/Sources/Tests/ModelTest/Test_Stub.cs b/Sources/Tests/ModelTest/Test_Stub.cs index eb90c66..44891c9 100644 --- a/Sources/Tests/ModelTest/Test_Stub.cs +++ b/Sources/Tests/ModelTest/Test_Stub.cs @@ -16,8 +16,7 @@ namespace ModelTest { Player player = new Player("Jax"); GameMode gameMode = new GameMode(); - DateTime dateTime = new DateTime(); - Game game = new Game(dateTime, player, gameMode, 1); + Game game = new Game(player, gameMode, 1); } } } \ No newline at end of file diff --git a/Sources/Tests/Test_Model/TestGame.cs b/Sources/Tests/Test_Model/TestGame.cs new file mode 100644 index 0000000..bdd541b --- /dev/null +++ b/Sources/Tests/Test_Model/TestGame.cs @@ -0,0 +1,41 @@ +using System; +using Model; + +namespace Test_Model +{ + public class TestGame + { + + public static IEnumerable GameData_init() + { + yield return new object[] + { + true, + new Player[] + { + new Player("Player 1",2) + }, + new Game(new Player("Player1",2),new GameMode(1,"Classique")), + new Player("Player1",2) + }; + } + + [Theory] + [MemberData(nameof(GameData_init))] + public void AddPlayerToGame_Should_Return_Correct_Result(bool expectedResult, + IEnumerable expectedPlayers, + Game game, + Player playerToBeAdded) + { + // Act + bool result = game.AddPlayerToGame(playerToBeAdded); + Console.WriteLine(result); + + // Assert + Assert.Equal(expectedResult, result); + Assert.Equal(expectedPlayers.Count(), game.Players.Count()); + Assert.All(expectedPlayers, p => game.Players.Contains(p)); + } + } +} + diff --git a/Sources/Tests/Test_Model/Test_Model.csproj b/Sources/Tests/Test_Model/Test_Model.csproj index 89cc59c..88b0541 100644 --- a/Sources/Tests/Test_Model/Test_Model.csproj +++ b/Sources/Tests/Test_Model/Test_Model.csproj @@ -9,13 +9,13 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all