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;
|
||||||
using apiLOL.Controllers;
|
using apiLOL.Controllers;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
using StubLib;
|
using StubLib;
|
||||||
|
|
||||||
namespace TestUnitaire
|
namespace TestUnitaire
|
||||||
{
|
{
|
||||||
public class TestAPILol
|
public class TestAPILol
|
||||||
{
|
{
|
||||||
[Fact]
|
[Theory]
|
||||||
public void Test1()
|
[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
|
// Arrange
|
||||||
var data = new StubData();
|
var data = new StubData();
|
||||||
var controller = new ControllerChampions(new StubData());
|
var logger = new NullLogger<ControllerChampions>();
|
||||||
var champDTO = new ChampionDTO("Charles", "Charles est un champion de League of Legends");
|
var controller = new ControllerChampions(data, logger);
|
||||||
|
var champDTO = new ChampionDTO(name, bio);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = controller.Post(champDTO);
|
// Call method POST to add a champion
|
||||||
data.ChampionsMgr.AddItem(champDTO.ToModel());
|
var result = await controller.Post(champDTO);
|
||||||
var nbItem = data.ChampionsMgr.GetNbItems();
|
// Call method GET to get the champion
|
||||||
Task<int> nbItemTask = nbItem;
|
var resultGet = await controller.GetChampion(name);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsType<OkResult>(result);
|
// IS the champion added to the list, number of champions in the list + 1
|
||||||
// Verify that the champions is added to the stub
|
Assert.Equal(name, champDTO.Name);
|
||||||
Assert.Equal(7, nbItemTask.Result);
|
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