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

162 lines
6.0 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;
private ITransformDTO transformDTO;
#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;
}
transformDTO = new TransformDTO();
collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO);
epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
}
#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);
}
[Test]
public async Task GetEPSignesCollaborateur()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPSignesCollaborateur(new Guid("a0f40e2a-cc03-4032-a627-5389e1281c64"));
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<IEnumerable<EpInformationDTO>>(result.Value);
}
[Test]
public async Task GetProchainEPCollaborateur()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetProchainEPCollaborateur(new Guid("a0f40e2a-cc03-4032-a627-5389e1281c64"));
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<EpInformationDTO>(result.Value);
}
[Test]
public async Task GetEPSignesReferent()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPSignesReferent(new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), 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 GetEPSignesReferentCount()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPSignesReferentCount(new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), 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 GetEPEnCoursReferent()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPEnCoursReferent(new Guid("eb8b0f33-f529-4985-861e-1207f3312bb5"), true, 1, 15, "", "", true, null, null);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<IEnumerable<EpInformationDTO>>(result.Value);
}
[Test]
public async Task GetEPEnCoursReferentCount()
{
EpApiController epApiController = new EpApiController(epInformationService, logger);
Task<IActionResult> task = epApiController.GetEPEnCoursReferentCount(new Guid("eb8b0f33-f529-4985-861e-1207f3312bb5"), true, 1, 15, "", "", true, null, null);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<int>(result.Value);
}
}
}