From ee2a5e422d32bb518904d7db6d9fd434ec746e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Tue, 2 Feb 2021 16:46:58 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20tests=20pour=20mettre=20=C3=A0=20?= =?UTF-8?q?jour=20une=20liste=20de=20collaborateur=20pour=20un=20r=C3=A9f?= =?UTF-8?q?=C3=A9rent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EPAServeur.Tests/Services/ReferentEPTests.cs | 110 ++++++++++++------- 1 file changed, 70 insertions(+), 40 deletions(-) diff --git a/EPAServeur.Tests/Services/ReferentEPTests.cs b/EPAServeur.Tests/Services/ReferentEPTests.cs index 501d66b..b376aac 100644 --- a/EPAServeur.Tests/Services/ReferentEPTests.cs +++ b/EPAServeur.Tests/Services/ReferentEPTests.cs @@ -1,6 +1,7 @@ using EPAServeur.Context; using EPAServeur.Exceptions; using EPAServeur.IServices; +using EPAServeur.Models.EP; using EPAServeur.Services; using IO.Swagger.ApiCollaborateur; using IO.Swagger.ClientCollaborateur; @@ -21,7 +22,7 @@ namespace EPAServeur.Tests.Services private EpContext context; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; - private Guid? referent1, referent2, referent3; + private Guid? referent1; private Guid? collaborateur1, collaborateur2, collaborateur3; private Guid? collaborateurNonExistant, collaborateurParti; #endregion @@ -37,6 +38,7 @@ namespace EPAServeur.Tests.Services context = new EpContext(optionBuider); + context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.SaveChanges(); @@ -49,16 +51,13 @@ namespace EPAServeur.Tests.Services collaborateurService = new CollaborateurService(collaborateurApi, context); - referent1 = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"); - referent2 = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"); - referent3 = new Guid("23d629cd-df09-404a-a6ff-81341db55f29"); - - collaborateur1 = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"); - collaborateur2 = new Guid("9e1ee839-4477-4d64-9b4d-80654c97c39f"); - collaborateur3 = new Guid("97e606a1-2fef-4cbf-b6a9-00366fabc412"); + referent1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696"); + collaborateur1 = new Guid("301ba7f3-095e-4912-8998-a7c942dc5f23"); + collaborateur2 = new Guid("a43b6f4f-f199-4dd0-93b6-a1cb2c0a0d14"); + collaborateur3 = new Guid("b5254c6c-7caa-435f-a4bb-e0cf92559832"); collaborateurNonExistant = new Guid(); - collaborateurParti = new Guid("3c99214d-0a5e-4bb6-b7b2-7d9bb8143c50"); + collaborateurParti = new Guid("ea027734-ff0f-4308-8879-133a09fb3c46"); } #endregion @@ -70,8 +69,6 @@ namespace EPAServeur.Tests.Services { ReferentEPService referentEPService = new ReferentEPService(context, collaborateurApi); CollaborateurDTO collaborateurDTO1 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); - CollaborateurDTO collaborateurDTO2 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur2); - CollaborateurDTO collaborateurDTO3 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur3); ReferentEPDTO referentEPDTO1 = new ReferentEPDTO() { @@ -80,47 +77,18 @@ namespace EPAServeur.Tests.Services }; referentEPDTO1.IdsCollaborateur.Add(collaborateur1); - ReferentEPDTO referentEPDTO2 = new ReferentEPDTO() - { - IdReferent = referent2, - IdsCollaborateur = new List(), - }; - referentEPDTO2.IdsCollaborateur.Add(collaborateur2); - - ReferentEPDTO referentEPDTO3 = new ReferentEPDTO() - { - IdReferent = referent3, - IdsCollaborateur = new List(), - }; - referentEPDTO3.IdsCollaborateur.Add(collaborateur3); await referentEPService.UpdateReferentCollaborateurAsync(referentEPDTO1, collaborateur1); - await referentEPService.UpdateReferentCollaborateurAsync(referentEPDTO2, collaborateur2); - await referentEPService.UpdateReferentCollaborateurAsync(referentEPDTO3, collaborateur3); Assert.IsNotNull(collaborateurDTO1); Assert.IsNull(collaborateurDTO1.Referent); - Assert.IsNotNull(collaborateurDTO2); - Assert.IsNull(collaborateurDTO2.Referent); - Assert.IsNotNull(collaborateurDTO3); - Assert.IsNull(collaborateurDTO3.Referent); collaborateurDTO1 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); - collaborateurDTO2 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur2); - collaborateurDTO3 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur3); Assert.IsNotNull(collaborateurDTO1); Assert.IsNotNull(collaborateurDTO1.Referent); Assert.AreEqual(collaborateurDTO1.Referent.Id, referent1); - - Assert.IsNotNull(collaborateurDTO2); - Assert.IsNotNull(collaborateurDTO2.Referent); - Assert.AreEqual(collaborateurDTO2.Referent.Id, referent2); - - Assert.IsNotNull(collaborateurDTO3); - Assert.IsNotNull(collaborateurDTO3.Referent); - Assert.AreEqual(collaborateurDTO3.Referent.Id, referent3); } [Test] @@ -220,5 +188,67 @@ namespace EPAServeur.Tests.Services #endregion + + + #region ajout de plusieurs collaborateur + + [Test] + public async Task UpdateCollaborateursReferent() + { + ReferentEPService referentEPService = new ReferentEPService(context, collaborateurApi); + ReferentEPDTO referentEPDTO = new ReferentEPDTO() + { + IdReferent = referent1, + IdsCollaborateur = new List(), + }; + referentEPDTO.IdsCollaborateur.Add(collaborateur1); + referentEPDTO.IdsCollaborateur.Add(collaborateur3); + referentEPDTO.IdsCollaborateur.Add(collaborateur2); + + await referentEPService.UpdateCollaborateursReferentAsync(referentEPDTO, referent1); + + foreach(Guid guid in referentEPDTO.IdsCollaborateur) + { + ReferentEP referentEP = await context.ReferentEP.FindAsync(guid); + Assert.AreEqual(referent1, referentEP.IdReferent); + } + } + + [Test] + public void UpdateCollaborateursReferent_CollaborateurNotFound() + { + ReferentEPService referentEPService = new ReferentEPService(context, collaborateurApi); + ReferentEPDTO referentEPDTO = new ReferentEPDTO() + { + IdReferent = referent1, + IdsCollaborateur = new List(), + }; + referentEPDTO.IdsCollaborateur.Add(collaborateur1); + referentEPDTO.IdsCollaborateur.Add(collaborateur3); + referentEPDTO.IdsCollaborateur.Add(collaborateurNonExistant); + referentEPDTO.IdsCollaborateur.Add(collaborateur2); + + AsyncTestDelegate exception = () => referentEPService.UpdateCollaborateursReferentAsync(referentEPDTO, referent1); + Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); + } + + [Test] + public void UpdateCollaborateursReferent_ReferentNotFound() + { + ReferentEPService referentEPService = new ReferentEPService(context, collaborateurApi); + ReferentEPDTO referentEPDTO = new ReferentEPDTO() + { + IdReferent = collaborateurNonExistant, + IdsCollaborateur = new List(), + }; + referentEPDTO.IdsCollaborateur.Add(collaborateur1); + referentEPDTO.IdsCollaborateur.Add(collaborateur3); + referentEPDTO.IdsCollaborateur.Add(collaborateur2); + + AsyncTestDelegate exception = () => referentEPService.UpdateCollaborateursReferentAsync(referentEPDTO, collaborateurNonExistant); + Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); + + } + #endregion } }