Ajout des tests pour mettre à jour une liste de collaborateur pour un référent

develop
Yanaël GRETTE 4 years ago
parent 2523a0d9f7
commit ee2a5e422d
  1. 110
      EPAServeur.Tests/Services/ReferentEPTests.cs

@ -1,6 +1,7 @@
using EPAServeur.Context; using EPAServeur.Context;
using EPAServeur.Exceptions; using EPAServeur.Exceptions;
using EPAServeur.IServices; using EPAServeur.IServices;
using EPAServeur.Models.EP;
using EPAServeur.Services; using EPAServeur.Services;
using IO.Swagger.ApiCollaborateur; using IO.Swagger.ApiCollaborateur;
using IO.Swagger.ClientCollaborateur; using IO.Swagger.ClientCollaborateur;
@ -21,7 +22,7 @@ namespace EPAServeur.Tests.Services
private EpContext context; private EpContext context;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private Guid? referent1, referent2, referent3; private Guid? referent1;
private Guid? collaborateur1, collaborateur2, collaborateur3; private Guid? collaborateur1, collaborateur2, collaborateur3;
private Guid? collaborateurNonExistant, collaborateurParti; private Guid? collaborateurNonExistant, collaborateurParti;
#endregion #endregion
@ -37,6 +38,7 @@ namespace EPAServeur.Tests.Services
context = new EpContext(optionBuider); context = new EpContext(optionBuider);
context.Database.EnsureDeleted(); context.Database.EnsureDeleted();
context.Database.EnsureCreated(); context.Database.EnsureCreated();
context.SaveChanges(); context.SaveChanges();
@ -49,16 +51,13 @@ namespace EPAServeur.Tests.Services
collaborateurService = new CollaborateurService(collaborateurApi, context); collaborateurService = new CollaborateurService(collaborateurApi, context);
referent1 = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"); referent1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696");
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");
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(); collaborateurNonExistant = new Guid();
collaborateurParti = new Guid("3c99214d-0a5e-4bb6-b7b2-7d9bb8143c50"); collaborateurParti = new Guid("ea027734-ff0f-4308-8879-133a09fb3c46");
} }
#endregion #endregion
@ -70,8 +69,6 @@ namespace EPAServeur.Tests.Services
{ {
ReferentEPService referentEPService = new ReferentEPService(context, collaborateurApi); ReferentEPService referentEPService = new ReferentEPService(context, collaborateurApi);
CollaborateurDTO collaborateurDTO1 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); CollaborateurDTO collaborateurDTO1 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1);
CollaborateurDTO collaborateurDTO2 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur2);
CollaborateurDTO collaborateurDTO3 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur3);
ReferentEPDTO referentEPDTO1 = new ReferentEPDTO() ReferentEPDTO referentEPDTO1 = new ReferentEPDTO()
{ {
@ -80,47 +77,18 @@ namespace EPAServeur.Tests.Services
}; };
referentEPDTO1.IdsCollaborateur.Add(collaborateur1); referentEPDTO1.IdsCollaborateur.Add(collaborateur1);
ReferentEPDTO referentEPDTO2 = new ReferentEPDTO()
{
IdReferent = referent2,
IdsCollaborateur = new List<Guid?>(),
};
referentEPDTO2.IdsCollaborateur.Add(collaborateur2);
ReferentEPDTO referentEPDTO3 = new ReferentEPDTO()
{
IdReferent = referent3,
IdsCollaborateur = new List<Guid?>(),
};
referentEPDTO3.IdsCollaborateur.Add(collaborateur3);
await referentEPService.UpdateReferentCollaborateurAsync(referentEPDTO1, collaborateur1); await referentEPService.UpdateReferentCollaborateurAsync(referentEPDTO1, collaborateur1);
await referentEPService.UpdateReferentCollaborateurAsync(referentEPDTO2, collaborateur2);
await referentEPService.UpdateReferentCollaborateurAsync(referentEPDTO3, collaborateur3);
Assert.IsNotNull(collaborateurDTO1); Assert.IsNotNull(collaborateurDTO1);
Assert.IsNull(collaborateurDTO1.Referent); Assert.IsNull(collaborateurDTO1.Referent);
Assert.IsNotNull(collaborateurDTO2);
Assert.IsNull(collaborateurDTO2.Referent);
Assert.IsNotNull(collaborateurDTO3);
Assert.IsNull(collaborateurDTO3.Referent);
collaborateurDTO1 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); collaborateurDTO1 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1);
collaborateurDTO2 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur2);
collaborateurDTO3 = await collaborateurService.GetCollaborateurByIdAsync(collaborateur3);
Assert.IsNotNull(collaborateurDTO1); Assert.IsNotNull(collaborateurDTO1);
Assert.IsNotNull(collaborateurDTO1.Referent); Assert.IsNotNull(collaborateurDTO1.Referent);
Assert.AreEqual(collaborateurDTO1.Referent.Id, referent1); 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] [Test]
@ -220,5 +188,67 @@ namespace EPAServeur.Tests.Services
#endregion #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<Guid?>(),
};
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<Guid?>(),
};
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<Guid?>(),
};
referentEPDTO.IdsCollaborateur.Add(collaborateur1);
referentEPDTO.IdsCollaborateur.Add(collaborateur3);
referentEPDTO.IdsCollaborateur.Add(collaborateur2);
AsyncTestDelegate exception = () => referentEPService.UpdateCollaborateursReferentAsync(referentEPDTO, collaborateurNonExistant);
Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception);
}
#endregion
} }
} }

Loading…
Cancel
Save