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/DemandeDelegationApiTests.cs

96 lines
3.0 KiB

using EPAServeur.Context;
using EPAServeur.IServices;
using EPAServeur.Services;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.Controllers;
using IO.Swagger.DTO;
using IO.Swagger.Enum;
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 DemandeDelegationApiTests
{
#region Variables
private EpContext context;
private ILogger<DemandesDelegationApiController> logger;
IDemandeDelegationService demandeDelegationService;
private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService;
#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();
DataSeeder.AddDemandeDelegationEP(context);
// Ajout du jeu de données pour les tests
//TO DO
// 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;
}
collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, context);
demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
}
#endregion
#region Tests Api
[Test]
public void GetDemandesDelegationReferent()
{
DemandesDelegationApiController demandesDelegationApiController = new DemandesDelegationApiController(demandeDelegationService, logger);
Task<IActionResult> task = demandesDelegationApiController.GetDemandesDelegationReferent(new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"));
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<IEnumerable<DemandeDelegationDTO>>(result.Value);
}
[Test]
public void UpdateDemandeDelegation()
{
DemandesDelegationApiController demandesDelegationApiController = new DemandesDelegationApiController(demandeDelegationService, logger);
DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO()
{
Id = 1,
DateDemande = new DateTime(),
RaisonDemande = "Raison demande",
EtatDemande = EtatDemande.Rejetee,
RaisonRefus = "exemple raison refus"
};
Task<IActionResult> task = demandesDelegationApiController.UpdateDemandeDelegation(demandeDTO, demandeDTO.Id) ;
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<DemandeDelegationDTO>(result.Value);
}
#endregion
}
}