Merge pull request 'Pagination et Filtre' (#10) from pagination into master
continuous-integration/drone/push Build is failing Details

Reviewed-on: #10
Le build ne réussit pas a cause du token, on ignorera donc le problème pour l'instant
pull/11/head
Corentin RICHARD 2 years ago
commit ae1198e623

@ -3,6 +3,7 @@ using Model;
using StubLib;
using DTO;
using DTO.Mapper;
using System.CodeDom.Compiler;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -19,26 +20,49 @@ namespace API_LoL.Controllers
private IChampionsManager ChampionsManager;
// GET: api/<ChampionController>
// GET api/<ChampionController>/5
[HttpGet]
public async Task<IActionResult> Get()
public async Task<IActionResult> Get(String? name= null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
{
var list = await ChampionsManager.GetItems(0,await ChampionsManager.GetNbItems());
if (list.Count() != 0) {
return Ok(list.Select(champion => champion?.toDTO()));
}else {
return NoContent();
if (size - index > 10)
{
return BadRequest();
}
if (!string.IsNullOrEmpty(name))
{
var list = await ChampionsManager.GetItemsByName(name, index,size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.toDTO()));
}
else { return NoContent(); }
}else if(!string.IsNullOrEmpty(skill)) {
var list = await ChampionsManager.GetItemsBySkill(skill, index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.toDTO()));
}
else { return NoContent(); }
}
else if(!string.IsNullOrEmpty (characteristic)) {
var list = await ChampionsManager.GetItems(index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.toDTO()));
}
else { return NoContent(); }
}
else {
var list = await ChampionsManager.GetItems(index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.toDTO()));
}
else { return NoContent(); }
}
}
// GET api/<ChampionController>/5
/*
[HttpGet("{id}")]
public string Get(String name)
{
return "value";
}*/
// POST api/<ChampionController>
[HttpPost]
public async Task<IActionResult> Post(ChampionDTO champion)

@ -0,0 +1,85 @@
using API_LoL.Controllers;
using DTO;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Model;
using StubLib;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace Api_UT
{
[TestClass]
public class ChampionControllerTest
{
ChampionsController api = new ChampionsController(new StubData());
[TestMethod]
public async Task Get_Default_OkList()
{
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") };
IActionResult a = await api.Get();
a.Should().NotBeNull();
var aObject = a as OkObjectResult;
aObject.Should().NotBeNull();
var championresult = aObject.Value as IEnumerable<ChampionDTO>;
list.Should().BeEquivalentTo(championresult);
}
[TestMethod]
public async Task Get_MoreThanLimit_BadRequest()
{
IActionResult a = await api.Get(index :0,size :11);
a.Should().NotBeNull();
a.Should().BeOfType<BadRequestResult>();
}
[TestMethod]
public async Task Get_2First_OkListOf2()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", ""), new ChampionDTO("Aatrox", "", "") };
IActionResult a = await api.Get(index: 0,size: 2);
a.Should().NotBeNull();
a.Should().BeOfType<OkObjectResult>();
var aObject = a as OkObjectResult;
aObject.Should().NotBeNull();
var championresult = aObject.Value as IEnumerable<ChampionDTO>;
list.Should().BeEquivalentTo(championresult);
}
[TestMethod]
public async Task Get_FilterAName_OkListOf5()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", ""), new ChampionDTO("Akshan", "", "") };
IActionResult a = await api.Get(name: "Ak");
a.Should().NotBeNull();
a.Should().BeOfType<OkObjectResult>();
var aObject = a as OkObjectResult;
aObject.Should().NotBeNull();
var championresult = aObject.Value as IEnumerable<ChampionDTO>;
list.Should().BeEquivalentTo(championresult);
}
[TestMethod]
public async Task Post_ValidChampion_Created()
{
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon"));
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
}
}
}

@ -1,45 +0,0 @@
using API_LoL.Controllers;
using DTO;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Model;
using StubLib;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace Api_UT
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public async Task TestGet()
{
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") };
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Get();
/// utilisation du nuggets fluentAssertion
//Assert.IsNotNull(a);
a.Should().NotBeNull();
//Assert.AreEqual(list,((OkObjectResult)a).Value);
var aObject = a as OkObjectResult;
aObject.Should().NotBeNull();
var championresult = aObject.Value as IEnumerable<ChampionDTO>;
list.Should().BeEquivalentTo(championresult);
}
[TestMethod]
public async Task TestPostValid()
{
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon"));
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
}
}
}

@ -28,8 +28,8 @@ namespace EntityFramework
[Required]
public string Icon { get; set; }
public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
private HashSet<Skill> skills = new HashSet<Skill>();
//public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
//private HashSet<Skill> skills = new HashSet<Skill>();
public ChampionEntity(string name,string bio,string icon) {
this.Name = name;
@ -43,11 +43,11 @@ namespace EntityFramework
}
/*
public bool AddSkill(Skill skill)
=> skills.Add(skill);
public bool RemoveSkill(Skill skill)
=> skills.Remove(skill);
=> skills.Remove(skill);*/
}
}

Loading…
Cancel
Save