diff --git a/EPAServeur.Tests/Services/EpDetailsServiceTests.cs b/EPAServeur.Tests/Services/EpDetailsServiceTests.cs new file mode 100644 index 0000000..da7e86b --- /dev/null +++ b/EPAServeur.Tests/Services/EpDetailsServiceTests.cs @@ -0,0 +1,115 @@ +using EPAServeur.Context; +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 + #endregion + + #region Récupérer EP avec Engagements + #endregion + + #region Récupérer EP avec participant EP + #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 CommentaireAssistant + #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 + } +} diff --git a/EPAServeur/Context/DataSeeder.cs b/EPAServeur/Context/DataSeeder.cs index 752ad9b..a8bd56d 100644 --- a/EPAServeur/Context/DataSeeder.cs +++ b/EPAServeur/Context/DataSeeder.cs @@ -2005,5 +2005,6 @@ namespace EPAServeur.Context context.SaveChanges(); } + } } diff --git a/EPAServeur/Exceptions/EpNotFoundException.cs b/EPAServeur/Exceptions/EpNotFoundException.cs new file mode 100644 index 0000000..4684fac --- /dev/null +++ b/EPAServeur/Exceptions/EpNotFoundException.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Threading.Tasks; + +namespace EPAServeur.Exceptions +{ + + /// + /// Exceptin pour gérer les EP non trouvé + /// + public class EpNotFoundException : Exception + { + public EpNotFoundException() + { + } + + public EpNotFoundException(string message) : base(message) + { + } + + public EpNotFoundException(string message, Exception innerException) : base(message, innerException) + { + } + + protected EpNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} diff --git a/EPAServeur/Services/EpDetailsService.cs b/EPAServeur/Services/EpDetailsService.cs index 8da37fa..91d7446 100644 --- a/EPAServeur/Services/EpDetailsService.cs +++ b/EPAServeur/Services/EpDetailsService.cs @@ -1,4 +1,8 @@ -using EPAServeur.IServices; +using EPAServeur.Context; +using EPAServeur.Exceptions; +using EPAServeur.IServices; +using EPAServeur.Models.EP; +using IO.Swagger.ApiCollaborateur; using IO.Swagger.DTO; using System; using System.Collections.Generic; @@ -9,10 +13,32 @@ namespace EPAServeur.Services { public class EpDetailsService : IEpDetailsService { + private EpContext context; + private ITransformDTO transformDTO; + private ICollaborateurService collaborateurService; - public Task GetEp(long id) + public EpDetailsService(EpContext context, ITransformDTO transformDTO, ICollaborateurService collaborateurService) { - throw new NotImplementedException(); + this.context = context; + this.transformDTO = transformDTO; + this.collaborateurService = collaborateurService; + } + + public async Task GetEp(long id) + { + Ep ep = await context.Ep.FindAsync(id); + if (ep == null) + throw new EpNotFoundException(); + List guids = new List(); + guids.Add(ep.IdCollaborateur); + if (ep.IdReferent.HasValue) + guids.Add(ep.IdCollaborateur); + + IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids) ; + + EpDTO epDTO = transformDTO.EpToEpDetails(ep, collaborateurDTOs); + + return epDTO; } public void RappelSignature(long idEp) diff --git a/EPAServeur/Services/TransformDTO.cs b/EPAServeur/Services/TransformDTO.cs index 0385d70..8f6d55c 100644 --- a/EPAServeur/Services/TransformDTO.cs +++ b/EPAServeur/Services/TransformDTO.cs @@ -47,7 +47,21 @@ namespace EPAServeur.Services /// L'EP transformé en DTO public EpDTO EpToEpDetails(Ep ep, IEnumerable collaborateurDTOs) { - throw new NotImplementedException(); + return new EpDTO() + { + Id = ep.IdEP, + Collaborateur = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdCollaborateur)), + Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdCollaborateur)), + DateDisponibilite = ep.DateDisponibilite, + DatePrevisionnelle = ep.DatePrevisionnelle, + DateSaisie = ep.DateSaisie, + DateSignatureCollaborateur = ep.DateSignatureCollaborateur, + DateSignatureReferent = ep.DateSignatureReferent, + Obligatoire = ep.Obligatoire, + Statut = ep.Statut, + Type = ep.TypeEP, + Cv = ep.CV + }; } ///