From 586702001ffd87bacf7a683d783808986a41baea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Wed, 24 Feb 2021 13:09:26 +0100 Subject: [PATCH] =?UTF-8?q?Tests=20et=20impl=C3=A9mentation=20de=20la=20r?= =?UTF-8?q?=C3=A9cup=C3=A9ration=20des=20EP=20en=20cours=20et=20sign=C3=A9?= =?UTF-8?q?s=20d'un=20r=C3=A9f=C3=A9rent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/EpInformationTests.cs | 100 ++++++++++++++-- EPAServeur/Services/EpInformationService.cs | 113 ++++++++---------- 2 files changed, 140 insertions(+), 73 deletions(-) diff --git a/EPAServeur.Tests/Services/EpInformationTests.cs b/EPAServeur.Tests/Services/EpInformationTests.cs index 4729cbe..eaea6ff 100644 --- a/EPAServeur.Tests/Services/EpInformationTests.cs +++ b/EPAServeur.Tests/Services/EpInformationTests.cs @@ -71,14 +71,14 @@ namespace EPAServeur.Tests.Services } } - + [Test] public async Task GetEpEnCours_OrleansTours() { IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1,2 }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPEnCoursCount(new List { 1, 2 }, true, 1, 15, "", "", null, null); - Assert.AreEqual(count, 8); + Assert.AreEqual(count, 6); Assert.AreEqual(count, epInformationDTOs.Count()); long? bu; foreach(EpInformationDTO ep in epInformationDTOs) @@ -146,9 +146,11 @@ namespace EPAServeur.Tests.Services [TestCase("agence")] [TestCase("collaborateur")] [TestCase("referent")] - [TestCase("date")] + [TestCase("dateentretien")] [TestCase("typeep")] - [TestCase("etatep")] + [TestCase("statutep")] + [TestCase("datearrivee")] + [TestCase("datedisponibilite")] public async Task GetEpEnCours_TriColonneDESC(string tri) { IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); @@ -165,20 +167,26 @@ namespace EPAServeur.Tests.Services compare = ep1.Collaborateur.BusinessUnit.Nom.CompareTo(ep2.Collaborateur.BusinessUnit.Nom); break; case "collaborateur": - compare = (ep1.Collaborateur.Nom + " " + ep1.Collaborateur.Prenom).CompareTo(ep2.Collaborateur.Nom + " " + ep2.Collaborateur.Prenom); + compare = (ep1.Collaborateur.Nom + " " + ep1.Collaborateur.Prenom).CompareTo((ep2.Collaborateur.Nom + " " + ep2.Collaborateur.Prenom)); break; case "referent": compare = (ep1.Referent.Nom + " " + ep1.Referent.Prenom).CompareTo((ep2.Referent.Nom + " " + ep2.Referent.Prenom)); break; - case "date": + case "dateentretien": compare = ep1.DatePrevisionnelle.Value.CompareTo(ep2.DatePrevisionnelle.Value); break; case "typeep": compare = ep1.Type.CompareTo(ep2.Type); break; - case "etatep": + case "statutep": compare = ep1.Statut.CompareTo(ep2.Statut); break; + case "datearrivee": + compare = ep1.Collaborateur.DateArrivee.Value.CompareTo(ep2.Collaborateur.DateArrivee.Value); + break; + case "datedisponibilite": + compare = ep1.DateDisponibilite.Value.CompareTo(ep2.DateDisponibilite.Value); + break; } Assert.IsTrue(compare >= 0); Assert.IsTrue(EstEpEnCours(ep1.Statut)); @@ -306,8 +314,11 @@ namespace EPAServeur.Tests.Services [TestCase("agence")] [TestCase("collaborateur")] [TestCase("referent")] - [TestCase("date")] + [TestCase("dateentretien")] [TestCase("typeep")] + [TestCase("statutep")] + [TestCase("datearrivee")] + [TestCase("datedisponibilite")] public async Task GetEpSignes_TriColonneASC(string tri) { IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); @@ -329,12 +340,21 @@ namespace EPAServeur.Tests.Services case "referent": compare = (ep1.Referent.Nom + " " + ep1.Referent.Prenom).CompareTo((ep2.Referent.Nom + " " + ep2.Referent.Prenom)); break; - case "date": + case "dateentretien": compare = ep1.DatePrevisionnelle.Value.CompareTo(ep2.DatePrevisionnelle.Value); break; case "typeep": compare = ep1.Type.CompareTo(ep2.Type); break; + case "statutep": + compare = ep1.Statut.CompareTo(ep2.Statut); + break; + case "datearrivee": + compare = ep1.Collaborateur.DateArrivee.Value.CompareTo(ep2.Collaborateur.DateArrivee.Value); + break; + case "datedisponibilite": + compare = ep1.DateDisponibilite.Value.CompareTo(ep2.DateDisponibilite.Value); + break; } Assert.IsTrue(compare <= 0); @@ -348,8 +368,11 @@ namespace EPAServeur.Tests.Services [TestCase("agence")] [TestCase("collaborateur")] [TestCase("referent")] - [TestCase("date")] + [TestCase("dateentretien")] [TestCase("typeep")] + [TestCase("statutep")] + [TestCase("datearrivee")] + [TestCase("datedisponibilite")] public async Task GetEpSignes_TriColonneDESC(string tri) { IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); @@ -366,20 +389,26 @@ namespace EPAServeur.Tests.Services compare = ep1.Collaborateur.BusinessUnit.Nom.CompareTo(ep2.Collaborateur.BusinessUnit.Nom); break; case "collaborateur": - compare = (ep1.Collaborateur.Nom + " " + ep1.Collaborateur.Prenom).CompareTo(ep2.Collaborateur.Nom + " " + ep2.Collaborateur.Prenom); + compare = (ep1.Collaborateur.Nom + " " + ep1.Collaborateur.Prenom).CompareTo((ep2.Collaborateur.Nom + " " + ep2.Collaborateur.Prenom)); break; case "referent": compare = (ep1.Referent.Nom + " " + ep1.Referent.Prenom).CompareTo((ep2.Referent.Nom + " " + ep2.Referent.Prenom)); break; - case "date": + case "dateentretien": compare = ep1.DatePrevisionnelle.Value.CompareTo(ep2.DatePrevisionnelle.Value); break; case "typeep": compare = ep1.Type.CompareTo(ep2.Type); break; - case "etatep": + case "statutep": compare = ep1.Statut.CompareTo(ep2.Statut); break; + case "datearrivee": + compare = ep1.Collaborateur.DateArrivee.Value.CompareTo(ep2.Collaborateur.DateArrivee.Value); + break; + case "datedisponibilite": + compare = ep1.DateDisponibilite.Value.CompareTo(ep2.DateDisponibilite.Value); + break; } Assert.IsTrue(compare >= 0); @@ -468,6 +497,51 @@ namespace EPAServeur.Tests.Services #endregion + #region Récupération des EP signés d'un collaborateur + [TestCase("ea027734-ff0f-4308-8879-133a09fb3c46", 1)] + [TestCase("56e3d82d-4be4-4449-a1f7-b4004b6bd186", 1)] + [TestCase("3f276ab8-727a-4e26-ad5d-4d296158688e", 1)] + [TestCase("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d", 1)] + [TestCase("eb8b0f33-f529-4985-861e-1207f3312bb5", 2)] + [TestCase("ea027734-ff0f-4308-8879-133a09fb3c46", 1)] + [TestCase("80220063-a5fa-472b-b610-2e350566df98", 1)] + public async Task GetEPCoursReferent(Guid idReferent, int count) + { + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEnumerable epInformationDTOs = await epInformationService.GetEPEnCoursReferent(idReferent, true, 1, 15, "", "", null, null); + int epCount = await epInformationService.GetEPEnCoursReferentCount(idReferent, true, 1, 15, "", "", null, null); + Assert.AreEqual(epCount, count); + foreach(EpInformationDTO ep in epInformationDTOs) + { + Assert.AreEqual(ep.Referent.Id, idReferent); + Assert.IsTrue(EstEpEnCours(ep.Statut)); + } + } + #endregion + + #region Récupération des EP + [TestCase("56e3d82d-4be4-4449-a1f7-b4004b6bd186", 1)] + [TestCase("3f276ab8-727a-4e26-ad5d-4d296158688e", 1)] + [TestCase("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d", 1)] + [TestCase("eb8b0f33-f529-4985-861e-1207f3312bb5", 2)] + [TestCase("d4fc247b-015a-44d6-8f3e-a52f0902d2bf", 1)] + [TestCase("b799a9de-7743-435e-933f-7f730affc5ae", 1)] + [TestCase("ea027734-ff0f-4308-8879-133a09fb3c46", 1)] + public async Task GetEPEnSignesReferent(Guid idReferent, int count) + { + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEnumerable epInformationDTOs = await epInformationService.GetEPSignesReferent(idReferent, true, 1, 15, "", "", null, null); + int epCount = await epInformationService.GetEPSignesReferentCount(idReferent, true, 1, 15, "", "", null, null); + Assert.AreEqual(epCount, count); + foreach (EpInformationDTO ep in epInformationDTOs) + { + Assert.AreEqual(ep.Referent.Id, idReferent); + Assert.IsTrue(ep.Statut.Equals(StatutEp.Signe)); + } + } + #endregion + + #region méthodes privées private bool EstEpEnCours(StatutEp statut) { diff --git a/EPAServeur/Services/EpInformationService.cs b/EPAServeur/Services/EpInformationService.cs index 1e72591..c0cdc1b 100644 --- a/EPAServeur/Services/EpInformationService.cs +++ b/EPAServeur/Services/EpInformationService.cs @@ -34,24 +34,8 @@ namespace EPAServeur.Services { IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).AsEnumerable().Where(ep => EstEpEnCours(ep.Statut)); - eps = TriDate(eps, dateDebut, dateFin); - - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); - - - IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); - - IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); - - if (texte != null && texte.Length > 0) - epDTOs = epDTOs.Where(e => TriTexte(e, texte)); - - epDTOs = TriColonne(epDTOs, tri); - - if (asc != null && asc.HasValue && !asc.Value) - epDTOs = epDTOs.Reverse(); - return SkipAndTake(epDTOs, numPage, parPage); + return await GetEpInformationDTOs(eps, asc, numPage, parPage, texte, tri, dateDebut, dateFin); } @@ -59,19 +43,8 @@ namespace EPAServeur.Services public async Task GetEPEnCoursCount(List idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).AsEnumerable().Where(ep => EstEpEnCours(ep.Statut)); - eps = TriDate(eps, dateDebut, dateFin); - - - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); - - IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); - - IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); - if( texte != null && texte.Length > 0) - epDTOs = epDTOs.Where(e => TriTexte(e, texte)); - - return epDTOs.Count(); + return await GetEpInformationDTOsCount(eps, texte, dateDebut, dateFin); } public async Task> GetEPEnCoursCollaborateurParticipant(Guid? idCollaborateur) @@ -81,34 +54,23 @@ namespace EPAServeur.Services public async Task> GetEPEnCoursReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { - throw new NotImplementedException(); + IEnumerable eps = context.Ep.Where(ep => ep.IdReferent.Equals(idReferent)).AsEnumerable().Where(ep => EstEpEnCours(ep.Statut)); + + return await GetEpInformationDTOs(eps, asc, numPage, parPage, texte, tri, dateDebut, dateFin); } public async Task GetEPEnCoursReferentCount(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { - throw new NotImplementedException(); + IEnumerable eps = context.Ep.Where(ep => ep.IdReferent.Equals(idReferent)).AsEnumerable().Where(ep => EstEpEnCours(ep.Statut)); + + return await GetEpInformationDTOsCount(eps, texte, dateDebut, dateFin); } public async Task> GetEPSignes(List idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => ep.Statut == StatutEp.Signe); - eps = TriDate(eps, dateDebut, dateFin); - - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); - - IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); - IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); - - if (texte != null && texte.Length > 0) - epDTOs = epDTOs.Where(e => TriTexte(e, texte)); - - epDTOs = TriColonne(epDTOs, tri); - - if (asc != null && asc.HasValue && !asc.Value) - epDTOs = epDTOs.Reverse(); - - return SkipAndTake(epDTOs, numPage, parPage); + return await GetEpInformationDTOs(eps, asc, numPage, parPage, texte, tri, dateDebut, dateFin); } public async Task> GetEPSignesCollaborateur(Guid? idCollaborateur) @@ -119,28 +81,20 @@ namespace EPAServeur.Services public async Task GetEPSignesCount(List idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { IEnumerable eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => ep.Statut == StatutEp.Signe); - eps = TriDate(eps, dateDebut, dateFin); - - List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); - - IEnumerable collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids); - - IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); - if (texte != null && texte.Length > 0) - epDTOs = epDTOs.Where(e => TriTexte(e, texte)); - - return epDTOs.Count(); + return await GetEpInformationDTOsCount(eps, texte, dateDebut, dateFin); } public async Task> GetEPSignesReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { - throw new NotImplementedException(); + IEnumerable eps = context.Ep.Where(ep => ep.IdReferent.Equals(idReferent)).Where(ep => ep.Statut.Equals(StatutEp.Signe)); + return await GetEpInformationDTOs(eps, asc, numPage, parPage, texte, tri, dateDebut, dateFin); } public async Task GetEPSignesReferentCount(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { - throw new NotImplementedException(); + IEnumerable eps = context.Ep.Where(ep => ep.IdReferent.Equals(idReferent)).Where(ep => ep.Statut.Equals(StatutEp.Signe)); + return await GetEpInformationDTOsCount(eps, texte, dateDebut, dateFin); } public async Task GetProchainEPCollaborateur(Guid? idCollaborateur) @@ -150,6 +104,39 @@ namespace EPAServeur.Services #endregion #region méthodes privées + + private async Task> GetEpInformationDTOs(IEnumerable eps, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) + { + eps = TriDate(eps, dateDebut, dateFin); + + IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(eps); + IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); + + if (!string.IsNullOrEmpty(texte)) + epDTOs = epDTOs.Where(e => TriTexte(e, texte)); + + epDTOs = TriColonne(epDTOs, tri); + + if (asc != null && asc.HasValue && !asc.Value) + epDTOs = epDTOs.Reverse(); + + return SkipAndTake(epDTOs, numPage, parPage); + } + + private async Task GetEpInformationDTOsCount(IEnumerable eps, string texte, DateTime? dateDebut, DateTime? dateFin) + { + eps = TriDate(eps, dateDebut, dateFin); + + + IEnumerable collaborateurDTOs = await GetCollaborateurDTOs(eps); + IEnumerable epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); + + if(!string.IsNullOrEmpty(texte)) + epDTOs = epDTOs.Where(e => TriTexte(e, texte)); + + return epDTOs.Count(); + } + private IEnumerable TriDate(IEnumerable eps, DateTime? dateDebut, DateTime? dateFin) { if (dateDebut.HasValue && dateDebut.Value != null) @@ -229,6 +216,12 @@ namespace EPAServeur.Services return (epDTOs.Collaborateur.Nom + " " + epDTOs.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (epDTOs.Collaborateur.Prenom + " " + epDTOs.Collaborateur.Nom).ToLower().Contains(texte.ToLower()); } + private async Task> GetCollaborateurDTOs(IEnumerable eps) + { + List guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList(); + return await collaborateurService.GetCollaborateurDTOsAsync(guids); + } + #endregion } }