Merge branch 'API2' of https://codefirst.iut.uca.fr/git/bastien.ollier/LOL into API2
continuous-integration/drone/push Build is failing Details

API2
bastien.ollier 2 years ago
commit df40c8ca20

@ -10,16 +10,16 @@ namespace TestUnitaire
public class TestAPILol public class TestAPILol
{ {
[Theory] [Theory]
[InlineData("Beatrice", "sdfsdfd")] [InlineData("Beatrice", "sdfsdfd", "icon.png")]
[InlineData("Maurice", "Ahri est un champion de League of Legends")] [InlineData("Maurice", "Ahri est un champion de League of Legends", "icon.png")]
[InlineData("Loupiotte", "Akali est un champion de League of Legends")] [InlineData("Loupiotte", "Akali est un champion de League of Legends", "icon.png")]
public async Task TestPostChampion(string name, string bio) public async Task TestPostChampion(string name, string bio, string icon)
{ {
// Arrange // Arrange
var data = new StubData(); var data = new StubData();
var logger = new NullLogger<ControllerChampions>(); var logger = new NullLogger<ControllerChampions>();
var controller = new ControllerChampions(data, logger); var controller = new ControllerChampions(data, logger);
var champDTO = new ChampionDTO(name, bio); var champDTO = new ChampionDTO(name, bio, icon);
// Act // Act
var nbInListBefore = data.ChampionsMgr.GetNbItems().Result; var nbInListBefore = data.ChampionsMgr.GetNbItems().Result;
@ -34,16 +34,16 @@ namespace TestUnitaire
[Theory] [Theory]
[InlineData("Beatrice", "Aatrox est un champion de League of Legends")] [InlineData("Beatrice", "Aatrox est un champion de League of Legends", "icon.png")]
[InlineData("Maurice", "Ahri est un champion de League of Legends")] [InlineData("Maurice", "Ahri est un champion de League of Legends", "icon.png")]
[InlineData("Loupiotte", "Akali est un champion de League of Legends")] [InlineData("Loupiotte", "Akali est un champion de League of Legends", "icon.png")]
public async Task TestGetChampion(string name, string bio) public async Task TestGetChampion(string name, string bio, string icon)
{ {
// Arrange // Arrange
var data = new StubData(); var data = new StubData();
var logger = new NullLogger<ControllerChampions>(); var logger = new NullLogger<ControllerChampions>();
var controller = new ControllerChampions(data, logger); var controller = new ControllerChampions(data, logger);
var champDTO = new ChampionDTO(name, bio); var champDTO = new ChampionDTO(name, bio, icon);
// Act // Act
// Call method POST to add a champion // Call method POST to add a champion
@ -52,9 +52,61 @@ namespace TestUnitaire
var resultGet = await controller.GetChampion(name); var resultGet = await controller.GetChampion(name);
// Assert // Assert
// IS the champion added to the list, number of champions in the list + 1
Assert.Equal(name, champDTO.Name); Assert.Equal(name, champDTO.Name);
Assert.Equal(bio, champDTO.Bio); Assert.Equal(bio, champDTO.Bio);
} }
[Theory]
[InlineData("Beatrice", "Nouvelle bio")]
[InlineData("Maurice", "Nouvelle bio")]
[InlineData("Loupiotte", "Nouvelle bio")]
public async Task TestPutChampion(string name, string bio)
{
// Method that change the bio of a champion. Make a test to check if the bio is changed
// Arrange
var data = new StubData();
var logger = new NullLogger<ControllerChampions>();
var controller = new ControllerChampions(data, logger);
// Act
// Add a champion
var champDTO = new ChampionDTO(name, "Ancienne bio", "icon.png");
var resultPost = await controller.Post(champDTO);
// Call method PUT to change the bio of a champion
var resultPut = await controller.Put(name, bio);
var champion = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
var bioOfChampion = champion.Bio;
// Assert
// Does the bio of the champion is changed
Assert.Equal(bio, bioOfChampion);
}
[Theory]
[InlineData("Beatrice")]
[InlineData("Maurice")]
[InlineData("Loupiotte")]
public async Task TestDeleteChampion(string name)
{
// Method that delete a champion. Make a test to check if the champion is deleted
// Arrange
var data = new StubData();
var logger = new NullLogger<ControllerChampions>();
var controller = new ControllerChampions(data, logger);
// Act
// Add a champion
var champDTO = new ChampionDTO(name, "Ancienne bio", "icon.png");
var resultPost = await controller.Post(champDTO);
// Call method DELETE to delete the champion
var resultDelete = await controller.Delete(name);
// Assert
// Does the type of the result is a OkObjectResult
Assert.IsType<OkObjectResult>(resultDelete);
}
} }
} }

@ -26,7 +26,7 @@ namespace apiLOL.Controllers
// GET: api/<ControllerLol> // GET: api/<ControllerLol>
[HttpGet] [HttpGet]
public async Task<IActionResult> Get([FromQuery]int index = 0, int count = 10, [FromQuery]string? name = "") public async Task<IActionResult> Get([FromQuery]int index = 0, int count = 10, string? name = "")
{ {
//FromQuery permet de filtrer dans la collection de champions en fonction du nom //FromQuery permet de filtrer dans la collection de champions en fonction du nom
@ -72,8 +72,6 @@ namespace apiLOL.Controllers
public async Task<IActionResult> Post(SkinDTO champDTO) public async Task<IActionResult> Post(SkinDTO champDTO)
{ {
_logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}");
try try
{ {
Champion tmp = champDTO.ToModel(); Champion tmp = champDTO.ToModel();

Loading…
Cancel
Save