|
|
|
@ -9,6 +9,7 @@ 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
|
|
|
|
@ -16,81 +17,115 @@ namespace TestUnitaire
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class UnitTestChampion
|
|
|
|
|
{
|
|
|
|
|
private readonly ChampionsController controller;
|
|
|
|
|
private readonly StubData stub;
|
|
|
|
|
public UnitTestChampion()
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ChampionsControllerTest
|
|
|
|
|
{
|
|
|
|
|
stub = new StubData();
|
|
|
|
|
controller = new ChampionsController(stub, new NullLogger<ChampionsController>());
|
|
|
|
|
}
|
|
|
|
|
private readonly StubData stub;
|
|
|
|
|
private readonly ChampionsController championsStub;
|
|
|
|
|
public ChampionsControllerTest()
|
|
|
|
|
{
|
|
|
|
|
stub = new StubData();
|
|
|
|
|
championsStub = new ChampionsController(stub, new NullLogger<ChampionsController>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task TestGet()
|
|
|
|
|
{
|
|
|
|
|
var champions = await controller.Get(new PageRequest());
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task TestGetChampions()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var resultObject = champions as OkObjectResult;
|
|
|
|
|
Assert.IsNotNull(resultObject);
|
|
|
|
|
//Act
|
|
|
|
|
var total = await stub.ChampionsMgr.GetNbItems();
|
|
|
|
|
var champion = await championsStub.Get(new PageRequest() { Offset = 0, Limit = 2 });
|
|
|
|
|
|
|
|
|
|
var resultType = resultObject?.Value as IEnumerable<ChampionDTO>;
|
|
|
|
|
Assert.IsNotNull(resultType);
|
|
|
|
|
//Assert
|
|
|
|
|
var objectResult = champion as OkObjectResult;
|
|
|
|
|
Assert.IsNotNull(objectResult);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(resultType.Count(), await stub.ChampionsMgr.GetNbItems());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task TestPost()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Arange
|
|
|
|
|
var champion = new ChampionDTO
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task TestPostChampion()
|
|
|
|
|
{
|
|
|
|
|
Name = "Jinx",
|
|
|
|
|
Bio = "Awesome , great, fantastic Q",
|
|
|
|
|
};
|
|
|
|
|
//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 controller.Post(champion);
|
|
|
|
|
//Act
|
|
|
|
|
var championsResult = await championsStub.Post(ChampionDto);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var objectResult = championsResult as CreatedAtActionResult;
|
|
|
|
|
Assert.IsNotNull(objectResult);
|
|
|
|
|
//Assert
|
|
|
|
|
var objectResult = championsResult as CreatedAtActionResult;
|
|
|
|
|
Assert.IsNotNull(objectResult);
|
|
|
|
|
|
|
|
|
|
var champions = objectResult?.Value as ChampionDTO;
|
|
|
|
|
Assert.IsNotNull(champions);
|
|
|
|
|
}
|
|
|
|
|
var champions = objectResult?.Value as ChampionDTO;
|
|
|
|
|
Assert.IsNotNull(champions);
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task TestDelete()
|
|
|
|
|
{
|
|
|
|
|
//Arange
|
|
|
|
|
string championName = "Aatrox";
|
|
|
|
|
Assert.AreEqual("Winrrard", champions.Name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var result = await controller.Delete(championName);
|
|
|
|
|
Assert.AreEqual("skill", champions.Skills.First().Name);
|
|
|
|
|
Assert.AreEqual("Empty", champions.Skills.First().Description);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.IsInstanceOfType(result, typeof(OkObjectResult));
|
|
|
|
|
Assert.IsTrue((await stub.ChampionsMgr.GetItemsByName(championName, 0, await stub.ChampionsMgr.GetNbItems())).Count() == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task TestUpdate()
|
|
|
|
|
{
|
|
|
|
|
//Arange
|
|
|
|
|
string championName = "Aatrox";
|
|
|
|
|
var updatedChampion = new ChampionDTO {Name = "Bibouuu", Bio = "Updated Bio" };
|
|
|
|
|
|
|
|
|
|
[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);
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var result = await controller.PutAsync(championName, updatedChampion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.IsInstanceOfType(result, typeof(OkResult));
|
|
|
|
|
Assert.IsNotNull(stub.ChampionsMgr.GetItemsByName("Bibouuu",0, await stub.ChampionsMgr.GetNbItems()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|