|
|
|
@ -0,0 +1,101 @@
|
|
|
|
|
using API.Controllers;
|
|
|
|
|
using Dto;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Shared;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using TestAPI.Extensions;
|
|
|
|
|
|
|
|
|
|
namespace TestAPI
|
|
|
|
|
{
|
|
|
|
|
public class LessonUnitTest
|
|
|
|
|
{
|
|
|
|
|
private readonly Mock<ILessonService<LessonDTO>> lessonService;
|
|
|
|
|
|
|
|
|
|
public LessonUnitTest()
|
|
|
|
|
{
|
|
|
|
|
lessonService = new Mock<ILessonService<LessonDTO>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetLessonsListSuccess()
|
|
|
|
|
{
|
|
|
|
|
var lessonList = GetLessonsData();
|
|
|
|
|
lessonService.Setup(x => x.GetLessons(1, 4, 0))
|
|
|
|
|
.Returns(lessonList);
|
|
|
|
|
var LessonsController = new LessonsController(lessonService.Object, new NullLogger<LessonsController>());
|
|
|
|
|
|
|
|
|
|
var lessonsResult = LessonsController.GetLessons(1, 4, 0);
|
|
|
|
|
|
|
|
|
|
if (lessonsResult is OkObjectResult okObjectResult)
|
|
|
|
|
{
|
|
|
|
|
var valeur = okObjectResult.Value;
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(valeur);
|
|
|
|
|
Assert.Equal(GetLessonsData().ToString(), valeur.ToString());
|
|
|
|
|
Assert.True(lessonList.SequenceEqual(valeur as IEnumerable<LessonDTO>, new LessonIdEqualityComparer()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GetLessonsListFail()
|
|
|
|
|
{
|
|
|
|
|
lessonService.Setup(x => x.GetLessons(1, 4, 0))
|
|
|
|
|
.Returns(new List<LessonDTO>());
|
|
|
|
|
var LessonsController = new LessonsController(lessonService.Object, new NullLogger<LessonsController>());
|
|
|
|
|
|
|
|
|
|
var lessonsResult = LessonsController.GetLessons(2, 3, 0);
|
|
|
|
|
|
|
|
|
|
if (lessonsResult is StatusCodeResult statusCodeResult && statusCodeResult.StatusCode == 204)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Assert.IsNotType<OkObjectResult>(lessonsResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<LessonDTO> GetLessonsData()
|
|
|
|
|
{
|
|
|
|
|
List<LessonDTO> lessonsData = new List<LessonDTO>(4)
|
|
|
|
|
{
|
|
|
|
|
new (1,"Le titre", "Clément",new DateOnly(2024,03,10)),
|
|
|
|
|
new (2,"Pas titre", "Erwan",new DateOnly(2024,02,11)),
|
|
|
|
|
new (3,"Chiant la", "Une personne",new DateOnly(2012,12,25)),
|
|
|
|
|
new ("Les fleurs du mal", "Baudelaire",new DateOnly(1872,10,01)),
|
|
|
|
|
};
|
|
|
|
|
return lessonsData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|