using EPAServeur.Context; using EPAServeur.Exceptions; using EPAServeur.IServices; using EPAServeur.Models.EP; using EPAServeur.Services; using IO.Swagger.ApiCollaborateur; using IO.Swagger.DTO; using IO.Swagger.Enum; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace EPAServeur.Tests.Services { public class EpDetailsServiceTests { #region variables private EpContext context; private ICollaborateurService collaborateurService; private ITransformDTO transformDTO; #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.AddEp(context); foreach (var entity in context.ChangeTracker.Entries()) { entity.State = EntityState.Detached; } transformDTO = new TransformDTO(); collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO); } #endregion #region Récupérer EP simple [TestCase(1, "301ba7f3-095e-4912-8998-a7c942dc5f23", StatutEp.Disponible)] [TestCase(2, "e7820f92-eab1-42f5-ae96-5c16e71ff1e6", StatutEp.DatesProposees)] [TestCase(5, "17b87130-0e9d-4b78-b0e3-a11e5f70318d", StatutEp.AttenteEntretien)] [TestCase(14, "a0f40e2a-cc03-4032-a627-5389e1281c64", StatutEp.Signe)] public async Task GetEpById(long idEP, Guid? idCollaborateur, StatutEp statutEp) { Ep ep = await context.Ep.FindAsync(idEP); Assert.IsNotNull(ep); Assert.AreEqual(idEP, ep.IdEP); Assert.AreEqual(idCollaborateur, ep.IdCollaborateur); Assert.AreEqual(statutEp, ep.Statut); IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService); EpDTO epDTO = await epDetailsService.GetEp(ep.IdEP); Assert.IsNotNull(epDTO); Assert.AreEqual(epDTO.Collaborateur.Id, ep.IdCollaborateur); Assert.AreEqual(epDTO.Statut, ep.Statut); Assert.AreEqual(epDTO.Id, ep.IdEP); } #endregion #region Récupérer EP exceptions [TestCase(-999)] [TestCase(20)] [TestCase(100)] [TestCase(0)] public void GetEPById_NotFoundException(long idEp) { IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService); AsyncTestDelegate exception = () => epDetailsService.GetEp(idEp); Assert.ThrowsAsync(typeof(EpNotFoundException), exception); } #endregion #region Récupérer EP avec Engagements [TestCase(6, 3)] [TestCase(8, 0)] [TestCase(10, 1)] public async Task GetEPById_GetEngagement(long idEP, int count) { IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService); EpDTO epDTO = await epDetailsService.GetEp(idEP); if(count == 0) { Assert.IsNull(epDTO.Engagements); } else { Assert.IsNotNull(epDTO.Engagements); Assert.AreEqual(count, epDTO.Engagements.Count); } } #endregion #region Récupérer EP avec participant EP [TestCase(1,0)] [TestCase(3,2)] [TestCase(5,1)] [TestCase(11,2)] public async Task GetEpById_GetParticipantEP(long idEP, int count) { IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService); EpDTO epDTO = await epDetailsService.GetEp(idEP); if (count == 0) { Assert.IsNull(epDTO.Participants); } else { Assert.IsNotNull(epDTO.Participants); Assert.AreEqual(count, epDTO.Participants.Count); } } #endregion #region Récupérer EP avec CommentaireAssistant [TestCase(2, 2)] [TestCase(4, 0)] [TestCase(16, 1)] public async Task GetEpById_GetCommentairesAssistant(long idEP, int count) { IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService); EpDTO epDTO = await epDetailsService.GetEp(idEP); if (count == 0) { Assert.IsNull(epDTO.CommentairesAssistant); } else { Assert.IsNotNull(epDTO.CommentairesAssistant); Assert.AreEqual(count, epDTO.CommentairesAssistant.Count); } } #endregion #region Récupérer EP avec RDV entretiens #endregion #region Récupérer EP avec type entretien #endregion #region Récupérer EP avec demandes de délégation #endregion #region Récupérer EP avec demandes de formation #endregion #region #endregion #region #endregion #region #endregion #region #endregion } }