You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.9 KiB
133 lines
3.9 KiB
using APILOL.Controllers;
|
|
using APILOL.Controllers.Request;
|
|
using APILOL.Controllers.v1;
|
|
using APILOL.Controllers.v2;
|
|
using APILOL.Mapper;
|
|
using DTO;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Model;
|
|
using StubLib;
|
|
using System.Web.Http;
|
|
using System.Web.Http.Results;
|
|
using ChampionsController = APILOL.Controllers.v1.ChampionsController;
|
|
|
|
namespace TestUnitaire
|
|
{
|
|
[TestClass]
|
|
public class UnitTestChampion
|
|
{
|
|
[TestClass]
|
|
public class ChampionsControllerTest
|
|
{
|
|
private readonly StubData stub;
|
|
private readonly ChampionsController championsStub;
|
|
public ChampionsControllerTest()
|
|
{
|
|
stub = new StubData();
|
|
championsStub = new ChampionsController(stub, new NullLogger<ChampionsController>());
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task TestGetChampions()
|
|
{
|
|
//Arrange
|
|
|
|
//Act
|
|
var total = await stub.ChampionsMgr.GetNbItems();
|
|
var champion = await championsStub.Get(new PageRequest() { Offset = 0, Limit = 2 });
|
|
|
|
//Assert
|
|
var objectResult = champion as OkObjectResult;
|
|
Assert.IsNotNull(objectResult);
|
|
|
|
|
|
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task TestPostChampion()
|
|
{
|
|
//Arange
|
|
var ChampionDto = new ChampionDTO
|
|
{
|
|
Name = "Winrrard",
|
|
Bio = "The amazing champ",
|
|
Class = ChampionClass.Assassin,
|
|
Icon = "",
|
|
Image = new LargeImage(""),
|
|
Skills = new List<SkillDTO>()
|
|
{
|
|
new SkillDTO() {Name = "skill", Description="Empty", Type = SkillType.Unknown}
|
|
},
|
|
};
|
|
|
|
//Act
|
|
var championsResult = await championsStub.Post(ChampionDto);
|
|
|
|
//Assert
|
|
var objectResult = championsResult as CreatedAtActionResult;
|
|
Assert.IsNotNull(objectResult);
|
|
|
|
var champions = objectResult?.Value as ChampionDTO;
|
|
Assert.IsNotNull(champions);
|
|
|
|
Assert.AreEqual("Winrrard", champions.Name);
|
|
|
|
|
|
Assert.AreEqual("skill", champions.Skills.First().Name);
|
|
Assert.AreEqual("Empty", champions.Skills.First().Description);
|
|
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
public async Task TestPutChampion()
|
|
{
|
|
//Arange
|
|
var ChampionDto = new ChampionDTO
|
|
{
|
|
Name = "Aatrox",
|
|
Bio = "The amazing champ",
|
|
Class = ChampionClass.Assassin,
|
|
Icon = "",
|
|
Image = new LargeImage(""),
|
|
Skills = new List<SkillDTO>()
|
|
{
|
|
new SkillDTO() {Name = "skill", Description="Empty", Type = SkillType.Unknown}
|
|
},
|
|
};
|
|
|
|
//Act
|
|
var championsResult = await championsStub.PutAsync(ChampionDto.Name, ChampionDto);
|
|
|
|
//Assert
|
|
var objectResult = championsResult as OkObjectResult;
|
|
Assert.IsNull(objectResult);
|
|
|
|
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task TestDeleteChampion()
|
|
{
|
|
//Arange
|
|
|
|
|
|
//Act
|
|
var total = await stub.ChampionsMgr.GetNbItems();
|
|
var championsResult = await championsStub.Delete("Aatrox");
|
|
|
|
//Assert
|
|
var objectResult = championsResult as OkObjectResult;
|
|
Assert.IsNotNull(objectResult);
|
|
|
|
Assert.AreNotEqual(await stub.ChampionsMgr.GetNbItems(), total);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
} |