From 8f964f255ff61b484443165279292403b78d3331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Thu, 18 Feb 2021 14:16:39 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20tests=20de=20l'API=20des=20demand?= =?UTF-8?q?es=20de=20d=C3=A9l=C3=A9gation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DemandeDelegationApiTests.cs | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs diff --git a/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs b/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs new file mode 100644 index 0000000..3e1a380 --- /dev/null +++ b/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs @@ -0,0 +1,110 @@ +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 logger; + IDemandeDelegationService demandeDelegationService; + private ICollaborateurApi collaborateurApi; + #endregion + + #region Setup + [SetUp] + public void Setup() + { + // Utilisation d'une base de données en mémoire + var optionBuider = new DbContextOptionsBuilder() + .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(); + demandeDelegationService = new DemandeDelegationService(collaborateurApi, context); + } + #endregion + + + #region Tests Api + + [Test] + public void GetDemandesDelegationReferent() + { + DemandesDelegationApiController demandesDelegationApiController = new DemandesDelegationApiController(demandeDelegationService, logger); + Task task = demandesDelegationApiController.GetDemandesDelegationReferent(new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d")); + OkObjectResult result = task.Result as OkObjectResult; + Assert.AreEqual(200, result.StatusCode); + Assert.IsInstanceOf>(result.Value); + } + + [Test] + public void UpdateDemandeDelegation_Refusee() + { + 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 task = demandesDelegationApiController.UpdateDemandeDelegation(demandeDTO, demandeDTO.Id) ; + OkObjectResult result = task.Result as OkObjectResult; + Assert.AreEqual(200, result.StatusCode); + Assert.IsInstanceOf(result.Value); + } + + [Test] + public void UpdateDemandeDelegation_Validee() + { + DemandesDelegationApiController demandesDelegationApiController = new DemandesDelegationApiController(demandeDelegationService, logger); + DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO() + { + Id = 2, + DateDemande = new DateTime(), + RaisonDemande = "Raison demande", + EtatDemande = EtatDemande.Validee, + }; + Task task = demandesDelegationApiController.UpdateDemandeDelegation(demandeDTO, demandeDTO.Id); + OkObjectResult result = task.Result as OkObjectResult; + Assert.AreEqual(200, result.StatusCode); + Assert.IsInstanceOf(null, result.Value); + } + #endregion + } +}