diff --git a/Sources/TestUnitaire/TestAPILol.cs b/Sources/TestUnitaire/TestAPILol.cs index 20fc95b..02dbdee 100644 --- a/Sources/TestUnitaire/TestAPILol.cs +++ b/Sources/TestUnitaire/TestAPILol.cs @@ -7,30 +7,49 @@ namespace TestUnitaire { public class TestAPILol { - [Fact] - public void Test1() + [Theory] + [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] + [InlineData("Ahri", "Ahri est un champion de League of Legends")] + [InlineData("Akali", "Akali est un champion de League of Legends")] + public async Task TestPostChampion(string name, string bio) { + // Arrange + var data = new StubData(); + var controller = new ControllerChampions(new StubData()); + var champDTO = new ChampionDTO(name, bio); + + // Act + var nbInListBefore = data.ChampionsMgr.GetNbItems().Result; + var result = await controller.Post(champDTO); + var nbInListAfter = data.ChampionsMgr.GetNbItems().Result; + // Assert + // IS the champion added to the list, number of champions in the list + 1 + Assert.Equal(nbInListBefore + 1, nbInListAfter); } - [Fact] - public void TestPostChampion() + + [Theory] + [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] + [InlineData("Ahri", "Ahri est un champion de League of Legends")] + [InlineData("Akali", "Akali est un champion de League of Legends")] + public async Task TestGetChampion(string name, string bio) { // Arrange var data = new StubData(); var controller = new ControllerChampions(new StubData()); - var champDTO = new ChampionDTO("Charles", "Charles est un champion de League of Legends"); + var champDTO = new ChampionDTO(name, bio); // Act - var result = controller.Post(champDTO); - data.ChampionsMgr.AddItem(champDTO.ToModel()); - var nbItem = data.ChampionsMgr.GetNbItems(); - Task nbItemTask = nbItem; + // Call method POST to add a champion + var result = await controller.Post(champDTO); + // Call method GET to get the champion + var resultGet = await controller.GetChampion(name); // Assert - // Verify that the champions is added to the stub - Assert.Equal(7, nbItemTask.Result); - + // IS the champion added to the list, number of champions in the list + 1 + Assert.Equal(name, champDTO.Name); + Assert.Equal(bio, champDTO.Bio); } } } \ No newline at end of file diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index a6581fc..91e39b2 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -42,12 +42,12 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] - public async Task Post([FromBody] ChampionDTO champDTO) + public async Task Post(ChampionDTO champDTO) { Champion tmp = champDTO.ToModel(); - Champion champ = await data.ChampionsMgr.AddItem(tmp); - ChampionDTO dto = champ.ToDTO(); - return CreatedAtAction(nameof(GetChampion), new { name = dto.Name }, dto); + Champion champion = await data.ChampionsMgr.AddItem(tmp); + ChampionDTO dtoChamp = champion.ToDTO(); + return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp); } // PUT api//5