Mise à jour des tests du service EpInformation avec validation des tests

develop
Yanaël GRETTE 4 years ago
parent f70eb4bc3a
commit 87f978bcf9
  1. 121
      EPAServeur.Tests/Services/EpInformationTests.cs
  2. 2
      EPAServeur/Services/EpInformationService.cs
  3. 1
      EPAServeur/Startup.cs

@ -3,6 +3,7 @@ using EPAServeur.IServices;
using EPAServeur.Services; using EPAServeur.Services;
using IO.Swagger.ApiCollaborateur; using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO; using IO.Swagger.DTO;
using IO.Swagger.Enum;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NUnit.Framework; using NUnit.Framework;
using System; using System;
@ -52,9 +53,9 @@ namespace EPAServeur.Tests.Services
#region Récupération des EP en cours #region Récupération des EP en cours
[TestCase(1, 5)] //Tours [TestCase(1, 3)] //Tours
[TestCase(2, 3)] //Orléans [TestCase(2, 3)] //Orléans
[TestCase(3, 6)] // Paris [TestCase(3, 3)] // Paris
public async Task GetEpEnCours_UneBU(long? idBUs, int nbElements) public async Task GetEpEnCours_UneBU(long? idBUs, int nbElements)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
@ -66,6 +67,7 @@ namespace EPAServeur.Tests.Services
foreach(EpInformationDTO ep in epInformationDTOs) foreach(EpInformationDTO ep in epInformationDTOs)
{ {
Assert.AreEqual(ep.Collaborateur.BusinessUnit.Id, idBUs); Assert.AreEqual(ep.Collaborateur.BusinessUnit.Id, idBUs);
Assert.IsTrue(EstEpEnCours(ep.Statut));
} }
} }
@ -83,6 +85,7 @@ namespace EPAServeur.Tests.Services
{ {
bu = ep.Collaborateur.BusinessUnit.Id; bu = ep.Collaborateur.BusinessUnit.Id;
Assert.IsTrue(bu == 1 || bu == 2); Assert.IsTrue(bu == 1 || bu == 2);
Assert.IsTrue(EstEpEnCours(ep.Statut));
} }
} }
@ -125,6 +128,8 @@ namespace EPAServeur.Tests.Services
break; break;
} }
Assert.IsTrue(compare <= 0); Assert.IsTrue(compare <= 0);
Assert.IsTrue(EstEpEnCours(ep1.Statut));
Assert.IsTrue(EstEpEnCours(ep2.Statut));
} }
} }
@ -168,75 +173,83 @@ namespace EPAServeur.Tests.Services
break; break;
} }
Assert.IsTrue(compare >= 0); Assert.IsTrue(compare >= 0);
Assert.IsTrue(EstEpEnCours(ep1.Statut));
Assert.IsTrue(EstEpEnCours(ep2.Statut));
} }
} }
//tris date //tris date
[TestCase(01, 02, 2021)] [TestCase(01, 03, 2021, 5)]
[TestCase(01, 03, 2021)] [TestCase(20, 03, 2021, 2)]
[TestCase(01, 04, 2021)] [TestCase(01, 04, 2021, 0)]
public async Task GetEpEnCours_TriDateD1(int j, int m, int a) public async Task GetEpEnCours_TriDateD1(int j, int m, int a, int count)
{ {
DateTime date = new DateTime(a, m, j); DateTime date = new DateTime(a, m, j);
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null);
int count = await epInformationService.GetEPEnCoursCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
foreach(EpInformationDTO ep in epInformationDTOs) foreach(EpInformationDTO ep in epInformationDTOs)
{ {
Assert.IsTrue(date <= ep.DatePrevisionnelle.Value); Assert.IsTrue(date <= ep.DatePrevisionnelle.Value);
Assert.IsTrue(EstEpEnCours(ep.Statut));
} }
} }
[TestCase(01, 04, 2021)] [TestCase(01, 04, 2021, 6)]
[TestCase(01, 03, 2021)] [TestCase(15, 03, 2021, 3)]
[TestCase(31, 01, 2021)] [TestCase(1, 02, 2021, 0)]
public async Task GetEpEnCours_TriDateD2(int j, int m, int a) public async Task GetEpEnCours_TriDateD2(int j, int m, int a, int count)
{ {
DateTime date = new DateTime(a, m, j); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); DateTime date = new DateTime(a, m, j); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date);
int count = await epInformationService.GetEPEnCoursCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
foreach (EpInformationDTO ep in epInformationDTOs) foreach (EpInformationDTO ep in epInformationDTOs)
{ {
Assert.IsTrue(date >= ep.DatePrevisionnelle.Value); Assert.IsTrue(date >= ep.DatePrevisionnelle.Value);
Assert.IsTrue(EstEpEnCours(ep.Statut));
} }
} }
[TestCase(01, 02, 2021, 28, 02, 2021)] [TestCase(01, 02, 2021, 28, 02, 2021, 1)]
[TestCase(01, 02, 2021, 01, 04, 2021)] [TestCase(01, 02, 2021, 01, 04, 2021, 6)]
[TestCase(15, 02, 2021, 15, 03, 2021)] [TestCase(15, 02, 2021, 15, 03, 2021, 3)]
[TestCase(01, 01, 2021, 31, 01, 2021)] [TestCase(01, 01, 2021, 31, 01, 2021, 0)]
[TestCase(01, 01, 2022, 31, 01, 2022)] [TestCase(01, 01, 2022, 31, 01, 2022, 0)]
public async Task GetEpEnCours_TriDateD1D2(int j1, int m1, int a1, int j2, int m2, int a2) public async Task GetEpEnCours_TriDateD1D2(int j1, int m1, int a1, int j2, int m2, int a2, int count)
{ {
DateTime date1 = new DateTime(a1, m1, j1); DateTime date1 = new DateTime(a1, m1, j1);
DateTime date2 = new DateTime(a2, m2, j2); DateTime date2 = new DateTime(a2, m2, j2);
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2);
int count = await epInformationService.GetEPEnCoursCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
foreach (EpInformationDTO ep in epInformationDTOs) foreach (EpInformationDTO ep in epInformationDTOs)
{ {
Assert.IsTrue(condition: date1 <= ep.DatePrevisionnelle.Value); Assert.IsTrue(condition: date1 <= ep.DatePrevisionnelle.Value);
Assert.IsTrue(date2 >= ep.DatePrevisionnelle.Value); Assert.IsTrue(date2 >= ep.DatePrevisionnelle.Value);
Assert.IsTrue(EstEpEnCours(ep.Statut));
} }
} }
//Tri texte //Tri texte
[TestCase("")] [TestCase("", 6)]
public async Task GetEpEnCours_texte(string texte) [TestCase("Ma", 2)]
[TestCase("Ne", 2)]
[TestCase("nE", 2)]
[TestCase("ma", 2)]
[TestCase("D", 2)]
[TestCase("d", 2)]
public async Task GetEpEnCours_texte(string texte, int count)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null);
int count = await epInformationService.GetEPEnCoursCount(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null);
Assert.AreEqual(count, epInformationDTOs.Count()); Assert.AreEqual(count, epInformationDTOs.Count());
foreach (EpInformationDTO ep in epInformationDTOs) foreach (EpInformationDTO ep in epInformationDTOs)
{ {
Assert.IsTrue((ep.Collaborateur.Nom + " " + ep.Collaborateur.Prenom).Contains(texte)); Assert.IsTrue((ep.Collaborateur.Nom + " " + ep.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (ep.Collaborateur.Prenom + " " + ep.Collaborateur.Nom).ToLower().Contains(texte.ToLower()));
Assert.IsTrue(EstEpEnCours(ep.Statut));
} }
} }
@ -245,9 +258,9 @@ namespace EPAServeur.Tests.Services
#region Récupération des EP signés #region Récupération des EP signés
[TestCase(1, 5)] //Tours [TestCase(1, 3)] //Tours
[TestCase(2, 4)] //Orléans [TestCase(2, 3)] //Orléans
[TestCase(3, 5)] // Paris [TestCase(3, 3)] // Paris
public async Task GetEpSignes_UneBU(long? idBUs, int nbElements) public async Task GetEpSignes_UneBU(long? idBUs, int nbElements)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
@ -259,6 +272,7 @@ namespace EPAServeur.Tests.Services
foreach(EpInformationDTO ep in epInformationDTOs) foreach(EpInformationDTO ep in epInformationDTOs)
{ {
Assert.AreEqual(ep.Collaborateur.BusinessUnit.Id, idBUs); Assert.AreEqual(ep.Collaborateur.BusinessUnit.Id, idBUs);
Assert.IsTrue(ep.Statut == StatutEp.Signe);
} }
} }
@ -276,6 +290,7 @@ namespace EPAServeur.Tests.Services
{ {
bu = ep.Collaborateur.BusinessUnit.Id; bu = ep.Collaborateur.BusinessUnit.Id;
Assert.IsTrue(bu == 1 || bu == 2); Assert.IsTrue(bu == 1 || bu == 2);
Assert.IsTrue(ep.Statut == StatutEp.Signe);
} }
} }
@ -314,6 +329,9 @@ namespace EPAServeur.Tests.Services
break; break;
} }
Assert.IsTrue(compare <= 0); Assert.IsTrue(compare <= 0);
Assert.IsTrue(ep1.Statut == StatutEp.Signe);
Assert.IsTrue(ep2.Statut == StatutEp.Signe);
} }
} }
@ -356,26 +374,29 @@ namespace EPAServeur.Tests.Services
break; break;
} }
Assert.IsTrue(compare >= 0); Assert.IsTrue(compare >= 0);
Assert.IsTrue(ep1.Statut == StatutEp.Signe);
Assert.IsTrue(ep2.Statut == StatutEp.Signe);
} }
} }
//tris date //tris date
[TestCase(01, 01, 2018)] [TestCase(01, 01, 2018, 4)]
[TestCase(01, 01, 2019)] [TestCase(01, 01, 2019, 2)]
[TestCase(01, 01, 2020)] [TestCase(01, 01, 2020, 1)]
[TestCase(01, 01, 2021)] [TestCase(01, 01, 2021, 0)]
[TestCase(01, 01, 2022)] [TestCase(01, 01, 2022, 0)]
public async Task GetEpSignes_TriDateD1(int j, int m, int a) public async Task GetEpSignes_TriDateD1(int j, int m, int a, int count)
{ {
DateTime date = new DateTime(a, m, j); DateTime date = new DateTime(a, m, j);
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null);
int count = await epInformationService.GetEPSignesCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
foreach(EpInformationDTO ep in epInformationDTOs) foreach(EpInformationDTO ep in epInformationDTOs)
{ {
Assert.IsTrue(date <= ep.DatePrevisionnelle.Value); Assert.IsTrue(date <= ep.DatePrevisionnelle.Value);
Assert.IsTrue(ep.Statut == StatutEp.Signe);
} }
} }
@ -393,43 +414,57 @@ namespace EPAServeur.Tests.Services
foreach (EpInformationDTO ep in epInformationDTOs) foreach (EpInformationDTO ep in epInformationDTOs)
{ {
Assert.IsTrue(date >= ep.DatePrevisionnelle.Value); Assert.IsTrue(date >= ep.DatePrevisionnelle.Value);
Assert.IsTrue(ep.Statut == StatutEp.Signe);
} }
} }
[TestCase(01, 07, 2021, 31, 12, 2021)] [TestCase(01, 07, 2021, 31, 12, 2021, 0)]
[TestCase(01, 09, 2018, 01, 12, 2019)] [TestCase(01, 09, 2018, 01, 12, 2019, 1)]
[TestCase(01, 01, 2018, 31, 12, 2019)] [TestCase(01, 01, 2018, 31, 12, 2019, 3)]
[TestCase(01, 01, 2017, 31, 12, 2017)] [TestCase(01, 01, 2017, 31, 12, 2017, 2)]
public async Task GetEpSignes_TriDateD1D2(int j1, int m1, int a1, int j2, int m2, int a2) public async Task GetEpSignes_TriDateD1D2(int j1, int m1, int a1, int j2, int m2, int a2, int count)
{ {
DateTime date1 = new DateTime(a1, m1, j1); DateTime date1 = new DateTime(a1, m1, j1);
DateTime date2 = new DateTime(a2, m2, j2); DateTime date2 = new DateTime(a2, m2, j2);
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2);
int count = await epInformationService.GetEPSignesCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
foreach (EpInformationDTO ep in epInformationDTOs) foreach (EpInformationDTO ep in epInformationDTOs)
{ {
Assert.IsTrue(condition: date1 <= ep.DatePrevisionnelle.Value); Assert.IsTrue(condition: date1 <= ep.DatePrevisionnelle.Value);
Assert.IsTrue(date2 >= ep.DatePrevisionnelle.Value); Assert.IsTrue(date2 >= ep.DatePrevisionnelle.Value);
Assert.IsTrue(ep.Statut == StatutEp.Signe);
} }
} }
//Tri texte //Tri texte
[TestCase("")] [TestCase("", 6)]
public async Task GetEpSignes_texte(string texte) [TestCase("Ma", 2)]
[TestCase("Ne", 2)]
[TestCase("nE", 2)]
[TestCase("ma",2)]
[TestCase("D", 2)]
[TestCase("d", 2)]
public async Task GetEpSignes_texte(string texte, int count)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null);
int count = await epInformationService.GetEPSignesCount(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null);
Assert.AreEqual(count, epInformationDTOs.Count()); Assert.AreEqual(count, epInformationDTOs.Count());
foreach (EpInformationDTO ep in epInformationDTOs) foreach (EpInformationDTO ep in epInformationDTOs)
{ {
Assert.IsTrue((ep.Collaborateur.Nom + " " + ep.Collaborateur.Prenom).Contains(texte)); Assert.IsTrue((ep.Collaborateur.Nom + " " + ep.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (ep.Collaborateur.Prenom + " " + ep.Collaborateur.Nom).ToLower().Contains(texte.ToLower()));
Assert.IsTrue(ep.Statut == StatutEp.Signe);
} }
} }
#endregion #endregion
#region méthodes privées
private bool EstEpEnCours(StatutEp statut)
{
return statut != StatutEp.Annule && statut != StatutEp.Cree && statut != StatutEp.Rejete && statut != StatutEp.Signe;
}
#endregion
} }
} }

@ -215,7 +215,7 @@ namespace EPAServeur.Services
private bool TriTexte(EpInformationDTO epDTOs, string texte) private bool TriTexte(EpInformationDTO epDTOs, string texte)
{ {
return (epDTOs.Collaborateur.Nom + " " + epDTOs.Collaborateur.Prenom).Contains(texte) || (epDTOs.Collaborateur.Prenom + " " + epDTOs.Collaborateur.Nom).Contains(texte); return (epDTOs.Collaborateur.Nom + " " + epDTOs.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (epDTOs.Collaborateur.Prenom + " " + epDTOs.Collaborateur.Nom).ToLower().Contains(texte.ToLower());
} }
#endregion #endregion

@ -123,6 +123,7 @@ namespace EPAServeur
//Services //Services
services.AddScoped<ICollaborateurService, CollaborateurService>(); services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IEpInformationService, EpInformationService>();
services.AddScoped<IFormationService, FormationService>(); services.AddScoped<IFormationService, FormationService>();
services.AddScoped<INoteService, NoteService>(); services.AddScoped<INoteService, NoteService>();
services.AddScoped<IReferentEPService, ReferentEPService>(); services.AddScoped<IReferentEPService, ReferentEPService>();

Loading…
Cancel
Save