merge master
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
5268427070
@ -1,37 +1,59 @@
|
||||
using apiLOL;
|
||||
using apiLOL.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StubLib;
|
||||
|
||||
namespace TestUnitaire
|
||||
{
|
||||
public class TestAPILol
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
[Theory]
|
||||
[InlineData("Beatrice", "sdfsdfd")]
|
||||
[InlineData("Maurice", "Ahri est un champion de League of Legends")]
|
||||
[InlineData("Loupiotte", "Akali est un champion de League of Legends")]
|
||||
public async Task TestPostChampion(string name, string bio)
|
||||
{
|
||||
// Arrange
|
||||
var data = new StubData();
|
||||
var logger = new NullLogger<ControllerChampions>();
|
||||
var controller = new ControllerChampions(data, logger);
|
||||
var champDTO = new ChampionDTO(name, bio);
|
||||
|
||||
// Act
|
||||
var nbInListBefore = data.ChampionsMgr.GetNbItems().Result;
|
||||
var result = await controller.Post(champDTO);
|
||||
var nbInListAfter = data.ChampionsMgr.GetNbItems().Result;
|
||||
|
||||
// Assert
|
||||
// IS the champion added to the list, number of champions in the list + 1
|
||||
Assert.Equal(nbInListBefore + 1, nbInListAfter);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPostChampion()
|
||||
|
||||
[Theory]
|
||||
[InlineData("Beatrice", "Aatrox est un champion de League of Legends")]
|
||||
[InlineData("Maurice", "Ahri est un champion de League of Legends")]
|
||||
[InlineData("Loupiotte", "Akali est un champion de League of Legends")]
|
||||
public async Task TestGetChampion(string name, string bio)
|
||||
{
|
||||
// Arrange
|
||||
var data = new StubData();
|
||||
var controller = new ControllerChampions(new StubData());
|
||||
var champDTO = new ChampionDTO("Charles", "Charles est un champion de League of Legends");
|
||||
var logger = new NullLogger<ControllerChampions>();
|
||||
var controller = new ControllerChampions(data, logger);
|
||||
var champDTO = new ChampionDTO(name, bio);
|
||||
|
||||
// Act
|
||||
var result = controller.Post(champDTO);
|
||||
data.ChampionsMgr.AddItem(champDTO.ToModel());
|
||||
var nbItem = data.ChampionsMgr.GetNbItems();
|
||||
Task<int> nbItemTask = nbItem;
|
||||
// Call method POST to add a champion
|
||||
var result = await controller.Post(champDTO);
|
||||
// Call method GET to get the champion
|
||||
var resultGet = await controller.GetChampion(name);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<OkResult>(result);
|
||||
// Verify that the champions is added to the stub
|
||||
Assert.Equal(7, nbItemTask.Result);
|
||||
|
||||
// IS the champion added to the list, number of champions in the list + 1
|
||||
Assert.Equal(name, champDTO.Name);
|
||||
Assert.Equal(bio, champDTO.Bio);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace apiLOL.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateTime.Now.AddDays(index),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
namespace apiLOL
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in new issue