diff --git a/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs b/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs index 136459e..8506e9e 100644 --- a/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs +++ b/EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs @@ -25,6 +25,7 @@ namespace EPAServeur.Tests.Controllers IDemandeDelegationService demandeDelegationService; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; #endregion #region Setup @@ -55,8 +56,9 @@ namespace EPAServeur.Tests.Controllers } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); - demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); } #endregion diff --git a/EPAServeur.Tests/Controllers/EngagementsApiTests.cs b/EPAServeur.Tests/Controllers/EngagementsApiTests.cs index ca0501b..815ab8a 100644 --- a/EPAServeur.Tests/Controllers/EngagementsApiTests.cs +++ b/EPAServeur.Tests/Controllers/EngagementsApiTests.cs @@ -64,6 +64,7 @@ namespace EPAServeur.Tests.Controllers entity.State = EntityState.Detached; } + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/EPAServeur.Tests/Controllers/EpInformationApiTests.cs b/EPAServeur.Tests/Controllers/EpInformationApiTests.cs index 97acaf0..023def8 100644 --- a/EPAServeur.Tests/Controllers/EpInformationApiTests.cs +++ b/EPAServeur.Tests/Controllers/EpInformationApiTests.cs @@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Controllers private ICollaborateurService collaborateurService; private IEpInformationService epInformationService; private ILogger logger; + private ITransformDTO transformDTO; #endregion @@ -50,8 +51,9 @@ namespace EPAServeur.Tests.Controllers { entity.State = EntityState.Detached; } - collaborateurService = new CollaborateurService(new CollaborateurApi(), context); - epInformationService = new EpInformationService(context, collaborateurService); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO); + epInformationService = new EpInformationService(context, collaborateurService, transformDTO); } #endregion diff --git a/EPAServeur.Tests/Controllers/FormationApiTests.cs b/EPAServeur.Tests/Controllers/FormationApiTests.cs index aff0d95..c31d43e 100644 --- a/EPAServeur.Tests/Controllers/FormationApiTests.cs +++ b/EPAServeur.Tests/Controllers/FormationApiTests.cs @@ -63,6 +63,7 @@ namespace EPAServeur.Tests.Controllers entity.State = EntityState.Detached; } + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/EPAServeur.Tests/Controllers/NoteApiTests.cs b/EPAServeur.Tests/Controllers/NoteApiTests.cs index a4e5e36..b53cee7 100644 --- a/EPAServeur.Tests/Controllers/NoteApiTests.cs +++ b/EPAServeur.Tests/Controllers/NoteApiTests.cs @@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Controllers private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; private INoteService noteService; private ILogger logger; private Guid? auteur1, collaborateur1; @@ -53,8 +54,10 @@ namespace EPAServeur.Tests.Controllers entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); - noteService = new NoteService(collaborateurApi, collaborateurService, context); + + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); logger = new NullLogger(); auteur1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696"); diff --git a/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs b/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs index 1f8da96..1527906 100644 --- a/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs +++ b/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs @@ -65,6 +65,7 @@ namespace EPAServeur.Tests.Controllers entity.State = EntityState.Detached; } + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs b/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs index 4f789a5..2d9bdf8 100644 --- a/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs +++ b/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs @@ -21,6 +21,7 @@ namespace EPAServeur.Tests.Controllers #region Variables private EpContext context; private ICollaborateurApi collaborateurApi; + private ITransformDTO transformDTO; private IReferentEPService referentEPService; private Guid? referent, collaborateur1, collaborateur2, collaborateur3; #endregion diff --git a/EPAServeur.Tests/Services/CollaborateurServiceTests.cs b/EPAServeur.Tests/Services/CollaborateurServiceTests.cs index f8ac6ef..b415585 100644 --- a/EPAServeur.Tests/Services/CollaborateurServiceTests.cs +++ b/EPAServeur.Tests/Services/CollaborateurServiceTests.cs @@ -20,6 +20,8 @@ namespace EPAServeur.Tests.Services #region private EpContext context; private ICollaborateurApi collaborateurApi; + private ITransformDTO transformDTO; + #endregion #region Setup @@ -46,6 +48,7 @@ namespace EPAServeur.Tests.Services { entity.State = EntityState.Detached; } + transformDTO = new TransformDTO(); collaborateurApi = new CollaborateurApi(); } #endregion @@ -57,7 +60,8 @@ namespace EPAServeur.Tests.Services [TestCase("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491")] public async Task GetCollaborateurById_Ok(Guid? id) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(id); Assert.IsNotNull(collaborateurDTO); @@ -69,7 +73,8 @@ namespace EPAServeur.Tests.Services [TestCase("coty.lemoine@apside-groupe.com")] public async Task GetCollaborateurByMail_Ok(string mail) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByMailAsync(mail); Assert.IsNotNull(collaborateurDTO); @@ -79,10 +84,10 @@ namespace EPAServeur.Tests.Services [TestCase("006226f6-51b2-4a02-a302-7447f7fccc04")] [TestCase("e5d36da4-df16-4d19-8a11-1ba2f6efc80c")] [TestCase("92b29b9c-40a4-4aa0-9412-bc97a379e52f")] - public async Task GetCollaborateurById_CollaborateurNotFound(Guid? id) + public void GetCollaborateurById_CollaborateurNotFound(Guid? id) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); - + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + AsyncTestDelegate exception = () => collaborateurService.GetCollaborateurByIdAsync(id); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); } @@ -90,9 +95,10 @@ namespace EPAServeur.Tests.Services [TestCase("nicolas@apside.fr")] [TestCase("rousseau@apside.fr")] [TestCase("lemoine@apside.fr")] - public async Task GetCollaborateurByMail_CollaborateurNotFound(string mail) + public void GetCollaborateurByMail_CollaborateurNotFound(string mail) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + AsyncTestDelegate exception = () => collaborateurService.GetCollaborateurByMailAsync(mail); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); } @@ -108,7 +114,7 @@ namespace EPAServeur.Tests.Services [TestCase("RA")] public async Task GetCollaborateurs_UnRole(string role) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); List roles = new List(); roles.Add(role); @@ -142,7 +148,7 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurs_RoleRH_RoleAssistant() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); List roles = new List(); roles.Add("Assistant"); @@ -156,7 +162,7 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurs_RoleRA_RoleManager() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); List roles = new List(); roles.Add("Manager"); @@ -175,7 +181,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurs_Asc_Desc() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateursAsc = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", null, null); IEnumerable collaborateursDesc = await collaborateurService.GetCollaborateursAsync(null, null, false, 1, 50, "", "", null, null); CollaborateurDTO collaborateurDTOFirstAsc = collaborateursAsc.First(); @@ -193,7 +200,8 @@ namespace EPAServeur.Tests.Services [TestCase("")] public async Task GetCollaborateurs_Texte(string texte) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, texte, "", null, null); string nomprenom, prenomnom; foreach(CollaborateurDTO collaborateur in collaborateurs) @@ -210,7 +218,8 @@ namespace EPAServeur.Tests.Services [TestCase(2018,1,1)] public async Task GetCollaborateurs_DateDebut(int annee, int mois, int jour) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + DateTime dateDebut = new DateTime(annee, mois, jour); IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", dateDebut, null); foreach(CollaborateurDTO collaborateur in collaborateurs) @@ -225,7 +234,8 @@ namespace EPAServeur.Tests.Services [TestCase(2017, 12, 31)] public async Task GetCollaborateurs_DateFin(int annee, int mois, int jour) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + DateTime dateFin = new DateTime(annee, mois, jour); IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", null, dateFin); foreach (CollaborateurDTO collaborateur in collaborateurs) @@ -240,8 +250,9 @@ namespace EPAServeur.Tests.Services [TestCase(2019,1,1,2019,12,31)] public async Task GetCollaborateurs_DateDebutDateFin(int anneeDeb, int moisDeb, int jourDeb, int anneeFin, int moisFin, int jourFin) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); - DateTime dateDebut= new DateTime(anneeDeb, moisDeb, jourDeb); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + + DateTime dateDebut = new DateTime(anneeDeb, moisDeb, jourDeb); DateTime dateFin = new DateTime(anneeFin, moisFin, jourFin); IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", dateDebut, dateFin); foreach (CollaborateurDTO collaborateur in collaborateurs) @@ -259,7 +270,8 @@ namespace EPAServeur.Tests.Services [TestCase(1,37)] public async Task GetCollaborateur_Paginaion(int numPage, int parPage) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); Assert.AreEqual(collaborateurs.Count(), parPage); } @@ -269,7 +281,8 @@ namespace EPAServeur.Tests.Services [TestCase(8, 5, 2)] public async Task GetCollaborateur_Paginaion_2(int numPage, int parPage, int res) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); Assert.AreEqual(collaborateurs.Count(), res); } @@ -281,7 +294,8 @@ namespace EPAServeur.Tests.Services [TestCase(-1, 37)] public async Task GetCollaborateur_PaginaionValeursParDefaut(int numPage, int parPage) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); if(parPage < 5) @@ -294,7 +308,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateur_OrderByDateArrive() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "datearrivee", null, null); DateTime d1, d2; for(int i = 0; i < collaborateurs.Count() -1; ++i) @@ -310,7 +325,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateur_OrderByBU() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "businessunit", null, null); string bu1, bu2; for (int i = 0; i < collaborateurs.Count() - 1; ++i) @@ -327,7 +343,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateur_OrderByNom() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "collaborateur", null, null); string nom1, nom2; for (int i = 0; i < collaborateurs.Count() - 1; ++i) @@ -348,7 +365,8 @@ namespace EPAServeur.Tests.Services [TestCase("642bc07f-051a-4088-8a73-425b44998673")] public async Task GetCollaborateurByReferentPlusCount(Guid idReferent) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + IEnumerable collaborateurs = await collaborateurService.GetCollaborateursByReferentAsync(idReferent, true, 1, 15, "", ""); int count = await collaborateurService.GetCollaborateursCountByReferentAsync(idReferent, ""); Assert.AreEqual(count, collaborateurs.Count()); @@ -361,7 +379,8 @@ namespace EPAServeur.Tests.Services [TestCase("ca1f480a-9918-4cea-819c-62e5c7f2b332")] public void GetCollaborateurByReferent_ReferentNotFound(Guid idReferent) { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + AsyncTestDelegate exception = () => collaborateurService.GetCollaborateursByReferentAsync(idReferent, true, 1, 15, "", ""); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); } @@ -375,7 +394,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurByGuids() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + List guids = new List(); guids.Add(new Guid("ebd911ef-a6a8-4047-afdc-9a9066aa1a07")); guids.Add(new Guid("71d33f6d-695a-4dc6-ae1a-b1605fd2073d")); @@ -394,7 +414,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurByGuidsAvecIdsNonExistantEnPlus() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + List guids = new List(); guids.Add(new Guid("b645f582-0a5d-48dc-97a1-4ebb0fb3a29f")); guids.Add(new Guid()); @@ -414,7 +435,8 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetCollaborateurByGuidsAvecIdsNonExistantUniquement() { - ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); + ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); + List guids = new List(); guids.Add(new Guid()); guids.Add(new Guid()); diff --git a/EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs b/EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs index 36dd8d4..e26fc6e 100644 --- a/EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs +++ b/EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs @@ -23,6 +23,8 @@ namespace EPAServeur.Tests.Services private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; + #endregion #region Setup @@ -52,7 +54,8 @@ namespace EPAServeur.Tests.Services entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); } #endregion @@ -65,7 +68,7 @@ namespace EPAServeur.Tests.Services [TestCase("17b87130-0e9d-4b78-b0e3-a11e5f70318d", 1)] public async Task RecupererDemandesDelegation_OK(Guid? idReferent, int count) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); IEnumerable demandesDelegation = await demandeDelegationService.RecupererDemandesDelegation(idReferent); foreach (DemandeDelegationDTO demandeDelegation in demandesDelegation) { @@ -80,7 +83,7 @@ namespace EPAServeur.Tests.Services public void RecupererDemandeDelegation_ReferentNotFound() { Guid? idReferent = new Guid(); - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => demandeDelegationService.RecupererDemandesDelegation(idReferent); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); } @@ -93,7 +96,7 @@ namespace EPAServeur.Tests.Services [TestCase(5)] public async Task UpdateDemandeDelegation_ReponsePositive(long id) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id); long idEp = demandeDelegation.IdEP; @@ -125,7 +128,7 @@ namespace EPAServeur.Tests.Services [TestCase(6)] public async Task UpdateDemandeDelegation_ReponseNegative(long id) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id); long idEp = demandeDelegation.IdEP; @@ -156,7 +159,7 @@ namespace EPAServeur.Tests.Services [TestCase(10, EtatDemande.Rejetee, "exemple refus")] public void UpdateDemandeDelegation_DemandeNonExistante(long id, EtatDemande etatDemande, string raisonRefus) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO() { Id = id, @@ -176,7 +179,7 @@ namespace EPAServeur.Tests.Services [TestCase(4, 1,EtatDemande.Rejetee, "exemple refus")] public void UpdateDemandeDelegation_DemandeIncompatible(long id, long idIncompatible, EtatDemande etatDemande, string raisonRefus) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO() { Id = id, @@ -199,7 +202,7 @@ namespace EPAServeur.Tests.Services [TestCase(7, EtatDemande.Rejetee, "")] public async Task UpdateDemandeDelegation_DemandeInvalid(long id, EtatDemande etatDemande, string raisonRefus) { - IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); + IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id); long idEp = demandeDelegation.IdEP; diff --git a/EPAServeur.Tests/Services/EngagementServiceTests.cs b/EPAServeur.Tests/Services/EngagementServiceTests.cs index 5ab7833..da06403 100644 --- a/EPAServeur.Tests/Services/EngagementServiceTests.cs +++ b/EPAServeur.Tests/Services/EngagementServiceTests.cs @@ -23,6 +23,8 @@ namespace EPAServeur.Tests.Services private EpContext epContext; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; + #endregion #region Setup @@ -37,7 +39,8 @@ namespace EPAServeur.Tests.Services epContext = new EpContext(optionBuider); collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, epContext); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO); epContext.Database.EnsureDeleted(); epContext.Database.EnsureCreated(); epContext.SaveChanges(); @@ -61,7 +64,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseDesParamsDesIdBUValides_RetourneDesEngagements(long[] arrIdBUs) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = arrIdBUs.Select(x => x).ToList(); // Act @@ -76,7 +79,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseDesParamsDesEtatsDEngagementsValides_RetourneDesEngagements(EtatEngagement[] arrEtatsEngagement) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; List etatEngagements = arrEtatsEngagement.Select(x => x).ToList(); @@ -92,7 +95,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesEngagements(int? numPage, int? parPage) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; // Act @@ -109,7 +112,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPage) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; int? nbEngagementDeuxiemePage; @@ -142,7 +145,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionCroissant(bool? asc, string tri) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; // Act @@ -159,7 +162,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionDecroissant(bool? asc, string tri) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; // Act @@ -174,7 +177,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifCroissant() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = true; string tri = "dispositif"; @@ -191,7 +194,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifDecroissant() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = false; string tri = "dispositif"; @@ -208,7 +211,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteCroissante() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = true; string tri = "modalite"; @@ -225,7 +228,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteDecroissante() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = false; string tri = "modalite"; @@ -242,7 +245,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateCroissante() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = true; string tri = "date"; @@ -259,7 +262,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateDecroissante() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List() { 1, 2, 3 }; bool? asc = false; string tri = "date"; @@ -279,7 +282,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsAsync_PasseDesParamsInvalides_RetourneZeroEngagement(long[] arrIdBUs, string texte) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs; if (arrIdBUs != null) @@ -298,7 +301,7 @@ namespace EPAServeur.Tests.Services public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUVide_LeveUneEngagementInvalidException() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = new List(); // Act @@ -312,7 +315,7 @@ namespace EPAServeur.Tests.Services public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUNull_LeveUneEngagementInvalidException() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs = null; // Act @@ -332,7 +335,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDEngagements(long[] arrIdBUs, string texte) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs; if (arrIdBUs != null) @@ -353,7 +356,7 @@ namespace EPAServeur.Tests.Services public async Task GetEngagementsCountAsync_PasseDesParamsInvalides_RetourneZero(long[] arrIdBUs, string texte) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); List idBUs; if (arrIdBUs != null) @@ -378,7 +381,7 @@ namespace EPAServeur.Tests.Services public async Task RepondreEngagementAsync_ModifieUnEngagementValide_EngagementModifieAvecSucces(long idEngagement, long idEp, EtatEngagement etatEngagement, string raisonNonRealisable) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO @@ -423,7 +426,7 @@ namespace EPAServeur.Tests.Services string raisonNonRealisableAvantUpdate = null; string raisonNonRealisableApresUpdate = "La date limite pour respecter l'engagement est passée."; // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO @@ -469,7 +472,7 @@ namespace EPAServeur.Tests.Services public void RepondreEngagementAsync_ModifieUnEngagementAvecDesProprietesInvalide_LeveUneEngagementInvalidException(long idEngagement, long idEp, string action, string dispositif, string modalite, DateTime? dateLimite, EtatEngagement etatEngagement, string raisonNonRealisable) { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO @@ -505,7 +508,7 @@ namespace EPAServeur.Tests.Services public void RepondreEngagementAsync_ModifieUnEngagementNull_LeveUneEngagementInvalidException() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EngagementDTO engagementDTO = null; long idEngagement = 1; @@ -520,7 +523,7 @@ namespace EPAServeur.Tests.Services public void RepondreEngagementAsync_ModifieUnEngagementAvecUnEPInexistantDansLaBDD_LeveUneEngagementInvalidException() { // Arrange - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); long idEngagement = 1; EpInformationDTO epInformationDTO = new EpInformationDTO { @@ -561,7 +564,7 @@ namespace EPAServeur.Tests.Services long idEngagementIncorrecte = 2; long idEp = 9; - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO @@ -600,7 +603,7 @@ namespace EPAServeur.Tests.Services long idEngagement = 0; long idEp = 9; - EngagementService engagementService = new EngagementService(epContext, collaborateurService); + EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) .Select(ep => new EpInformationDTO diff --git a/EPAServeur.Tests/Services/EpInformationTests.cs b/EPAServeur.Tests/Services/EpInformationTests.cs index b1fe14f..a67f9a1 100644 --- a/EPAServeur.Tests/Services/EpInformationTests.cs +++ b/EPAServeur.Tests/Services/EpInformationTests.cs @@ -20,6 +20,8 @@ namespace EPAServeur.Tests.Services #region private EpContext context; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; + #endregion @@ -47,7 +49,8 @@ namespace EPAServeur.Tests.Services { entity.State = EntityState.Detached; } - collaborateurService = new CollaborateurService(new CollaborateurApi(), context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO); } #endregion @@ -58,7 +61,7 @@ namespace EPAServeur.Tests.Services [TestCase(3, 3)] // Paris public async Task GetEpEnCours_UneBU(long? idBUs, int nbElements) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List{ idBUs }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPEnCoursCount(new List { idBUs }, true, 1, 15, "", "", null, null); @@ -74,7 +77,7 @@ namespace EPAServeur.Tests.Services [Test] public async Task GetEpEnCours_OrleansTours() { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); 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); @@ -100,7 +103,7 @@ namespace EPAServeur.Tests.Services [TestCase("datedisponibilite")] public async Task GetEpEnCours_TriColonneASC(string tri) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, "", tri, null, null); EpInformationDTO ep1, ep2; int compare = 0; @@ -153,7 +156,7 @@ namespace EPAServeur.Tests.Services [TestCase("datedisponibilite")] public async Task GetEpEnCours_TriColonneDESC(string tri) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, false, 1, 15, "", tri, null, null); EpInformationDTO ep1, ep2; int compare = 0; @@ -201,7 +204,7 @@ namespace EPAServeur.Tests.Services public async Task GetEpEnCours_TriDateD1(int j, int m, int a, int count) { DateTime date = new DateTime(a, m, j); - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, "", "", date, null); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -217,7 +220,7 @@ namespace EPAServeur.Tests.Services [TestCase(1, 02, 2021, 0)] 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, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, "", "", null, date); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -237,7 +240,7 @@ namespace EPAServeur.Tests.Services { DateTime date1 = new DateTime(a1, m1, j1); DateTime date2 = new DateTime(a2, m2, j2); - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, "", "", date1, date2); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -259,7 +262,7 @@ namespace EPAServeur.Tests.Services [TestCase("d", 2)] public async Task GetEpEnCours_texte(string texte, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPEnCours(new List { 1, 2 }, true, 1, 15, texte, "", null, null); Assert.AreEqual(count, epInformationDTOs.Count()); foreach (EpInformationDTO ep in epInformationDTOs) @@ -279,7 +282,7 @@ namespace EPAServeur.Tests.Services [TestCase(3, 3)] // Paris public async Task GetEpSignes_UneBU(long? idBUs, int nbElements) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List{ idBUs }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPSignesCount(new List { idBUs }, true, 1, 15, "", "", null, null); @@ -295,7 +298,7 @@ namespace EPAServeur.Tests.Services public async Task GetEpSignes_OrleansTours() { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1,2 }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPSignesCount(new List { 1, 2 }, true, 1, 15, "", "", null, null); @@ -321,7 +324,7 @@ namespace EPAServeur.Tests.Services [TestCase("datedisponibilite")] public async Task GetEpSignes_TriColonneASC(string tri) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, "", tri, null, null); EpInformationDTO ep1, ep2; int compare = 0; @@ -375,7 +378,7 @@ namespace EPAServeur.Tests.Services [TestCase("datedisponibilite")] public async Task GetEpSignes_TriColonneDESC(string tri) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, false, 1, 15, "", tri, null, null); EpInformationDTO ep1, ep2; int compare = 0; @@ -426,7 +429,7 @@ namespace EPAServeur.Tests.Services public async Task GetEpSignes_TriDateD1(int j, int m, int a, int count) { DateTime date = new DateTime(a, m, j); - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, "", "", date, null); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -443,7 +446,7 @@ namespace EPAServeur.Tests.Services [TestCase(31, 07, 2017)] public async Task GetEpSignes_TriDateD2(int j, int m, int a) { - 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, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, "", "", null, date); int count = await epInformationService.GetEPSignesCount(new List { 1, 2 }, true, 1, 15, "", "", null, date); @@ -463,7 +466,7 @@ namespace EPAServeur.Tests.Services { DateTime date1 = new DateTime(a1, m1, j1); DateTime date2 = new DateTime(a2, m2, j2); - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, "", "", date1, date2); Assert.AreEqual(epInformationDTOs.Count(), count); @@ -485,7 +488,7 @@ namespace EPAServeur.Tests.Services [TestCase("d", 2)] public async Task GetEpSignes_texte(string texte, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignes(new List { 1, 2 }, true, 1, 15, texte, "", null, null); Assert.AreEqual(count, epInformationDTOs.Count()); foreach (EpInformationDTO ep in epInformationDTOs) @@ -508,7 +511,7 @@ namespace EPAServeur.Tests.Services [TestCase("80220063-a5fa-472b-b610-2e350566df98", 1)] public async Task GetEPCoursReferent(Guid idReferent, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); 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); @@ -531,7 +534,7 @@ namespace EPAServeur.Tests.Services [TestCase("ea027734-ff0f-4308-8879-133a09fb3c46", 1)] public async Task GetEPEnSignesReferent(Guid idReferent, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); 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); @@ -553,7 +556,7 @@ namespace EPAServeur.Tests.Services [TestCase("13fbe621-1bc9-4f04-afde-b54ca076e239", 3)] public async Task GetEPSignesCollaborateur(Guid idCollaborateur, int count) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); IEnumerable epInformationDTOs = await epInformationService.GetEPSignesCollaborateur(idCollaborateur); Assert.AreEqual(count, epInformationDTOs.Count()); foreach(EpInformationDTO ep in epInformationDTOs) @@ -574,7 +577,7 @@ namespace EPAServeur.Tests.Services [TestCase("de98a866-736f-4295-a669-92a8694e2ee3", true)] public async Task GetEPEnCoursCollaborateur(Guid idCollaborateur, bool existe) { - IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); + IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO); EpInformationDTO epInformationDTO = await epInformationService.GetProchainEPCollaborateur(idCollaborateur); if(existe) { diff --git a/EPAServeur.Tests/Services/FormationServiceTests.cs b/EPAServeur.Tests/Services/FormationServiceTests.cs index 5c16163..fddaf76 100644 --- a/EPAServeur.Tests/Services/FormationServiceTests.cs +++ b/EPAServeur.Tests/Services/FormationServiceTests.cs @@ -22,6 +22,7 @@ namespace EPAServeur.Tests.Services private EpContext epContext; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; #endregion #region Setup @@ -36,7 +37,8 @@ namespace EPAServeur.Tests.Services epContext = new EpContext(optionBuider); collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, epContext); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO); epContext.Database.EnsureDeleted(); epContext.Database.EnsureCreated(); epContext.SaveChanges(); @@ -59,7 +61,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act FormationDTO formationDTO = await formationService.GetFormationByIdAsync(3); @@ -85,7 +87,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormationSansParticipation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); long idFormation = 11; // Act @@ -114,7 +116,7 @@ namespace EPAServeur.Tests.Services public void GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long idFormation) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.GetFormationByIdAsync(idFormation); @@ -136,7 +138,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseDesParamsValides_RetourneDesFormations(long? idAgence, int[] arrIdStatuts, bool? asc, int? numPage, int? parPAge, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); List idStatuts; if (arrIdStatuts != null) @@ -156,7 +158,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesFormations(int? numPage, int? parPAge) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, numPage, parPAge, null, null, null, null); @@ -172,7 +174,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPAge) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); int? nbFormationDeuxiemePage; switch (parPAge) @@ -204,7 +206,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleCroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -221,7 +223,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleDecroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -236,7 +238,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutCroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -251,7 +253,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutDecroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -266,7 +268,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParNombreDeParticipantsCroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -281,7 +283,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParNombreDeParticipantsDecroissant(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -296,7 +298,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineCroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -311,7 +313,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineDecroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -326,7 +328,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateCroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -341,7 +343,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateDecroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -356,7 +358,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationCroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -371,7 +373,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationDecroissante(bool? asc, string tri) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); @@ -387,7 +389,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamUneDateDeDebut_RetourneDesFormationsAvecUneDateDeDebutSuperieur(DateTime dateDebut) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, null); @@ -402,7 +404,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamUneDateDeFin_RetourneDesFormationsAvecUneDateDeFinInferieur(DateTime dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, null, dateFin); @@ -417,7 +419,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutEtUneDateDeFin_RetourneDesFormationsAvecUneDateDeDebutSuperieurUneDateDeFinInferieur(DateTime dateDebut, DateTime dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin); @@ -435,7 +437,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutSuperieurEtUneDateDeFinInferieur_RetourneZeroFormation(DateTime dateDebut, DateTime dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin); @@ -450,7 +452,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsAsync_PasseDesParamsInvalides_RetourneZeroFormation(long? idAgence, int[] arrIdStatuts, bool? asc, int? numPage, int? parPAge, string texte, string tri, DateTime? dateDebut, DateTime? dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); List idStatuts; if (arrIdStatuts != null) @@ -479,7 +481,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDeFormations(long? idAgence, int[] arrIdStatuts, string texte, DateTime? dateDebut, DateTime? dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); List idStatuts; if (arrIdStatuts != null) @@ -500,7 +502,7 @@ namespace EPAServeur.Tests.Services public async Task GetFormationsCountAsync_PasseDesParamsInvalides_RetourneZero(long? idAgence, int[] arrIdStatuts, string texte, DateTime? dateDebut, DateTime? dateFin) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); List idStatuts; if (arrIdStatuts != null) @@ -524,7 +526,7 @@ namespace EPAServeur.Tests.Services public async Task GetModesFormationAsync_RetourneTousLesModesDeFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable modeFormationDTOs = await formationService.GetModesFormationAsync(); @@ -542,7 +544,7 @@ namespace EPAServeur.Tests.Services public async Task GetOriginesAsyncFormation_RetourneToutesLesOriginesDeFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable origineFormationDTOs = await formationService.GetOriginesFormationAsync(); @@ -560,7 +562,7 @@ namespace EPAServeur.Tests.Services public async Task GetStatutsFormationAsyncFormation_RetourneTousLesStatutsDeFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable statutFormationDTOs = await formationService.GetStatutsFormationAsync(); @@ -578,7 +580,7 @@ namespace EPAServeur.Tests.Services public async Task GetTypesFormationAsync_RetourneTousLesTypesDeFormation() { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable typeFormationDTOs = await formationService.GetTypesFormationAsync(); @@ -623,7 +625,7 @@ namespace EPAServeur.Tests.Services EstCertifiee = false }; - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act FormationDTO formationAjoute = await formationService.AddFormationAsync(formation); @@ -652,7 +654,7 @@ namespace EPAServeur.Tests.Services // Arrange FormationDTO formation = null; - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); @@ -701,7 +703,7 @@ namespace EPAServeur.Tests.Services EstCertifiee = false }; - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); @@ -747,7 +749,7 @@ namespace EPAServeur.Tests.Services EstCertifiee = false }; - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); @@ -773,7 +775,7 @@ namespace EPAServeur.Tests.Services OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation); @@ -837,7 +839,7 @@ namespace EPAServeur.Tests.Services OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation); @@ -876,7 +878,7 @@ namespace EPAServeur.Tests.Services OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); FormationDTO formation = await formationService.GetFormationByIdAsync(1); @@ -914,7 +916,7 @@ namespace EPAServeur.Tests.Services OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); FormationDTO formation = new FormationDTO { @@ -950,7 +952,7 @@ namespace EPAServeur.Tests.Services public async Task DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long idFormation) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); bool existFormation = true; // Act @@ -967,7 +969,7 @@ namespace EPAServeur.Tests.Services public void DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdInvalide_LeveUneFormationNotFoundException(long idFormation) { // Arrange - FormationService formationService = new FormationService(epContext, collaborateurService); + FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => formationService.DeleteFormationByIdAsync(idFormation); diff --git a/EPAServeur.Tests/Services/NoteServiceTests.cs b/EPAServeur.Tests/Services/NoteServiceTests.cs index e98dbed..c33ca0c 100644 --- a/EPAServeur.Tests/Services/NoteServiceTests.cs +++ b/EPAServeur.Tests/Services/NoteServiceTests.cs @@ -21,6 +21,7 @@ namespace EPAServeur.Tests.Services private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; private Guid? auteur1, auteur2, auteur3; private Guid? collaborateur1, collaborateur2, collaborateur3; private Guid? auteurNonExistant, collaborateurNonExistant, collaborateurParti, referentParti; @@ -51,7 +52,8 @@ namespace EPAServeur.Tests.Services entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); auteur1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696"); @@ -81,7 +83,7 @@ namespace EPAServeur.Tests.Services CollaborateurDTO collaborateur2DTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur2); CollaborateurDTO collaborateur3DTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur3); - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; DetailsNoteDTO noteAjoutee1, noteAjoutee2; @@ -203,7 +205,7 @@ namespace EPAServeur.Tests.Services CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; DetailsNoteDTO noteAjoutee1 = new DetailsNoteDTO() @@ -226,7 +228,7 @@ namespace EPAServeur.Tests.Services { CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; DetailsNoteDTO note = new DetailsNoteDTO() @@ -249,7 +251,7 @@ namespace EPAServeur.Tests.Services CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); collaborateurDTO.Id = collaborateurNonExistant; - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; DetailsNoteDTO note = new DetailsNoteDTO() @@ -274,7 +276,7 @@ namespace EPAServeur.Tests.Services CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); CollaborateurDTO collaborateurPartiDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateurParti); - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DateTime date = DateTime.Now; @@ -317,7 +319,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task GetNote_NoteNotNull(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO detailsNoteDTO = await noteService.GetNoteByIdAsync(id); Assert.NotNull(detailsNoteDTO); @@ -341,7 +343,7 @@ namespace EPAServeur.Tests.Services [TestCase(100)] public void GetNote_NoteNotFoundException(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); Assert.ThrowsAsync(typeof(NoteNotFoundException), exception); } @@ -350,7 +352,7 @@ namespace EPAServeur.Tests.Services [TestCase(7)] public void GetNote_ReferentNotFoundException(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); } @@ -359,7 +361,7 @@ namespace EPAServeur.Tests.Services [TestCase(10)] public void GetNote_CollaborateurNotFoundException(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); } @@ -375,7 +377,7 @@ namespace EPAServeur.Tests.Services [TestCase(8)] public async Task SupprimerNote_Succes(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); await noteService.SupprimerNoteAsync(id); Note note = await context.Note.FindAsync(id); @@ -393,7 +395,7 @@ namespace EPAServeur.Tests.Services [TestCase(100)] public void SupprimerNote_NoteNotFoundException(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); AsyncTestDelegate exception = () => noteService.SupprimerNoteAsync(id); Assert.ThrowsAsync(typeof(NoteNotFoundException), exception); @@ -410,7 +412,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task UpdateNote_UpdateTitreEtTexte(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Titre = "Titre à jour " + id; note.Texte= "Texte à jour " + id; @@ -433,7 +435,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task UpdateNote_UpdateTexte(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Texte = "Texte à jour " + id; DetailsNoteDTO noteUpdate = await noteService.UpdateNoteAsync(id, note); @@ -455,7 +457,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task UpdateNote_UpdateTitre(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Titre = "Titre à jour " + id; DetailsNoteDTO noteUpdate = await noteService.UpdateNoteAsync(id, note); @@ -479,7 +481,7 @@ namespace EPAServeur.Tests.Services [TestCase(9,7)] public async Task UpdateNote_NoteIdImcompatibleExceptionId(long id, long mauvaisId) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Titre = "Titre à jour " + id; note.Texte = "Texte à jour " + id; @@ -493,7 +495,7 @@ namespace EPAServeur.Tests.Services [TestCase(9)] public async Task UpdateNote_NoteIdImcompatibleExceptionDate(long id) { - INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id); note.Titre = "Titre à jour " + id; note.Texte = "Texte à jour " + id; diff --git a/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs b/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs index cafddf1..014ffbc 100644 --- a/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs +++ b/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs @@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Services private EpContext epContext; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; #endregion #region Setup @@ -37,7 +38,8 @@ namespace EPAServeur.Tests.Services epContext = new EpContext(optionBuider); collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, epContext); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO); epContext.Database.EnsureDeleted(); epContext.Database.EnsureCreated(); epContext.SaveChanges(); @@ -61,7 +63,7 @@ namespace EPAServeur.Tests.Services public async Task GetEvaluationCollaborateurAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneEvaluation() { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; // Act EvaluationDTO evaluationDTO = await participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation); @@ -79,7 +81,7 @@ namespace EPAServeur.Tests.Services public void GetEvaluationCollaborateurAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneParticipationFormationNotFoundException(long idParticipationFormation) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation); @@ -97,7 +99,7 @@ namespace EPAServeur.Tests.Services public async Task GetParticipationByCollaborateurAsync_PasseDesParamsValides_RetourneDesParticipationsFormations(Guid idCollaborateur) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); @@ -111,7 +113,7 @@ namespace EPAServeur.Tests.Services public async Task GetParticipationByCollaborateurAsync_PasseDesParamsInvalides_RetourneZeroParticipation(Guid idCollaborateur) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); @@ -128,7 +130,7 @@ namespace EPAServeur.Tests.Services public async Task EvaluerFormationAsync_EvaluerUneFormationValide_EvaluationRealiseeAvecSucces() { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -198,7 +200,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -259,7 +261,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; bool? estCertifiee = null; @@ -321,7 +323,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; DateTime? dateDebut = null; @@ -383,7 +385,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -411,7 +413,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -439,7 +441,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -498,7 +500,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -558,7 +560,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = null; @@ -574,7 +576,7 @@ namespace EPAServeur.Tests.Services public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecte_LeveUneParticipationFormationIncompatibleIdException(long idParticipationFormationIncompatible) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -634,7 +636,7 @@ namespace EPAServeur.Tests.Services public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecteAuNiveauDuDTO_LeveUneParticipationFormationIncompatibleIdException(long? idParticipationFormationIncompatible) { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) @@ -695,7 +697,7 @@ namespace EPAServeur.Tests.Services { // Arrange - ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); long idParticipationFormation = 5; long idParticipationFormationInexistant = 0; diff --git a/EPAServeur.Tests/Services/ReferentEPTests.cs b/EPAServeur.Tests/Services/ReferentEPTests.cs index b376aac..7774297 100644 --- a/EPAServeur.Tests/Services/ReferentEPTests.cs +++ b/EPAServeur.Tests/Services/ReferentEPTests.cs @@ -22,6 +22,7 @@ namespace EPAServeur.Tests.Services private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; + private ITransformDTO transformDTO; private Guid? referent1; private Guid? collaborateur1, collaborateur2, collaborateur3; private Guid? collaborateurNonExistant, collaborateurParti; @@ -48,7 +49,8 @@ namespace EPAServeur.Tests.Services entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); - collaborateurService = new CollaborateurService(collaborateurApi, context); + transformDTO = new TransformDTO(); + collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO); referent1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696");