From 80b433000385b01a450935b5f87be67efad8b800 Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Thu, 2 Feb 2023 12:01:35 +0100 Subject: [PATCH] Modification UT and Controller Champions, also i add Mapper and Dto for Rune, Skill class --- .vs/LolProject/v17/.suo | Bin 13824 -> 12800 bytes .../ApiLol/Controllers/ChampionsController.cs | 22 ++++++++------- .../Sources/ApiLol/Mapper/ChampionMapper.cs | 6 ++++- .../Sources/ApiLol/Mapper/RuneMapper.cs | 25 ++++++++++++++++++ .../Sources/ApiLol/Mapper/SkillMapper.cs | 25 ++++++++++++++++++ .../Sources/ApiLol/Program.cs | 2 +- .../Sources/Client/ChampionHttpClient.cs | 4 +-- .../Sources/DTO/ChampionDto.cs | 1 + .../Sources/DTO/RuneDto.cs | 15 +++++++++++ .../Sources/DTO/SkillDto.cs | 14 ++++++++++ .../Tests/ApiTests/ChampionsControllerTest.cs | 17 ++++++------ 11 files changed, 110 insertions(+), 21 deletions(-) create mode 100644 src/EntityFramework_LoL/Sources/ApiLol/Mapper/RuneMapper.cs create mode 100644 src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkillMapper.cs create mode 100644 src/EntityFramework_LoL/Sources/DTO/RuneDto.cs create mode 100644 src/EntityFramework_LoL/Sources/DTO/SkillDto.cs diff --git a/.vs/LolProject/v17/.suo b/.vs/LolProject/v17/.suo index d3190eff2d84debdc910ff8157ca8d8816dcad71..ba8264e62d096d8574c973815b9d12cfccab3b64 100644 GIT binary patch delta 1142 zcmb_a&1+LZ5YN7BnxyW_hs{UZB#p)dMU#@3uiAr<(o!M`+ zA~ti;ll}?PclA(6K}AqJdJ~HOK@QEuI`fh(saR2PVA$Q+-|TPZx6{4f-F#D1m>&mMm-ePtndqFj zaPLR=pu5mjbczdD;b9gw8~hd9x$EjFwK4OzTTlOz83xYe3USeUWM^^jM)!_mL0pMX z)Cs;bP1x3eb@VO@|; z^j9*?LBa-L=&izjGz*4L7iTacGM1S3&bnZStrq7g?z7vV8X)&|A}t0f1G z9fx70D&}w(8pEu-askIRS`!4J2|dp3k_^!r>?_z+>@%#UuR(WVRb?}X3QQsg3%ZDm z12Vl=xu6%g;_Jz4~Im>$UYr>8RzsRp!3jRU<$m#OO-~XN| z-B%f@_m5hc!&H@7n#jgR<9ksTG!Z8h9K`CUi(?KJ>rAy#xAbLF9xwuRf`OUnoTGe~6N&@3B zDUA0vUhiEtvmaO-9tiJYLr|eHCBmw|#9JtW&*!5ru!t;;;HDduBmhiIp5VCZLH$lX zCsm{T zEC&ZeMLvpF!sniVJ#26h4KCnzBPX_u`T)6y(`MyXi3 zsc5rVRawsGEG1vgV<$7_v}I0X8Ir=x~nc{`w9n%1Z6@`}Au Rw(Yz3@2pU7>xHR?{|B*{)J6aR diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs index e1f2dda..ad2f3f2 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs @@ -32,6 +32,10 @@ namespace ApiLol.Controllers { var dtos = (await _manager.ChampionsMgr.GetItemsByName(name,0, await _manager.ChampionsMgr.GetNbItems())) .Select(x => x.ToDto()); + if(dtos == null) + { + return NotFound(); + } return Ok(dtos); } @@ -40,21 +44,21 @@ namespace ApiLol.Controllers public async Task Post([FromBody] ChampionDto champion) { return CreatedAtAction(nameof(Get), - await _manager.ChampionsMgr.AddItem(champion.ToModel())); + (await _manager.ChampionsMgr.AddItem(champion.ToModel())).ToDto()); } - // PUT api//5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) +/* // PUT api//5 + [HttpPut("{name}")] + public async void Put(string name, [FromBody] ChampionDto champion) { - - } + return Ok(await _manager.ChampionsMgr.UpdateItem(, champion.ToModel())); + }*/ // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) + [HttpDelete] + public async Task Delete([FromBody] ChampionDto champion) { - + return Ok(await _manager.ChampionsMgr.DeleteItem(champion.ToModel())); } } } diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs index 97fe7ca..32ab8a7 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs @@ -10,12 +10,16 @@ namespace ApiLol.Mapper return new ChampionDto() { Name = champion.Name, + Bio = champion.Bio, }; } public static Champion ToModel(this ChampionDto championDto) { - + return new Champion(championDto.Name) + { + Bio = championDto.Bio, + }; } } diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/RuneMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/RuneMapper.cs new file mode 100644 index 0000000..fcd88a6 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/RuneMapper.cs @@ -0,0 +1,25 @@ +using DTO; +using Model; + +namespace ApiLol.Mapper +{ + public static class RuneMapper + { + public static RuneDto ToDto(this Rune rune) + { + return new RuneDto() + { + Name = rune.Name, + Description = rune.Description, + }; + } + +/* public static Rune ToModel(this RuneDto rune) + { + return new Rune(rune.Name) + { + Description = rune.Description, + }; + }*/ + } +} diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkillMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkillMapper.cs new file mode 100644 index 0000000..768caf7 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/SkillMapper.cs @@ -0,0 +1,25 @@ +using DTO; +using Model; + +namespace ApiLol.Mapper +{ + public static class SkillMapper + { + public static SkillDto ToDto(this Skill skill) + { + return new SkillDto() + { + Name = skill.Name, + Description = skill.Description, + }; + } + +/* public static Skill ToModel(this SkillDto skill) + { + return new Skill(skill.Name) + { + Description = skill.Description + }; + }*/ + } +} diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Program.cs b/src/EntityFramework_LoL/Sources/ApiLol/Program.cs index 5952afd..e6ed0a5 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Program.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Program.cs @@ -9,7 +9,7 @@ builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddScoped(); +builder.Services.AddSingleton(); var app = builder.Build(); diff --git a/src/EntityFramework_LoL/Sources/Client/ChampionHttpClient.cs b/src/EntityFramework_LoL/Sources/Client/ChampionHttpClient.cs index ff63eb9..2fa8957 100644 --- a/src/EntityFramework_LoL/Sources/Client/ChampionHttpClient.cs +++ b/src/EntityFramework_LoL/Sources/Client/ChampionHttpClient.cs @@ -28,7 +28,7 @@ namespace Client await _httpClient.PostAsJsonAsync(ApiChampions, champion); } - public async void Delete(ChampionDto champion) +/* public async void Delete(ChampionDto champion) { await _httpClient.DeleteAsync(champion); } @@ -36,7 +36,7 @@ namespace Client public async void Update(ChampionDto champion) { await _httpClient.PutAsJsonAsync(ApiChampions, champion); - } + }*/ } } diff --git a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs index 5c7ecf2..f19a03b 100644 --- a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs +++ b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs @@ -3,5 +3,6 @@ public class ChampionDto { public string Name { get; set; } + public string Bio { get; set; } } } \ No newline at end of file diff --git a/src/EntityFramework_LoL/Sources/DTO/RuneDto.cs b/src/EntityFramework_LoL/Sources/DTO/RuneDto.cs new file mode 100644 index 0000000..f5afb80 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/RuneDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class RuneDto + { + public string Name { get; set; } + public string Description { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/DTO/SkillDto.cs b/src/EntityFramework_LoL/Sources/DTO/SkillDto.cs new file mode 100644 index 0000000..77372ab --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/SkillDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class SkillDto + { + public string Name { get; set; } + public string Description { get; set; } + } +} diff --git a/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTest.cs b/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTest.cs index b7468b5..a0b976c 100644 --- a/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/ApiTests/ChampionsControllerTest.cs @@ -10,7 +10,7 @@ namespace ApiTests public class ChampionsControllerTest { private readonly StubData stub; - private readonly ChampionsControllerTest champs; + private readonly ChampionsController champs; public ChampionsControllerTest() { stub = new StubData(); @@ -18,21 +18,21 @@ namespace ApiTests } [TestMethod] - public async void TestGetChampions() + public async Task TestGetChampions() { //Arrange //Act - var champion = champs.Get(); + var champion = await champs.Get(); //Assert var objectResult = champion as OkObjectResult; Assert.IsNotNull(objectResult); - var champions = objectResult?.Value as IEnumerable; + var champions = objectResult?.Value as IEnumerable; Assert.IsNotNull(champions); - Assert.AreEqual(champions.Count(), await stub.ChampionsMgr.GetItems(0,5).Count()); + Assert.AreEqual(champions.Count(), await stub.ChampionsMgr.GetNbItems()); } @@ -42,17 +42,18 @@ namespace ApiTests //Arange var ChampionDto = new ChampionDto { - Name = "Sylas" + Name = "Sylas", + Bio = "Good" }; //Act var championsResult = await champs.Post(ChampionDto); //Assert - var objectResult = championsResult as OkObjectResult; + var objectResult = championsResult as CreatedAtActionResult; Assert.IsNotNull(objectResult); - var champions = objectResult?.Value as IEnumerable; + var champions = objectResult?.Value as Champion; Assert.IsNotNull(champions); }