Tests et implémentation de la récupération des EP en cours et signés d'un référent

develop
Yanaël GRETTE 4 years ago
parent 76b4a06b9d
commit 586702001f
  1. 100
      EPAServeur.Tests/Services/EpInformationTests.cs
  2. 113
      EPAServeur/Services/EpInformationService.cs

@ -71,14 +71,14 @@ namespace EPAServeur.Tests.Services
}
}
[Test]
public async Task GetEpEnCours_OrleansTours()
{
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1,2 }, true, 1, 15, "", "", null, null);
int count = await epInformationService.GetEPEnCoursCount(new List<long?> { 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<EpInformationDTO> 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<EpInformationDTO> 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)
{

@ -34,24 +34,8 @@ namespace EPAServeur.Services
{
IEnumerable<Ep> eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).AsEnumerable().Where(ep => EstEpEnCours(ep.Statut));
eps = TriDate(eps, dateDebut, dateFin);
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList();
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
IEnumerable<EpInformationDTO> 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<int> GetEPEnCoursCount(List<long?> idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
IEnumerable<Ep> eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).AsEnumerable().Where(ep => EstEpEnCours(ep.Statut));
eps = TriDate(eps, dateDebut, dateFin);
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList();
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
IEnumerable<EpInformationDTO> 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<IEnumerable<EpInformationDTO>> GetEPEnCoursCollaborateurParticipant(Guid? idCollaborateur)
@ -81,34 +54,23 @@ namespace EPAServeur.Services
public async Task<IEnumerable<EpInformationDTO>> GetEPEnCoursReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
throw new NotImplementedException();
IEnumerable<Ep> 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<int> GetEPEnCoursReferentCount(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
throw new NotImplementedException();
IEnumerable<Ep> 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<IEnumerable<EpInformationDTO>> GetEPSignes(List<long?> idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
IEnumerable<Ep> eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => ep.Statut == StatutEp.Signe);
eps = TriDate(eps, dateDebut, dateFin);
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList();
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
IEnumerable<EpInformationDTO> 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<IEnumerable<EpInformationDTO>> GetEPSignesCollaborateur(Guid? idCollaborateur)
@ -119,28 +81,20 @@ namespace EPAServeur.Services
public async Task<int> GetEPSignesCount(List<long?> idBUs, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
IEnumerable<Ep> eps = context.Ep.Where(ep => idBUs.Contains(ep.IdBu)).Where(ep => ep.Statut == StatutEp.Signe);
eps = TriDate(eps, dateDebut, dateFin);
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList();
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids);
IEnumerable<EpInformationDTO> 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<IEnumerable<EpInformationDTO>> GetEPSignesReferent(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
throw new NotImplementedException();
IEnumerable<Ep> 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<int> GetEPSignesReferentCount(Guid? idReferent, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
throw new NotImplementedException();
IEnumerable<Ep> 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<EpInformationDTO> GetProchainEPCollaborateur(Guid? idCollaborateur)
@ -150,6 +104,39 @@ namespace EPAServeur.Services
#endregion
#region méthodes privées
private async Task<IEnumerable<EpInformationDTO>> GetEpInformationDTOs(IEnumerable<Ep> eps, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
eps = TriDate(eps, dateDebut, dateFin);
IEnumerable<CollaborateurDTO> collaborateurDTOs = await GetCollaborateurDTOs(eps);
IEnumerable<EpInformationDTO> 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<int> GetEpInformationDTOsCount(IEnumerable<Ep> eps, string texte, DateTime? dateDebut, DateTime? dateFin)
{
eps = TriDate(eps, dateDebut, dateFin);
IEnumerable<CollaborateurDTO> collaborateurDTOs = await GetCollaborateurDTOs(eps);
IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs));
if(!string.IsNullOrEmpty(texte))
epDTOs = epDTOs.Where(e => TriTexte(e, texte));
return epDTOs.Count();
}
private IEnumerable<Ep> TriDate(IEnumerable<Ep> 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<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOs(IEnumerable<Ep> eps)
{
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList();
return await collaborateurService.GetCollaborateurDTOsAsync(guids);
}
#endregion
}
}

Loading…
Cancel
Save