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.
Digitalisation_EPA_Serveur/EPAServeur.Tests/Controllers/EpInformationApiTests.cs

102 lines
3.2 KiB

using EPAServeur.Context;
using EPAServeur.IServices;
using EPAServeur.Services;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.Controllers;
using IO.Swagger.DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace EPAServeur.Tests.Controllers
{
[TestFixture]
public class EpInformationApiTests
{
#region
private EpContext context;
private ICollaborateurService collaborateurService;
private IEpInformationService epInformationService;
private ILogger<EpApiController> logger;
#endregion
#region Setup
[SetUp]
public void Setup()
{
// Utilisation d'une base de données en mémoire
var optionBuider = new DbContextOptionsBuilder<EpContext>()
.UseInMemoryDatabase("server_ep_test")
.Options;
context = new EpContext(optionBuider);
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.SaveChanges();
// Ajout du jeu de données pour les tests
DataSeeder.AddEp(context);
// Détache les entités du context car la base de données InMemory créé des conflits
// entre les clés primaires lors d'un Update ou d'un Insert
foreach (var entity in context.ChangeTracker.Entries())
{
entity.State = EntityState.Detached;
}
collaborateurService = new CollaborateurService(new CollaborateurApi(), context);
epInformationService = new EpInformationService(context, collaborateurService);
}
#endregion
[Test]
public async Task GetEpEnCours()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPEnCours(new List<long?>() { 1, 2 }, true, 1, 15, "", "", null, null);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<IEnumerable<EpInformationDTO>>(result.Value);
}
[Test]
public async Task GetEpEnCoursCount()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPEnCoursCount(new List<long?>() { 1, 2 }, true, 1, 15, "", "", null, null);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<int>(result.Value);
}
[Test]
public async Task GetEpEnSignes()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPSignes(new List<long?>() { 1, 2 }, true, 1, 15, "", "", null, null);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<IEnumerable<EpInformationDTO>>(result.Value);
}
[Test]
public async Task GetEpEnSignesCount()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPSignesCount(new List<long?>() { 1, 2 }, true, 1, 15, "", "", null, null);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<int>(result.Value);
}
}
}