New Mappers, Controllers and beginning SkinsControllerTest 🎉
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
a1dadd05d7
commit
701f9b4494
@ -1,127 +1,127 @@
|
|||||||
using ApiLol.Controllers;
|
using ApiLol.Controllers;
|
||||||
using ApiLol.Controllers.v2;
|
using ApiLol.Controllers.v2;
|
||||||
using DTO;
|
using DTO;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
using StubLib;
|
using StubLib;
|
||||||
|
|
||||||
namespace ApiTests
|
namespace ApiTests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class ChampionsControllerTest
|
public class ChampionsControllerTest
|
||||||
{
|
{
|
||||||
private readonly StubData stub;
|
private readonly StubData stub;
|
||||||
private readonly ChampionsController champs;
|
private readonly ChampionsController champs;
|
||||||
public ChampionsControllerTest()
|
public ChampionsControllerTest()
|
||||||
{
|
{
|
||||||
stub = new StubData();
|
stub = new StubData();
|
||||||
champs = new ChampionsController(stub, new NullLogger<ChampionsController>());
|
champs = new ChampionsController(stub, new NullLogger<ChampionsController>());
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task TestGetChampions()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
|
|
||||||
//Act
|
|
||||||
var total = await stub.ChampionsMgr.GetNbItems();
|
|
||||||
var champion = await champs.Get(new PageRequest());
|
|
||||||
|
|
||||||
//Assert
|
|
||||||
var objectResult = champion as OkObjectResult;
|
|
||||||
Assert.IsNotNull(objectResult);
|
|
||||||
|
|
||||||
var champions = objectResult?.Value as IEnumerable<ChampionDto>;
|
|
||||||
Assert.IsNotNull(champions);
|
|
||||||
|
|
||||||
Assert.AreEqual(champions.Count(), total);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestMethod]
|
|
||||||
public async Task TestPostChampion()
|
|
||||||
{
|
|
||||||
//Arange
|
|
||||||
var ChampionDto = new ChampionDto
|
|
||||||
{
|
|
||||||
Name = "Sylas",
|
|
||||||
Bio = "Good",
|
|
||||||
Class = ChampionClassDto.Tank,
|
|
||||||
Icon = "",
|
|
||||||
Image = new LargeImageDto() { Base64 = "" },
|
|
||||||
Skins = new List<SkinDto>()
|
|
||||||
};
|
|
||||||
|
|
||||||
//Act
|
|
||||||
var championsResult = await champs.Post(ChampionDto);
|
|
||||||
|
|
||||||
//Assert
|
|
||||||
var objectResult = championsResult as CreatedAtActionResult;
|
|
||||||
Assert.IsNotNull(objectResult);
|
|
||||||
|
|
||||||
var champions = objectResult?.Value as ChampionDto;
|
|
||||||
Assert.IsNotNull(champions);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task TestPutChampion()
|
public async Task TestGetChampions()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var total = await stub.ChampionsMgr.GetNbItems();
|
||||||
|
var champion = await champs.Get(new PageRequest());
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
var objectResult = champion as OkObjectResult;
|
||||||
|
Assert.IsNotNull(objectResult);
|
||||||
|
|
||||||
|
var champions = objectResult?.Value as IEnumerable<ChampionDto>;
|
||||||
|
Assert.IsNotNull(champions);
|
||||||
|
|
||||||
|
Assert.AreEqual(champions.Count(), total);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task TestPostChampion()
|
||||||
{
|
{
|
||||||
//Arange
|
//Arange
|
||||||
var ChampionDto = new ChampionDto
|
var ChampionDto = new ChampionDto
|
||||||
{
|
{
|
||||||
Name = "Sylas",
|
Name = "Sylas",
|
||||||
Bio = "Good",
|
Bio = "Good",
|
||||||
Class = ChampionClassDto.Tank,
|
Class = ChampionClassDto.Tank,
|
||||||
Icon = "",
|
Icon = "",
|
||||||
Image = new LargeImageDto() { Base64 = "" },
|
Image = new LargeImageDto() { Base64 = "" },
|
||||||
Skins = new List<SkinDto>()
|
Skins = new List<SkinDto>()
|
||||||
};
|
};
|
||||||
var ChampionDtoPut = new ChampionDto
|
|
||||||
{
|
//Act
|
||||||
Name = "Sylas",
|
var championsResult = await champs.Post(ChampionDto);
|
||||||
Bio = "Bad",
|
|
||||||
Class = ChampionClassDto.Tank,
|
//Assert
|
||||||
Icon = "",
|
var objectResult = championsResult as CreatedAtActionResult;
|
||||||
Image = new LargeImageDto() { Base64 = "" },
|
Assert.IsNotNull(objectResult);
|
||||||
Skins = new List<SkinDto>()
|
|
||||||
};
|
var champions = objectResult?.Value as ChampionDto;
|
||||||
|
Assert.IsNotNull(champions);
|
||||||
//Act
|
|
||||||
await champs.Post(ChampionDto);
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task TestPutChampion()
|
||||||
|
{
|
||||||
|
//Arange
|
||||||
|
var ChampionDto = new ChampionDto
|
||||||
|
{
|
||||||
|
Name = "Sylas",
|
||||||
|
Bio = "Good",
|
||||||
|
Class = ChampionClassDto.Tank,
|
||||||
|
Icon = "",
|
||||||
|
Image = new LargeImageDto() { Base64 = "" },
|
||||||
|
Skins = new List<SkinDto>()
|
||||||
|
};
|
||||||
|
var ChampionDtoPut = new ChampionDto
|
||||||
|
{
|
||||||
|
Name = "Sylas",
|
||||||
|
Bio = "Bad",
|
||||||
|
Class = ChampionClassDto.Tank,
|
||||||
|
Icon = "",
|
||||||
|
Image = new LargeImageDto() { Base64 = "" },
|
||||||
|
Skins = new List<SkinDto>()
|
||||||
|
};
|
||||||
|
|
||||||
|
//Act
|
||||||
|
await champs.Post(ChampionDto);
|
||||||
var championsResult = await champs.Put(ChampionDto.Name, ChampionDtoPut);
|
var championsResult = await champs.Put(ChampionDto.Name, ChampionDtoPut);
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var objectResult = championsResult as OkObjectResult;
|
var objectResult = championsResult as OkObjectResult;
|
||||||
Assert.IsNotNull(objectResult);
|
Assert.IsNotNull(objectResult);
|
||||||
|
|
||||||
var champions = objectResult?.Value as ChampionDto;
|
var champions = objectResult?.Value as ChampionDto;
|
||||||
Assert.IsNotNull(champions);
|
Assert.IsNotNull(champions);
|
||||||
|
|
||||||
Assert.AreNotEqual(ChampionDto.Bio, champions.Bio);
|
Assert.AreNotEqual(ChampionDto.Bio, champions.Bio);
|
||||||
Assert.AreEqual(ChampionDtoPut.Bio, champions.Bio);
|
Assert.AreEqual(ChampionDtoPut.Bio, champions.Bio);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public async Task TestDeleteChampion()
|
public async Task TestDeleteChampion()
|
||||||
{
|
{
|
||||||
//Arange
|
//Arange
|
||||||
|
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
var total = await stub.ChampionsMgr.GetNbItems();
|
var total = await stub.ChampionsMgr.GetNbItems();
|
||||||
var championsResult = await champs.Delete("Akali");
|
var championsResult = await champs.Delete("Akali");
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var objectResult = championsResult as OkObjectResult;
|
var objectResult = championsResult as OkObjectResult;
|
||||||
Assert.IsNotNull(objectResult);
|
Assert.IsNotNull(objectResult);
|
||||||
|
|
||||||
Assert.AreEqual(objectResult.Value, true);
|
Assert.AreEqual(objectResult.Value, true);
|
||||||
Assert.AreNotEqual(await stub.ChampionsMgr.GetNbItems(), total);
|
Assert.AreNotEqual(await stub.ChampionsMgr.GetNbItems(), total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue