diff --git a/.vs/LolProject/v17/.suo b/.vs/LolProject/v17/.suo index f873e9e..fa82156 100644 Binary files a/.vs/LolProject/v17/.suo and b/.vs/LolProject/v17/.suo differ diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/RunesController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/RunesController.cs index 787689a..17e43a7 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/RunesController.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/RunesController.cs @@ -51,7 +51,7 @@ namespace ApiLol.Controllers dtos = (await _manager.RunesMgr.GetItemsByName(pageRequest.name, pageRequest.index, pageRequest.count, pageRequest.orderingPropertyName, pageRequest.descending)) .Select(x => x.ToDto()); } - return Ok(new PageResponse{ Data = dtos, index = pageRequest.index, count = pageRequest.count, total = nbTotal }); + return Ok(new PageResponse { Data = dtos, index = pageRequest.index, count = pageRequest.count, total = nbTotal }); } catch (Exception error) @@ -94,7 +94,7 @@ namespace ApiLol.Controllers if (await _manager.RunesMgr.GetNbItemsByName(rune.Name) == 0) { return CreatedAtAction(nameof(Get), - (await _manager.RunesMgr.AddItem(rune.ToModel()))); + (await _manager.RunesMgr.AddItem(rune.ToModel())).ToDto()); } _logger.LogWarning($"Name : {rune.Name} is already exist"); return BadRequest($"Name : {rune.Name} is already exist"); @@ -122,12 +122,12 @@ namespace ApiLol.Controllers if (name != rune.Name) { var dtos2 = (await _manager.RunesMgr.GetItemByName(rune.Name, 0, await _manager.RunesMgr.GetNbItems())); - if (dtos2.IsNullOrEmpty() || dtos2.Count() > 0) + if (!dtos2.IsNullOrEmpty() || dtos2.Count() > 0) { return BadRequest($"New Name {rune.Name} is already exist"); } } - return Ok(await _manager.RunesMgr.UpdateItem(dtos.First(),rune.ToModel())); + return Ok((await _manager.RunesMgr.UpdateItem(dtos.First(), rune.ToModel())).ToDto()); } catch (Exception error) @@ -160,7 +160,7 @@ namespace ApiLol.Controllers } [HttpGet("/countRunes")] - public async Task> GetCountSkins() + public async Task GetCountSkins() { try { diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/SkinsController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/SkinsController.cs index 8353d0b..1057d85 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/SkinsController.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/SkinsController.cs @@ -137,7 +137,7 @@ namespace ApiLol.Controllers if (name != skin.Name) { var dtos2 = (await _manager.SkinsMgr.GetItemByName(skin.Name, 0, await _manager.SkinsMgr.GetNbItems())); - if (dtos2.IsNullOrEmpty() || dtos2.Count() > 0) + if (!dtos2.IsNullOrEmpty() || dtos2.Count() > 0) { return BadRequest($"New Name {skin.Name} is already exist"); } @@ -183,7 +183,7 @@ namespace ApiLol.Controllers [HttpGet("/countSkins")] - public async Task> GetCountSkins() + public async Task GetCountSkins() { try { diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/v2/ChampionsController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/v2/ChampionsController.cs index 7b67006..130ba63 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/v2/ChampionsController.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/v2/ChampionsController.cs @@ -151,7 +151,7 @@ namespace ApiLol.Controllers.v2 if (name != champion.Name) { var dtos2 = (await _manager.ChampionsMgr.GetItemByName(champion.Name, 0, await _manager.ChampionsMgr.GetNbItems())); - if (dtos2.IsNullOrEmpty() || dtos2.Count() > 0) + if (!dtos2.IsNullOrEmpty() || dtos2.Count() > 0) { return BadRequest($"New Name {champion.Name} is already exist"); } @@ -204,7 +204,7 @@ namespace ApiLol.Controllers.v2 } [HttpGet("/countChampions")] - public async Task> GetCountChampions() + public async Task GetCountChampions() { try { diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs index 094739d..ef89170 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs @@ -26,6 +26,11 @@ namespace ApiLol.Mapper { champ.AddSkin(skin.ToModel(champ)); } + + foreach (var skill in championDto.Skills) + { + champ.AddSkill(skill.ToModel()); + } return champ; } diff --git a/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTestV1.cs b/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTestV1.cs index 641fc9a..766c9ab 100644 --- a/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTestV1.cs +++ b/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTestV1.cs @@ -29,7 +29,7 @@ namespace ApiTests //Act var total = await stub.ChampionsMgr.GetNbItems(); - var champion = await champs.Get(new PageRequest(){ index = 0, count = total }); + var champion = await champs.Get(new PageRequest() { index = 0, count = total }); //Assert var objectResult = champion as OkObjectResult; @@ -54,6 +54,13 @@ namespace ApiTests Icon = "", Image = new LargeImageDto() { Base64 = "" }, Skins = new List() + { + new SkinDto() {Name = "Project", Description = "Test", Icon = "",Image = new LargeImageDto(),Price = 900 } + }, + Skills = new List() + { + new SkillDto() {Name = "Test skill", Description="Empty", Type = SkillTypeDto.Unknown} + } }; //Act @@ -66,6 +73,14 @@ namespace ApiTests var champions = objectResult?.Value as ChampionDto; Assert.IsNotNull(champions); + Assert.AreEqual("Sylas", champions.Name); + + Assert.AreEqual("Project", champions.Skins.First().Name); + Assert.AreEqual("Test", champions.Skins.First().Description); + + Assert.AreEqual("Test skill", champions.Skills.First().Name); + Assert.AreEqual("Empty", champions.Skills.First().Description); + } [TestMethod] @@ -80,6 +95,13 @@ namespace ApiTests Icon = "", Image = new LargeImageDto() { Base64 = "" }, Skins = new List() + { + new SkinDto() {Name = "Project", Description = "Test", Icon = "",Image = new LargeImageDto(),Price = 900 } + }, + Skills = new List() + { + new SkillDto() {Name = "Test skill", Description="Empty", Type = SkillTypeDto.Unknown} + } }; //Act @@ -121,6 +143,13 @@ namespace ApiTests Icon = "", Image = new LargeImageDto() { Base64 = "" }, Skins = new List() + { + new SkinDto() {Name = "Project", Description = "Test", Icon = "",Image = new LargeImageDto(),Price = 900 } + }, + Skills = new List() + { + new SkillDto() {Name = "Test skill", Description="Empty", Type = SkillTypeDto.Unknown} + } }; var ChampionDtoPut = new ChampionDto { @@ -129,7 +158,8 @@ namespace ApiTests Class = ChampionClassDto.Tank, Icon = "", Image = new LargeImageDto() { Base64 = "" }, - Skins = new List() + Skins = new List(), + Skills = new List() }; //Act diff --git a/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTestV2.cs b/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTestV2.cs index 39366e8..c2dc246 100644 --- a/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTestV2.cs +++ b/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTestV2.cs @@ -62,6 +62,54 @@ namespace ApiTests } + [TestMethod] + public async Task TestCountChampion() + { + //Arange + var ChampionDto = new ChampionDto + { + Name = "Sylas", + Bio = "Good", + Class = ChampionClassDto.Tank, + Icon = "", + Image = new LargeImageDto() { Base64 = "" }, + Skins = new List() + { + new SkinDto() {Name = "Project", Description = "Test", Icon = "",Image = new LargeImageDto(),Price = 900 } + }, + Skills = new List() + { + new SkillDto() {Name = "Test skill", Description="Empty", Type = SkillTypeDto.Unknown} + } + }; + + //Act + var oldTotal = await stub.ChampionsMgr.GetNbItems(); + var oldResult = await champs.GetCountChampions(); + await champs.Post(ChampionDto); + + var objectResult = oldResult as OkObjectResult; + Assert.IsNotNull(objectResult); + + var newTotal = await stub.ChampionsMgr.GetNbItems(); + var newResult = await champs.GetCountChampions(); + + //Assert + var objectResultOld = oldResult as OkObjectResult; + Assert.IsNotNull(objectResultOld); + + var objectResultNew = newResult as OkObjectResult; + Assert.IsNotNull(objectResultNew); + + Assert.AreEqual(objectResultOld.Value, oldTotal); + Assert.AreNotEqual(objectResultOld.Value, newTotal); + + Assert.AreEqual(objectResultNew.Value, newTotal); + Assert.AreNotEqual(objectResultNew.Value, oldTotal); + + + } + [TestMethod] public async Task TestPostChampion() { @@ -74,6 +122,13 @@ namespace ApiTests Icon = "", Image = new LargeImageDto() { Base64 = "" }, Skins = new List() + { + new SkinDto() {Name = "Project", Description = "Test", Icon = "",Image = new LargeImageDto(),Price = 900 } + }, + Skills = new List() + { + new SkillDto() {Name = "Test skill", Description="Empty", Type = SkillTypeDto.Unknown} + } }; //Act @@ -86,6 +141,14 @@ namespace ApiTests var champions = objectResult?.Value as ChampionDto; Assert.IsNotNull(champions); + Assert.AreEqual("Sylas", champions.Name); + + Assert.AreEqual("Project", champions.Skins.First().Name); + Assert.AreEqual("Test", champions.Skins.First().Description); + + Assert.AreEqual("Test skill", champions.Skills.First().Name); + Assert.AreEqual("Empty", champions.Skills.First().Description); + } [TestMethod] @@ -100,15 +163,23 @@ namespace ApiTests Icon = "", Image = new LargeImageDto() { Base64 = "" }, Skins = new List() + { + new SkinDto() {Name = "Project", Description = "Test", Icon = "",Image = new LargeImageDto(),Price = 900 } + }, + Skills = new List() + { + new SkillDto() {Name = "Test skill", Description="Empty", Type = SkillTypeDto.Unknown} + } }; var ChampionDtoPut = new ChampionDto { - Name = "Sylas", + Name = "new Sylas", Bio = "Bad", Class = ChampionClassDto.Tank, Icon = "", Image = new LargeImageDto() { Base64 = "" }, - Skins = new List() + Skins = new List(), + Skills = new List() }; //Act @@ -123,7 +194,9 @@ namespace ApiTests Assert.IsNotNull(champions); Assert.AreNotEqual(ChampionDto.Bio, champions.Bio); + Assert.AreNotEqual(ChampionDto.Name, champions.Name); Assert.AreEqual(ChampionDtoPut.Bio, champions.Bio); + Assert.AreEqual(ChampionDtoPut.Name, champions.Name); } diff --git a/src/EntityFramework_LoL/Sources/Tests/ApiTests/RunesControllerTest.cs b/src/EntityFramework_LoL/Sources/Tests/ApiTests/RunesControllerTest.cs index 2bdedb4..7487c79 100644 --- a/src/EntityFramework_LoL/Sources/Tests/ApiTests/RunesControllerTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/ApiTests/RunesControllerTest.cs @@ -1,4 +1,10 @@ -using System; +using ApiLol.Controllers; +using DTO; +using DTO.enums; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging.Abstractions; +using StubLib; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -9,5 +15,164 @@ namespace ApiTests [TestClass] public class RunesControllerTest { + private readonly StubData stub; + private readonly RunesController runes; + public RunesControllerTest() + { + stub = new StubData(); + runes = new RunesController(stub, new NullLogger()); + } + + [TestMethod] + public async Task TestGetRunes() + { + //Arrange + + //Act + var total = await stub.RunesMgr.GetNbItems(); + var rune = await runes.Get(new PageRequest()); + + //Assert + var objectResult = rune as OkObjectResult; + Assert.IsNotNull(objectResult); + + var runesResult = objectResult.Value as PageResponse; + Assert.IsNotNull(runesResult); + + var result = runesResult.Data as IEnumerable; + Assert.IsNotNull(result); + + Assert.AreEqual(result.Count(), total); + Assert.AreEqual(total, runesResult.total); + + } + + [TestMethod] + public async Task TestPostRune() + { + //Arange + var runeDto = new RuneDto + { + Name = "Project", + Description = "Test", + Icon = "", + Image = new LargeImageDto(), + Family = RuneFamilyDto.Precision + }; + + //Act + var total = await stub.RunesMgr.GetNbItems(); + var runesResult = await runes.Post(runeDto); + + //Assert + var objectResult = runesResult as CreatedAtActionResult; + Assert.IsNotNull(objectResult); + + var isRuneDto = objectResult?.Value as RuneDto; + Assert.IsNotNull(isRuneDto); + + Assert.AreEqual(total + 1, await stub.RunesMgr.GetNbItems()); + + } + + [TestMethod] + public async Task TestCountChampion() + { + //Arange + var runeDto = new RuneDto + { + Name = "Project", + Description = "Test", + Icon = "", + Image = new LargeImageDto(), + Family = RuneFamilyDto.Domination + }; + + //Act + var oldTotal = await stub.RunesMgr.GetNbItems(); + var oldResult = await runes.GetCountSkins(); + await runes.Post(runeDto); + + var objectResult = oldResult as OkObjectResult; + Assert.IsNotNull(objectResult); + + var newTotal = await stub.RunesMgr.GetNbItems(); + var newResult = await runes.GetCountSkins(); + + //Assert + var objectResultOld = oldResult as OkObjectResult; + Assert.IsNotNull(objectResultOld); + + var objectResultNew = newResult as OkObjectResult; + Assert.IsNotNull(objectResultNew); + + Assert.AreEqual(objectResultOld.Value, oldTotal); + Assert.AreNotEqual(objectResultOld.Value, newTotal); + + Assert.AreEqual(objectResultNew.Value, newTotal); + Assert.AreNotEqual(objectResultNew.Value, oldTotal); + + + } + + [TestMethod] + public async Task TestPutSkin() + { + //Arange + var runeDto = new RuneDto + { + Name = "Project", + Description = "Test", + Icon = "", + Image = new LargeImageDto(), + Family = RuneFamilyDto.Precision + }; + + var runeDtoPut = new RuneDto + { + Name = "New Project", + Description = "new Test", + Icon = "", + Image = new LargeImageDto(), + Family = RuneFamilyDto.Unknown + }; + + //Act + await runes.Post(runeDto); + var runesResult = await runes.Put(runeDto.Name, runeDtoPut); + + //Assert + var objectResult = runesResult as OkObjectResult; + Assert.IsNotNull(objectResult); + + var rune = objectResult?.Value as RuneDto; + Assert.IsNotNull(rune); + + Assert.AreNotEqual(runeDto.Description, rune.Description); + Assert.AreNotEqual(runeDto.Family, rune.Family); + + Assert.AreEqual(runeDtoPut.Description, rune.Description); + Assert.AreEqual(runeDtoPut.Family, rune.Family); + + } + + [TestMethod] + public async Task TestDeleteChampion() + { + //Arange + + + //Act + var total = await stub.RunesMgr.GetNbItems(); + var runesResult = await runes.Delete("Conqueror"); + + //Assert + var objectResult = runesResult as OkObjectResult; + Assert.IsNotNull(objectResult); + + Assert.AreEqual(objectResult.Value, true); + Assert.AreNotEqual(await stub.RunesMgr.GetNbItems(), total); + + } } } diff --git a/src/EntityFramework_LoL/Sources/Tests/ApiTests/SkinsControllerTest.cs b/src/EntityFramework_LoL/Sources/Tests/ApiTests/SkinsControllerTest.cs index 26a0f59..0231cfa 100644 --- a/src/EntityFramework_LoL/Sources/Tests/ApiTests/SkinsControllerTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/ApiTests/SkinsControllerTest.cs @@ -71,7 +71,48 @@ namespace ApiTests var isSkinDto = objectResult?.Value as SkinDtoC; Assert.IsNotNull(isSkinDto); - Assert.AreEqual(total+1, await stub.SkinsMgr.GetNbItems()); + Assert.AreEqual(total + 1, await stub.SkinsMgr.GetNbItems()); + + } + + [TestMethod] + public async Task TestCountChampion() + { + //Arange + var SkinDto = new SkinDtoC + { + Name = "Project", + Description = "Test", + Icon = "", + Image = new LargeImageDto(), + Price = 900, + ChampionName = "aatrox" + }; + + //Act + var oldTotal = await stub.SkinsMgr.GetNbItems(); + var oldResult = await skins.GetCountSkins(); + await skins.Post(SkinDto); + + var objectResult = oldResult as OkObjectResult; + Assert.IsNotNull(objectResult); + + var newTotal = await stub.SkinsMgr.GetNbItems(); + var newResult = await skins.GetCountSkins(); + + //Assert + var objectResultOld = oldResult as OkObjectResult; + Assert.IsNotNull(objectResultOld); + + var objectResultNew = newResult as OkObjectResult; + Assert.IsNotNull(objectResultNew); + + Assert.AreEqual(objectResultOld.Value, oldTotal); + Assert.AreNotEqual(objectResultOld.Value, newTotal); + + Assert.AreEqual(objectResultNew.Value, newTotal); + Assert.AreNotEqual(objectResultNew.Value, oldTotal); + } @@ -90,7 +131,7 @@ namespace ApiTests }; var SkinDtoPut = new SkinDtoC { - Name = "Project", + Name = "new Project", Description = "ForTestTest", Icon = "", Image = new LargeImageDto(), @@ -109,9 +150,11 @@ namespace ApiTests var skin = objectResult?.Value as SkinDtoC; Assert.IsNotNull(skin); + Assert.AreNotEqual(SkinDto.Name, skin.Name); Assert.AreNotEqual(SkinDto.Description, skin.Description); Assert.AreNotEqual(SkinDto.Price, skin.Price); + Assert.AreEqual(SkinDtoPut.Name, skin.Name); Assert.AreEqual(SkinDtoPut.Description, skin.Description); Assert.AreEqual(SkinDtoPut.Price, skin.Price);