Modification UT and Controller Champions, also i add Mapper and Dto for Rune, Skill class

Documentation_UT_Client
Emre KARTAL 2 years ago
parent 671c880fcb
commit 80b4330003

Binary file not shown.

@ -32,6 +32,10 @@ namespace ApiLol.Controllers
{ {
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name,0, await _manager.ChampionsMgr.GetNbItems())) var dtos = (await _manager.ChampionsMgr.GetItemsByName(name,0, await _manager.ChampionsMgr.GetNbItems()))
.Select(x => x.ToDto()); .Select(x => x.ToDto());
if(dtos == null)
{
return NotFound();
}
return Ok(dtos); return Ok(dtos);
} }
@ -40,21 +44,21 @@ namespace ApiLol.Controllers
public async Task<IActionResult> Post([FromBody] ChampionDto champion) public async Task<IActionResult> Post([FromBody] ChampionDto champion)
{ {
return CreatedAtAction(nameof(Get), return CreatedAtAction(nameof(Get),
await _manager.ChampionsMgr.AddItem(champion.ToModel())); (await _manager.ChampionsMgr.AddItem(champion.ToModel())).ToDto());
} }
// PUT api/<ValuesController>/5 /* // PUT api/<ValuesController>/5
[HttpPut("{id}")] [HttpPut("{name}")]
public void Put(int id, [FromBody] string value) public async void Put(string name, [FromBody] ChampionDto champion)
{ {
return Ok(await _manager.ChampionsMgr.UpdateItem(, champion.ToModel()));
} }*/
// DELETE api/<ValuesController>/5 // DELETE api/<ValuesController>/5
[HttpDelete("{id}")] [HttpDelete]
public void Delete(int id) public async Task<IActionResult> Delete([FromBody] ChampionDto champion)
{ {
return Ok(await _manager.ChampionsMgr.DeleteItem(champion.ToModel()));
} }
} }
} }

@ -10,12 +10,16 @@ namespace ApiLol.Mapper
return new ChampionDto() return new ChampionDto()
{ {
Name = champion.Name, Name = champion.Name,
Bio = champion.Bio,
}; };
} }
public static Champion ToModel(this ChampionDto championDto) public static Champion ToModel(this ChampionDto championDto)
{ {
return new Champion(championDto.Name)
{
Bio = championDto.Bio,
};
} }
} }

@ -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,
};
}*/
}
}

@ -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
};
}*/
}
}

@ -9,7 +9,7 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IDataManager, StubData>(); builder.Services.AddSingleton<IDataManager, StubData>();
var app = builder.Build(); var app = builder.Build();

@ -28,7 +28,7 @@ namespace Client
await _httpClient.PostAsJsonAsync<ChampionDto>(ApiChampions, champion); await _httpClient.PostAsJsonAsync<ChampionDto>(ApiChampions, champion);
} }
public async void Delete(ChampionDto champion) /* public async void Delete(ChampionDto champion)
{ {
await _httpClient.DeleteAsync(champion); await _httpClient.DeleteAsync(champion);
} }
@ -36,7 +36,7 @@ namespace Client
public async void Update(ChampionDto champion) public async void Update(ChampionDto champion)
{ {
await _httpClient.PutAsJsonAsync<ChampionDto>(ApiChampions, champion); await _httpClient.PutAsJsonAsync<ChampionDto>(ApiChampions, champion);
} }*/
} }
} }

@ -3,5 +3,6 @@
public class ChampionDto public class ChampionDto
{ {
public string Name { get; set; } public string Name { get; set; }
public string Bio { get; set; }
} }
} }

@ -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; }
}
}

@ -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; }
}
}

@ -10,7 +10,7 @@ namespace ApiTests
public class ChampionsControllerTest public class ChampionsControllerTest
{ {
private readonly StubData stub; private readonly StubData stub;
private readonly ChampionsControllerTest champs; private readonly ChampionsController champs;
public ChampionsControllerTest() public ChampionsControllerTest()
{ {
stub = new StubData(); stub = new StubData();
@ -18,21 +18,21 @@ namespace ApiTests
} }
[TestMethod] [TestMethod]
public async void TestGetChampions() public async Task TestGetChampions()
{ {
//Arrange //Arrange
//Act //Act
var champion = champs.Get(); var champion = await champs.Get();
//Assert //Assert
var objectResult = champion as OkObjectResult; var objectResult = champion as OkObjectResult;
Assert.IsNotNull(objectResult); Assert.IsNotNull(objectResult);
var champions = objectResult?.Value as IEnumerable<Champion>; var champions = objectResult?.Value as IEnumerable<ChampionDto>;
Assert.IsNotNull(champions); 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 //Arange
var ChampionDto = new ChampionDto var ChampionDto = new ChampionDto
{ {
Name = "Sylas" Name = "Sylas",
Bio = "Good"
}; };
//Act //Act
var championsResult = await champs.Post(ChampionDto); var championsResult = await champs.Post(ChampionDto);
//Assert //Assert
var objectResult = championsResult as OkObjectResult; var objectResult = championsResult as CreatedAtActionResult;
Assert.IsNotNull(objectResult); Assert.IsNotNull(objectResult);
var champions = objectResult?.Value as IEnumerable<Champion>; var champions = objectResult?.Value as Champion;
Assert.IsNotNull(champions); Assert.IsNotNull(champions);
} }

Loading…
Cancel
Save