From dc64edf23a5c4c77fce476070f9be3af6906a114 Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Tue, 7 Mar 2023 22:19:27 +0100 Subject: [PATCH] bug solving :bug: --- .../Controllers/ChampionsController.cs | 30 ++++++-------- Sources/Api_UT/ChampionControllerTest.cs | 10 ++--- Sources/Api_UT/UnitTest1.cs | 41 ------------------- 3 files changed, 17 insertions(+), 64 deletions(-) delete mode 100644 Sources/Api_UT/UnitTest1.cs diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index 8ef8ca7..ce8b87e 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -7,6 +7,7 @@ using System.CodeDom.Compiler; using System.Drawing; using System; using API_LoL.Mapper; +using System.Xml.Linq; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -28,13 +29,22 @@ namespace API_LoL.Controllers // GET api//5 [HttpGet] - public async Task Get(String? skill = null, String? characteristic = null,int index = 0,int size =10) + public async Task Get(string? name = null,String? skill = null, String? characteristic = null,int index = 0,int size =10) { if (size - index > 10) { return BadRequest(); } - if(!string.IsNullOrEmpty(skill)) { + if (!string.IsNullOrEmpty(name)) + { + var list = await ChampionsManager.GetItemsByName(name, index, size); + if (list.Count() != 0) + { + return Ok(list.Select(champion => champion?.ToDTO())); + } + else { return NoContent(); } + } + else if(!string.IsNullOrEmpty(skill)) { var list = await ChampionsManager.GetItemsBySkill(skill, index, size); if (list.Count() != 0) { @@ -90,22 +100,6 @@ namespace API_LoL.Controllers else { return NoContent(); } } - [HttpGet("name/largeImage")] - public async Task GetLargeImageByName(String name) - { - if (string.IsNullOrEmpty(name)) return BadRequest(); - var list = await ChampionsManager.GetItemsByName(name, 0, 1); - if (list.Count() == 1) - { - var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First())); - if (skins.Count() != 0) - { - return Ok(skins.Select(skin => skin?.ToDTO())); - } - else { return NoContent(); } - } - else { return NoContent(); } - // POST api/ [HttpPost] public async Task Post(ChampionDTO champion) diff --git a/Sources/Api_UT/ChampionControllerTest.cs b/Sources/Api_UT/ChampionControllerTest.cs index 16fccaa..a3ca675 100644 --- a/Sources/Api_UT/ChampionControllerTest.cs +++ b/Sources/Api_UT/ChampionControllerTest.cs @@ -21,7 +21,7 @@ namespace Api_UT public async Task Get_Default_OkList() { - List list = new List {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") }; + List list = new List {new ChampionDTO("Akali","","","Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter"), new ChampionDTO("Ahri", "", "", "Mage"), new ChampionDTO("Akshan", "", "", "Marksman"), new ChampionDTO("Bard", "", "","Support"), new ChampionDTO("Alistar", "", "","Tank") }; IActionResult a = await api.Get(); a.Should().NotBeNull(); var aObject = a as OkObjectResult; @@ -42,7 +42,7 @@ namespace Api_UT [TestMethod] public async Task Get_2First_OkListOf2() { - List list = new List { new ChampionDTO("Akali", "", ""), new ChampionDTO("Aatrox", "", "") }; + List list = new List { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter") }; IActionResult a = await api.Get(index: 0,size: 2); @@ -57,7 +57,7 @@ namespace Api_UT [TestMethod] public async Task Get_FilterAName_OkListOf5() { - List list = new List { new ChampionDTO("Akali", "", ""), new ChampionDTO("Akshan", "", "") }; + List list = new List { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Akshan", "", "", "Marksman") }; IActionResult a = await api.Get(name: "Ak"); @@ -75,9 +75,9 @@ namespace Api_UT public async Task Post_ValidChampion_Created() { ChampionsController api = new ChampionsController(new StubData()); - IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon")); + IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin")); Assert.IsNotNull(a); - ChampionDTO champ = new ChampionDTO("nom", "bio", "icon"); + ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin"); Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value)); } diff --git a/Sources/Api_UT/UnitTest1.cs b/Sources/Api_UT/UnitTest1.cs deleted file mode 100644 index de78d2b..0000000 --- a/Sources/Api_UT/UnitTest1.cs +++ /dev/null @@ -1,41 +0,0 @@ -using API_LoL.Controllers; -using DTO; -using FluentAssertions; -using Microsoft.AspNetCore.Mvc; -using Model; -using StubLib; - -namespace Api_UT -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public async Task TestGet() - { - List list = new List {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") }; - ChampionsController api = new ChampionsController(new StubData()); - IActionResult a = await api.Get(); - - /// utilisation du nuggets fluentAssertion - //Assert.IsNotNull(a); - a.Should().NotBeNull(); - //Assert.AreEqual(list,((OkObjectResult)a).Value); - var aObject = a as OkObjectResult; - aObject.Should().NotBeNull(); - var championresult = aObject.Value as IEnumerable; - list.Should().BeEquivalentTo(championresult); - } - - [TestMethod] - public async Task TestPostValid() - { - ChampionsController api = new ChampionsController(new StubData()); - IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon")); - Assert.IsNotNull(a); - ChampionDTO champ = new ChampionDTO("nom", "bio", "icon"); - //Assert.AreEqual(champ,((CreatedAtActionResult)a).Value); - } - - } -} \ No newline at end of file