Merge branch 'develop' into demande_formation

develop
jboinembalome 4 years ago
commit ed83ee261c
  1. 6
      EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs
  2. 1
      EPAServeur.Tests/Controllers/EngagementsApiTests.cs
  3. 6
      EPAServeur.Tests/Controllers/EpInformationApiTests.cs
  4. 1
      EPAServeur.Tests/Controllers/FormationApiTests.cs
  5. 7
      EPAServeur.Tests/Controllers/NoteApiTests.cs
  6. 1
      EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs
  7. 1
      EPAServeur.Tests/Controllers/ReferentEPApiTests.cs
  8. 72
      EPAServeur.Tests/Services/CollaborateurServiceTests.cs
  9. 19
      EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs
  10. 53
      EPAServeur.Tests/Services/EngagementServiceTests.cs
  11. 45
      EPAServeur.Tests/Services/EpInformationTests.cs
  12. 82
      EPAServeur.Tests/Services/FormationServiceTests.cs
  13. 36
      EPAServeur.Tests/Services/NoteServiceTests.cs
  14. 36
      EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs
  15. 4
      EPAServeur.Tests/Services/ReferentEPTests.cs
  16. 9
      EPAServeur/IServices/ICollaborateurService.cs
  17. 59
      EPAServeur/IServices/ITransformDTO.cs
  18. 216
      EPAServeur/Services/CollaborateurService.cs
  19. 47
      EPAServeur/Services/DemandeDelegationService.cs
  20. 150
      EPAServeur/Services/EngagementService.cs
  21. 69
      EPAServeur/Services/EpInformationService.cs
  22. 413
      EPAServeur/Services/FormationService.cs
  23. 88
      EPAServeur/Services/NoteService.cs
  24. 250
      EPAServeur/Services/ParticipationFormationService.cs
  25. 713
      EPAServeur/Services/TransformDTO.cs
  26. 1
      EPAServeur/Startup.cs

@ -25,6 +25,7 @@ namespace EPAServeur.Tests.Controllers
IDemandeDelegationService demandeDelegationService; IDemandeDelegationService demandeDelegationService;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
#endregion #endregion
#region Setup #region Setup
@ -55,8 +56,9 @@ namespace EPAServeur.Tests.Controllers
} }
collaborateurApi = new CollaborateurApi(); collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, context); transformDTO = new TransformDTO();
demandeDelegationService = new DemandeDelegationService(collaborateurService, context); collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO);
} }
#endregion #endregion

@ -64,6 +64,7 @@ namespace EPAServeur.Tests.Controllers
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
services.AddScoped<ITransformDTO, TransformDTO>();
services.AddScoped<ICollaborateurApi, CollaborateurApi>(); services.AddScoped<ICollaborateurApi, CollaborateurApi>();
services.AddScoped<ICollaborateurService, CollaborateurService>(); services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IEngagementService, EngagementService>(); services.AddScoped<IEngagementService, EngagementService>();

@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Controllers
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private IEpInformationService epInformationService; private IEpInformationService epInformationService;
private ILogger<EpApiController> logger; private ILogger<EpApiController> logger;
private ITransformDTO transformDTO;
#endregion #endregion
@ -50,8 +51,9 @@ namespace EPAServeur.Tests.Controllers
{ {
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
collaborateurService = new CollaborateurService(new CollaborateurApi(), context); transformDTO = new TransformDTO();
epInformationService = new EpInformationService(context, collaborateurService); collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO);
epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
} }
#endregion #endregion

@ -63,6 +63,7 @@ namespace EPAServeur.Tests.Controllers
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
services.AddScoped<ITransformDTO, TransformDTO>();
services.AddScoped<ICollaborateurApi, CollaborateurApi>(); services.AddScoped<ICollaborateurApi, CollaborateurApi>();
services.AddScoped<ICollaborateurService, CollaborateurService>(); services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IFormationService, FormationService>(); services.AddScoped<IFormationService, FormationService>();

@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Controllers
private EpContext context; private EpContext context;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
private INoteService noteService; private INoteService noteService;
private ILogger<NotesApiController> logger; private ILogger<NotesApiController> logger;
private Guid? auteur1, collaborateur1; private Guid? auteur1, collaborateur1;
@ -53,8 +54,10 @@ namespace EPAServeur.Tests.Controllers
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
collaborateurApi = new CollaborateurApi(); 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<NotesApiController>(); logger = new NullLogger<NotesApiController>();
auteur1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696"); auteur1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696");

@ -65,6 +65,7 @@ namespace EPAServeur.Tests.Controllers
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
services.AddScoped<ITransformDTO, TransformDTO>();
services.AddScoped<ICollaborateurApi, CollaborateurApi>(); services.AddScoped<ICollaborateurApi, CollaborateurApi>();
services.AddScoped<ICollaborateurService, CollaborateurService>(); services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IParticipationFormationService, ParticipationFormationService>(); services.AddScoped<IParticipationFormationService, ParticipationFormationService>();

@ -21,6 +21,7 @@ namespace EPAServeur.Tests.Controllers
#region Variables #region Variables
private EpContext context; private EpContext context;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ITransformDTO transformDTO;
private IReferentEPService referentEPService; private IReferentEPService referentEPService;
private Guid? referent, collaborateur1, collaborateur2, collaborateur3; private Guid? referent, collaborateur1, collaborateur2, collaborateur3;
#endregion #endregion

@ -20,6 +20,8 @@ namespace EPAServeur.Tests.Services
#region #region
private EpContext context; private EpContext context;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ITransformDTO transformDTO;
#endregion #endregion
#region Setup #region Setup
@ -46,6 +48,7 @@ namespace EPAServeur.Tests.Services
{ {
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
transformDTO = new TransformDTO();
collaborateurApi = new CollaborateurApi(); collaborateurApi = new CollaborateurApi();
} }
#endregion #endregion
@ -57,7 +60,8 @@ namespace EPAServeur.Tests.Services
[TestCase("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491")] [TestCase("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491")]
public async Task GetCollaborateurById_Ok(Guid? id) 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); CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(id);
Assert.IsNotNull(collaborateurDTO); Assert.IsNotNull(collaborateurDTO);
@ -69,7 +73,8 @@ namespace EPAServeur.Tests.Services
[TestCase("coty.lemoine@apside-groupe.com")] [TestCase("coty.lemoine@apside-groupe.com")]
public async Task GetCollaborateurByMail_Ok(string mail) 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); CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByMailAsync(mail);
Assert.IsNotNull(collaborateurDTO); Assert.IsNotNull(collaborateurDTO);
@ -79,9 +84,9 @@ namespace EPAServeur.Tests.Services
[TestCase("006226f6-51b2-4a02-a302-7447f7fccc04")] [TestCase("006226f6-51b2-4a02-a302-7447f7fccc04")]
[TestCase("e5d36da4-df16-4d19-8a11-1ba2f6efc80c")] [TestCase("e5d36da4-df16-4d19-8a11-1ba2f6efc80c")]
[TestCase("92b29b9c-40a4-4aa0-9412-bc97a379e52f")] [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); AsyncTestDelegate exception = () => collaborateurService.GetCollaborateurByIdAsync(id);
Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception);
@ -90,9 +95,10 @@ namespace EPAServeur.Tests.Services
[TestCase("nicolas@apside.fr")] [TestCase("nicolas@apside.fr")]
[TestCase("rousseau@apside.fr")] [TestCase("rousseau@apside.fr")]
[TestCase("lemoine@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); AsyncTestDelegate exception = () => collaborateurService.GetCollaborateurByMailAsync(mail);
Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception);
} }
@ -108,7 +114,7 @@ namespace EPAServeur.Tests.Services
[TestCase("RA")] [TestCase("RA")]
public async Task GetCollaborateurs_UnRole(string role) public async Task GetCollaborateurs_UnRole(string role)
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
List<string> roles = new List<string>(); List<string> roles = new List<string>();
roles.Add(role); roles.Add(role);
@ -142,7 +148,7 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateurs_RoleRH_RoleAssistant() public async Task GetCollaborateurs_RoleRH_RoleAssistant()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
List<string> roles = new List<string>(); List<string> roles = new List<string>();
roles.Add("Assistant"); roles.Add("Assistant");
@ -156,7 +162,7 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateurs_RoleRA_RoleManager() public async Task GetCollaborateurs_RoleRA_RoleManager()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
List<string> roles = new List<string>(); List<string> roles = new List<string>();
roles.Add("Manager"); roles.Add("Manager");
@ -175,7 +181,8 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateurs_Asc_Desc() public async Task GetCollaborateurs_Asc_Desc()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
IEnumerable<CollaborateurDTO> collaborateursAsc = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", null, null); IEnumerable<CollaborateurDTO> collaborateursAsc = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", null, null);
IEnumerable<CollaborateurDTO> collaborateursDesc = await collaborateurService.GetCollaborateursAsync(null, null, false, 1, 50, "", "", null, null); IEnumerable<CollaborateurDTO> collaborateursDesc = await collaborateurService.GetCollaborateursAsync(null, null, false, 1, 50, "", "", null, null);
CollaborateurDTO collaborateurDTOFirstAsc = collaborateursAsc.First(); CollaborateurDTO collaborateurDTOFirstAsc = collaborateursAsc.First();
@ -193,7 +200,8 @@ namespace EPAServeur.Tests.Services
[TestCase("")] [TestCase("")]
public async Task GetCollaborateurs_Texte(string texte) public async Task GetCollaborateurs_Texte(string texte)
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, texte, "", null, null); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, texte, "", null, null);
string nomprenom, prenomnom; string nomprenom, prenomnom;
foreach(CollaborateurDTO collaborateur in collaborateurs) foreach(CollaborateurDTO collaborateur in collaborateurs)
@ -210,7 +218,8 @@ namespace EPAServeur.Tests.Services
[TestCase(2018,1,1)] [TestCase(2018,1,1)]
public async Task GetCollaborateurs_DateDebut(int annee, int mois, int jour) 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); DateTime dateDebut = new DateTime(annee, mois, jour);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", dateDebut, null); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", dateDebut, null);
foreach(CollaborateurDTO collaborateur in collaborateurs) foreach(CollaborateurDTO collaborateur in collaborateurs)
@ -225,7 +234,8 @@ namespace EPAServeur.Tests.Services
[TestCase(2017, 12, 31)] [TestCase(2017, 12, 31)]
public async Task GetCollaborateurs_DateFin(int annee, int mois, int jour) 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); DateTime dateFin = new DateTime(annee, mois, jour);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", null, dateFin); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", null, dateFin);
foreach (CollaborateurDTO collaborateur in collaborateurs) foreach (CollaborateurDTO collaborateur in collaborateurs)
@ -240,7 +250,8 @@ namespace EPAServeur.Tests.Services
[TestCase(2019,1,1,2019,12,31)] [TestCase(2019,1,1,2019,12,31)]
public async Task GetCollaborateurs_DateDebutDateFin(int anneeDeb, int moisDeb, int jourDeb, int anneeFin, int moisFin, int jourFin) public async Task GetCollaborateurs_DateDebutDateFin(int anneeDeb, int moisDeb, int jourDeb, int anneeFin, int moisFin, int jourFin)
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
DateTime dateDebut = new DateTime(anneeDeb, moisDeb, jourDeb); DateTime dateDebut = new DateTime(anneeDeb, moisDeb, jourDeb);
DateTime dateFin = new DateTime(anneeFin, moisFin, jourFin); DateTime dateFin = new DateTime(anneeFin, moisFin, jourFin);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", dateDebut, dateFin); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 50, "", "", dateDebut, dateFin);
@ -259,7 +270,8 @@ namespace EPAServeur.Tests.Services
[TestCase(1,37)] [TestCase(1,37)]
public async Task GetCollaborateur_Paginaion(int numPage, int parPage) public async Task GetCollaborateur_Paginaion(int numPage, int parPage)
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null);
Assert.AreEqual(collaborateurs.Count(), parPage); Assert.AreEqual(collaborateurs.Count(), parPage);
} }
@ -269,7 +281,8 @@ namespace EPAServeur.Tests.Services
[TestCase(8, 5, 2)] [TestCase(8, 5, 2)]
public async Task GetCollaborateur_Paginaion_2(int numPage, int parPage, int res) 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<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null);
Assert.AreEqual(collaborateurs.Count(), res); Assert.AreEqual(collaborateurs.Count(), res);
} }
@ -281,7 +294,8 @@ namespace EPAServeur.Tests.Services
[TestCase(-1, 37)] [TestCase(-1, 37)]
public async Task GetCollaborateur_PaginaionValeursParDefaut(int numPage, int parPage) public async Task GetCollaborateur_PaginaionValeursParDefaut(int numPage, int parPage)
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, numPage, parPage, "", "", null, null);
if(parPage < 5) if(parPage < 5)
@ -294,7 +308,8 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateur_OrderByDateArrive() public async Task GetCollaborateur_OrderByDateArrive()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "datearrivee", null, null); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "datearrivee", null, null);
DateTime d1, d2; DateTime d1, d2;
for(int i = 0; i < collaborateurs.Count() -1; ++i) for(int i = 0; i < collaborateurs.Count() -1; ++i)
@ -310,7 +325,8 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateur_OrderByBU() public async Task GetCollaborateur_OrderByBU()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "businessunit", null, null); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "businessunit", null, null);
string bu1, bu2; string bu1, bu2;
for (int i = 0; i < collaborateurs.Count() - 1; ++i) for (int i = 0; i < collaborateurs.Count() - 1; ++i)
@ -327,7 +343,8 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateur_OrderByNom() public async Task GetCollaborateur_OrderByNom()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "collaborateur", null, null); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(null, null, true, 1, 30, "", "collaborateur", null, null);
string nom1, nom2; string nom1, nom2;
for (int i = 0; i < collaborateurs.Count() - 1; ++i) for (int i = 0; i < collaborateurs.Count() - 1; ++i)
@ -348,7 +365,8 @@ namespace EPAServeur.Tests.Services
[TestCase("642bc07f-051a-4088-8a73-425b44998673")] [TestCase("642bc07f-051a-4088-8a73-425b44998673")]
public async Task GetCollaborateurByReferentPlusCount(Guid idReferent) public async Task GetCollaborateurByReferentPlusCount(Guid idReferent)
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursByReferentAsync(idReferent, true, 1, 15, "", ""); IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursByReferentAsync(idReferent, true, 1, 15, "", "");
int count = await collaborateurService.GetCollaborateursCountByReferentAsync(idReferent, ""); int count = await collaborateurService.GetCollaborateursCountByReferentAsync(idReferent, "");
Assert.AreEqual(count, collaborateurs.Count()); Assert.AreEqual(count, collaborateurs.Count());
@ -361,7 +379,8 @@ namespace EPAServeur.Tests.Services
[TestCase("ca1f480a-9918-4cea-819c-62e5c7f2b332")] [TestCase("ca1f480a-9918-4cea-819c-62e5c7f2b332")]
public void GetCollaborateurByReferent_ReferentNotFound(Guid idReferent) 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, "", ""); AsyncTestDelegate exception = () => collaborateurService.GetCollaborateursByReferentAsync(idReferent, true, 1, 15, "", "");
Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception);
} }
@ -375,7 +394,8 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateurByGuids() public async Task GetCollaborateurByGuids()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
List<Guid?> guids = new List<Guid?>(); List<Guid?> guids = new List<Guid?>();
guids.Add(new Guid("ebd911ef-a6a8-4047-afdc-9a9066aa1a07")); guids.Add(new Guid("ebd911ef-a6a8-4047-afdc-9a9066aa1a07"));
guids.Add(new Guid("71d33f6d-695a-4dc6-ae1a-b1605fd2073d")); guids.Add(new Guid("71d33f6d-695a-4dc6-ae1a-b1605fd2073d"));
@ -394,7 +414,8 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateurByGuidsAvecIdsNonExistantEnPlus() public async Task GetCollaborateurByGuidsAvecIdsNonExistantEnPlus()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
List<Guid?> guids = new List<Guid?>(); List<Guid?> guids = new List<Guid?>();
guids.Add(new Guid("b645f582-0a5d-48dc-97a1-4ebb0fb3a29f")); guids.Add(new Guid("b645f582-0a5d-48dc-97a1-4ebb0fb3a29f"));
guids.Add(new Guid()); guids.Add(new Guid());
@ -414,7 +435,8 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetCollaborateurByGuidsAvecIdsNonExistantUniquement() public async Task GetCollaborateurByGuidsAvecIdsNonExistantUniquement()
{ {
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context); ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
List<Guid?> guids = new List<Guid?>(); List<Guid?> guids = new List<Guid?>();
guids.Add(new Guid()); guids.Add(new Guid());
guids.Add(new Guid()); guids.Add(new Guid());

@ -23,6 +23,8 @@ namespace EPAServeur.Tests.Services
private EpContext context; private EpContext context;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
#endregion #endregion
#region Setup #region Setup
@ -52,7 +54,8 @@ namespace EPAServeur.Tests.Services
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
collaborateurApi = new CollaborateurApi(); collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, context); transformDTO = new TransformDTO();
collaborateurService = new CollaborateurService(collaborateurApi, context, transformDTO);
} }
#endregion #endregion
@ -65,7 +68,7 @@ namespace EPAServeur.Tests.Services
[TestCase("17b87130-0e9d-4b78-b0e3-a11e5f70318d", 1)] [TestCase("17b87130-0e9d-4b78-b0e3-a11e5f70318d", 1)]
public async Task RecupererDemandesDelegation_OK(Guid? idReferent, int count) public async Task RecupererDemandesDelegation_OK(Guid? idReferent, int count)
{ {
IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO);
IEnumerable<DemandeDelegationDTO> demandesDelegation = await demandeDelegationService.RecupererDemandesDelegation(idReferent); IEnumerable<DemandeDelegationDTO> demandesDelegation = await demandeDelegationService.RecupererDemandesDelegation(idReferent);
foreach (DemandeDelegationDTO demandeDelegation in demandesDelegation) foreach (DemandeDelegationDTO demandeDelegation in demandesDelegation)
{ {
@ -80,7 +83,7 @@ namespace EPAServeur.Tests.Services
public void RecupererDemandeDelegation_ReferentNotFound() public void RecupererDemandeDelegation_ReferentNotFound()
{ {
Guid? idReferent = new Guid(); Guid? idReferent = new Guid();
IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context, transformDTO);
AsyncTestDelegate exception = () => demandeDelegationService.RecupererDemandesDelegation(idReferent); AsyncTestDelegate exception = () => demandeDelegationService.RecupererDemandesDelegation(idReferent);
Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception);
} }
@ -93,7 +96,7 @@ namespace EPAServeur.Tests.Services
[TestCase(5)] [TestCase(5)]
public async Task UpdateDemandeDelegation_ReponsePositive(long id) 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); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id);
long idEp = demandeDelegation.IdEP; long idEp = demandeDelegation.IdEP;
@ -125,7 +128,7 @@ namespace EPAServeur.Tests.Services
[TestCase(6)] [TestCase(6)]
public async Task UpdateDemandeDelegation_ReponseNegative(long id) 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); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id);
long idEp = demandeDelegation.IdEP; long idEp = demandeDelegation.IdEP;
@ -156,7 +159,7 @@ namespace EPAServeur.Tests.Services
[TestCase(10, EtatDemande.Rejetee, "exemple refus")] [TestCase(10, EtatDemande.Rejetee, "exemple refus")]
public void UpdateDemandeDelegation_DemandeNonExistante(long id, EtatDemande etatDemande, string raisonRefus) 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() DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO()
{ {
Id = id, Id = id,
@ -176,7 +179,7 @@ namespace EPAServeur.Tests.Services
[TestCase(4, 1,EtatDemande.Rejetee, "exemple refus")] [TestCase(4, 1,EtatDemande.Rejetee, "exemple refus")]
public void UpdateDemandeDelegation_DemandeIncompatible(long id, long idIncompatible, EtatDemande etatDemande, string raisonRefus) 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() DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO()
{ {
Id = id, Id = id,
@ -199,7 +202,7 @@ namespace EPAServeur.Tests.Services
[TestCase(7, EtatDemande.Rejetee, "")] [TestCase(7, EtatDemande.Rejetee, "")]
public async Task UpdateDemandeDelegation_DemandeInvalid(long id, EtatDemande etatDemande, string raisonRefus) 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); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id);
long idEp = demandeDelegation.IdEP; long idEp = demandeDelegation.IdEP;

@ -23,6 +23,8 @@ namespace EPAServeur.Tests.Services
private EpContext epContext; private EpContext epContext;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
#endregion #endregion
#region Setup #region Setup
@ -37,7 +39,8 @@ namespace EPAServeur.Tests.Services
epContext = new EpContext(optionBuider); epContext = new EpContext(optionBuider);
collaborateurApi = new CollaborateurApi(); collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, epContext); transformDTO = new TransformDTO();
collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO);
epContext.Database.EnsureDeleted(); epContext.Database.EnsureDeleted();
epContext.Database.EnsureCreated(); epContext.Database.EnsureCreated();
epContext.SaveChanges(); epContext.SaveChanges();
@ -61,7 +64,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseDesParamsDesIdBUValides_RetourneDesEngagements(long[] arrIdBUs) public async Task GetEngagementsAsync_PasseDesParamsDesIdBUValides_RetourneDesEngagements(long[] arrIdBUs)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = arrIdBUs.Select(x => x).ToList(); List<long> idBUs = arrIdBUs.Select(x => x).ToList();
// Act // Act
@ -76,7 +79,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseDesParamsDesEtatsDEngagementsValides_RetourneDesEngagements(EtatEngagement[] arrEtatsEngagement) public async Task GetEngagementsAsync_PasseDesParamsDesEtatsDEngagementsValides_RetourneDesEngagements(EtatEngagement[] arrEtatsEngagement)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
List<EtatEngagement> etatEngagements = arrEtatsEngagement.Select(x => x).ToList(); List<EtatEngagement> etatEngagements = arrEtatsEngagement.Select(x => x).ToList();
@ -92,7 +95,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesEngagements(int? numPage, int? parPage) public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesEngagements(int? numPage, int? parPage)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
// Act // Act
@ -109,7 +112,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPage) public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPage)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
int? nbEngagementDeuxiemePage; int? nbEngagementDeuxiemePage;
@ -142,7 +145,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionCroissant(bool? asc, string tri) public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionCroissant(bool? asc, string tri)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
// Act // Act
@ -159,7 +162,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionDecroissant(bool? asc, string tri) public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionDecroissant(bool? asc, string tri)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
// Act // Act
@ -174,7 +177,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifCroissant() public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifCroissant()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
bool? asc = true; bool? asc = true;
string tri = "dispositif"; string tri = "dispositif";
@ -191,7 +194,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifDecroissant() public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifDecroissant()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
bool? asc = false; bool? asc = false;
string tri = "dispositif"; string tri = "dispositif";
@ -208,7 +211,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteCroissante() public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteCroissante()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
bool? asc = true; bool? asc = true;
string tri = "modalite"; string tri = "modalite";
@ -225,7 +228,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteDecroissante() public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteDecroissante()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
bool? asc = false; bool? asc = false;
string tri = "modalite"; string tri = "modalite";
@ -242,7 +245,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateCroissante() public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateCroissante()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
bool? asc = true; bool? asc = true;
string tri = "date"; string tri = "date";
@ -259,7 +262,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateDecroissante() public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateDecroissante()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>() { 1, 2, 3 }; List<long> idBUs = new List<long>() { 1, 2, 3 };
bool? asc = false; bool? asc = false;
string tri = "date"; string tri = "date";
@ -279,7 +282,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsAsync_PasseDesParamsInvalides_RetourneZeroEngagement(long[] arrIdBUs, string texte) public async Task GetEngagementsAsync_PasseDesParamsInvalides_RetourneZeroEngagement(long[] arrIdBUs, string texte)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs; List<long> idBUs;
if (arrIdBUs != null) if (arrIdBUs != null)
@ -298,7 +301,7 @@ namespace EPAServeur.Tests.Services
public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUVide_LeveUneEngagementInvalidException() public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUVide_LeveUneEngagementInvalidException()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = new List<long>(); List<long> idBUs = new List<long>();
// Act // Act
@ -312,7 +315,7 @@ namespace EPAServeur.Tests.Services
public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUNull_LeveUneEngagementInvalidException() public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUNull_LeveUneEngagementInvalidException()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs = null; List<long> idBUs = null;
// Act // Act
@ -332,7 +335,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDEngagements(long[] arrIdBUs, string texte) public async Task GetEngagementsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDEngagements(long[] arrIdBUs, string texte)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs; List<long> idBUs;
if (arrIdBUs != null) if (arrIdBUs != null)
@ -353,7 +356,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEngagementsCountAsync_PasseDesParamsInvalides_RetourneZero(long[] arrIdBUs, string texte) public async Task GetEngagementsCountAsync_PasseDesParamsInvalides_RetourneZero(long[] arrIdBUs, string texte)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
List<long> idBUs; List<long> idBUs;
if (arrIdBUs != null) 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) public async Task RepondreEngagementAsync_ModifieUnEngagementValide_EngagementModifieAvecSucces(long idEngagement, long idEp, EtatEngagement etatEngagement, string raisonNonRealisable)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
.Select(ep => new EpInformationDTO .Select(ep => new EpInformationDTO
@ -423,7 +426,7 @@ namespace EPAServeur.Tests.Services
string raisonNonRealisableAvantUpdate = null; string raisonNonRealisableAvantUpdate = null;
string raisonNonRealisableApresUpdate = "La date limite pour respecter l'engagement est passée."; string raisonNonRealisableApresUpdate = "La date limite pour respecter l'engagement est passée.";
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
.Select(ep => new EpInformationDTO .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) public void RepondreEngagementAsync_ModifieUnEngagementAvecDesProprietesInvalide_LeveUneEngagementInvalidException(long idEngagement, long idEp, string action, string dispositif, string modalite, DateTime? dateLimite, EtatEngagement etatEngagement, string raisonNonRealisable)
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp) EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
.Select(ep => new EpInformationDTO .Select(ep => new EpInformationDTO
@ -505,7 +508,7 @@ namespace EPAServeur.Tests.Services
public void RepondreEngagementAsync_ModifieUnEngagementNull_LeveUneEngagementInvalidException() public void RepondreEngagementAsync_ModifieUnEngagementNull_LeveUneEngagementInvalidException()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
EngagementDTO engagementDTO = null; EngagementDTO engagementDTO = null;
long idEngagement = 1; long idEngagement = 1;
@ -520,7 +523,7 @@ namespace EPAServeur.Tests.Services
public void RepondreEngagementAsync_ModifieUnEngagementAvecUnEPInexistantDansLaBDD_LeveUneEngagementInvalidException() public void RepondreEngagementAsync_ModifieUnEngagementAvecUnEPInexistantDansLaBDD_LeveUneEngagementInvalidException()
{ {
// Arrange // Arrange
EngagementService engagementService = new EngagementService(epContext, collaborateurService); EngagementService engagementService = new EngagementService(epContext, collaborateurService, transformDTO);
long idEngagement = 1; long idEngagement = 1;
EpInformationDTO epInformationDTO = new EpInformationDTO EpInformationDTO epInformationDTO = new EpInformationDTO
{ {
@ -561,7 +564,7 @@ namespace EPAServeur.Tests.Services
long idEngagementIncorrecte = 2; long idEngagementIncorrecte = 2;
long idEp = 9; 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) EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
.Select(ep => new EpInformationDTO .Select(ep => new EpInformationDTO
@ -600,7 +603,7 @@ namespace EPAServeur.Tests.Services
long idEngagement = 0; long idEngagement = 0;
long idEp = 9; 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) EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
.Select(ep => new EpInformationDTO .Select(ep => new EpInformationDTO

@ -20,6 +20,8 @@ namespace EPAServeur.Tests.Services
#region #region
private EpContext context; private EpContext context;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
#endregion #endregion
@ -47,7 +49,8 @@ namespace EPAServeur.Tests.Services
{ {
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
collaborateurService = new CollaborateurService(new CollaborateurApi(), context); transformDTO = new TransformDTO();
collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO);
} }
#endregion #endregion
@ -58,7 +61,7 @@ namespace EPAServeur.Tests.Services
[TestCase(3, 3)] // Paris [TestCase(3, 3)] // Paris
public async Task GetEpEnCours_UneBU(long? idBUs, int nbElements) public async Task GetEpEnCours_UneBU(long? idBUs, int nbElements)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?>{ idBUs }, true, 1, 15, "", "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?>{ idBUs }, true, 1, 15, "", "", null, null);
int count = await epInformationService.GetEPEnCoursCount(new List<long?> { idBUs }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPEnCoursCount(new List<long?> { idBUs }, true, 1, 15, "", "", null, null);
@ -74,7 +77,7 @@ namespace EPAServeur.Tests.Services
[Test] [Test]
public async Task GetEpEnCours_OrleansTours() public async Task GetEpEnCours_OrleansTours()
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1,2 }, true, 1, 15, "", "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1,2 }, true, 1, 15, "", "", null, null);
int count = await epInformationService.GetEPEnCoursCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPEnCoursCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, null);
@ -100,7 +103,7 @@ namespace EPAServeur.Tests.Services
[TestCase("datedisponibilite")] [TestCase("datedisponibilite")]
public async Task GetEpEnCours_TriColonneASC(string tri) public async Task GetEpEnCours_TriColonneASC(string tri)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", tri, null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", tri, null, null);
EpInformationDTO ep1, ep2; EpInformationDTO ep1, ep2;
int compare = 0; int compare = 0;
@ -153,7 +156,7 @@ namespace EPAServeur.Tests.Services
[TestCase("datedisponibilite")] [TestCase("datedisponibilite")]
public async Task GetEpEnCours_TriColonneDESC(string tri) public async Task GetEpEnCours_TriColonneDESC(string tri)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, false, 1, 15, "", tri, null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, false, 1, 15, "", tri, null, null);
EpInformationDTO ep1, ep2; EpInformationDTO ep1, ep2;
int compare = 0; int compare = 0;
@ -201,7 +204,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEpEnCours_TriDateD1(int j, int m, int a, int count) public async Task GetEpEnCours_TriDateD1(int j, int m, int a, int count)
{ {
DateTime date = new DateTime(a, m, j); DateTime date = new DateTime(a, m, j);
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
@ -217,7 +220,7 @@ namespace EPAServeur.Tests.Services
[TestCase(1, 02, 2021, 0)] [TestCase(1, 02, 2021, 0)]
public async Task GetEpEnCours_TriDateD2(int j, int m, int a, int count) 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<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
@ -237,7 +240,7 @@ namespace EPAServeur.Tests.Services
{ {
DateTime date1 = new DateTime(a1, m1, j1); DateTime date1 = new DateTime(a1, m1, j1);
DateTime date2 = new DateTime(a2, m2, j2); DateTime date2 = new DateTime(a2, m2, j2);
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
@ -259,7 +262,7 @@ namespace EPAServeur.Tests.Services
[TestCase("d", 2)] [TestCase("d", 2)]
public async Task GetEpEnCours_texte(string texte, int count) public async Task GetEpEnCours_texte(string texte, int count)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCours(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null);
Assert.AreEqual(count, epInformationDTOs.Count()); Assert.AreEqual(count, epInformationDTOs.Count());
foreach (EpInformationDTO ep in epInformationDTOs) foreach (EpInformationDTO ep in epInformationDTOs)
@ -279,7 +282,7 @@ namespace EPAServeur.Tests.Services
[TestCase(3, 3)] // Paris [TestCase(3, 3)] // Paris
public async Task GetEpSignes_UneBU(long? idBUs, int nbElements) public async Task GetEpSignes_UneBU(long? idBUs, int nbElements)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?>{ idBUs }, true, 1, 15, "", "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?>{ idBUs }, true, 1, 15, "", "", null, null);
int count = await epInformationService.GetEPSignesCount(new List<long?> { idBUs }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPSignesCount(new List<long?> { idBUs }, true, 1, 15, "", "", null, null);
@ -295,7 +298,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEpSignes_OrleansTours() public async Task GetEpSignes_OrleansTours()
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1,2 }, true, 1, 15, "", "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1,2 }, true, 1, 15, "", "", null, null);
int count = await epInformationService.GetEPSignesCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, null); int count = await epInformationService.GetEPSignesCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, null);
@ -321,7 +324,7 @@ namespace EPAServeur.Tests.Services
[TestCase("datedisponibilite")] [TestCase("datedisponibilite")]
public async Task GetEpSignes_TriColonneASC(string tri) public async Task GetEpSignes_TriColonneASC(string tri)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", tri, null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", tri, null, null);
EpInformationDTO ep1, ep2; EpInformationDTO ep1, ep2;
int compare = 0; int compare = 0;
@ -375,7 +378,7 @@ namespace EPAServeur.Tests.Services
[TestCase("datedisponibilite")] [TestCase("datedisponibilite")]
public async Task GetEpSignes_TriColonneDESC(string tri) public async Task GetEpSignes_TriColonneDESC(string tri)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, false, 1, 15, "", tri, null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, false, 1, 15, "", tri, null, null);
EpInformationDTO ep1, ep2; EpInformationDTO ep1, ep2;
int compare = 0; int compare = 0;
@ -426,7 +429,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEpSignes_TriDateD1(int j, int m, int a, int count) public async Task GetEpSignes_TriDateD1(int j, int m, int a, int count)
{ {
DateTime date = new DateTime(a, m, j); DateTime date = new DateTime(a, m, j);
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", date, null);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
@ -443,7 +446,7 @@ namespace EPAServeur.Tests.Services
[TestCase(31, 07, 2017)] [TestCase(31, 07, 2017)]
public async Task GetEpSignes_TriDateD2(int j, int m, int a) 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<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date);
int count = await epInformationService.GetEPSignesCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date); int count = await epInformationService.GetEPSignesCount(new List<long?> { 1, 2 }, true, 1, 15, "", "", null, date);
@ -463,7 +466,7 @@ namespace EPAServeur.Tests.Services
{ {
DateTime date1 = new DateTime(a1, m1, j1); DateTime date1 = new DateTime(a1, m1, j1);
DateTime date2 = new DateTime(a2, m2, j2); DateTime date2 = new DateTime(a2, m2, j2);
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, "", "", date1, date2);
Assert.AreEqual(epInformationDTOs.Count(), count); Assert.AreEqual(epInformationDTOs.Count(), count);
@ -485,7 +488,7 @@ namespace EPAServeur.Tests.Services
[TestCase("d", 2)] [TestCase("d", 2)]
public async Task GetEpSignes_texte(string texte, int count) public async Task GetEpSignes_texte(string texte, int count)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignes(new List<long?> { 1, 2 }, true, 1, 15, texte, "", null, null);
Assert.AreEqual(count, epInformationDTOs.Count()); Assert.AreEqual(count, epInformationDTOs.Count());
foreach (EpInformationDTO ep in epInformationDTOs) foreach (EpInformationDTO ep in epInformationDTOs)
@ -508,7 +511,7 @@ namespace EPAServeur.Tests.Services
[TestCase("80220063-a5fa-472b-b610-2e350566df98", 1)] [TestCase("80220063-a5fa-472b-b610-2e350566df98", 1)]
public async Task GetEPCoursReferent(Guid idReferent, int count) public async Task GetEPCoursReferent(Guid idReferent, int count)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCoursReferent(idReferent, true, 1, 15, "", "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPEnCoursReferent(idReferent, true, 1, 15, "", "", null, null);
int epCount = await epInformationService.GetEPEnCoursReferentCount(idReferent, true, 1, 15, "", "", null, null); int epCount = await epInformationService.GetEPEnCoursReferentCount(idReferent, true, 1, 15, "", "", null, null);
Assert.AreEqual(epCount, count); Assert.AreEqual(epCount, count);
@ -531,7 +534,7 @@ namespace EPAServeur.Tests.Services
[TestCase("ea027734-ff0f-4308-8879-133a09fb3c46", 1)] [TestCase("ea027734-ff0f-4308-8879-133a09fb3c46", 1)]
public async Task GetEPEnSignesReferent(Guid idReferent, int count) public async Task GetEPEnSignesReferent(Guid idReferent, int count)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignesReferent(idReferent, true, 1, 15, "", "", null, null); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignesReferent(idReferent, true, 1, 15, "", "", null, null);
int epCount = await epInformationService.GetEPSignesReferentCount(idReferent, true, 1, 15, "", "", null, null); int epCount = await epInformationService.GetEPSignesReferentCount(idReferent, true, 1, 15, "", "", null, null);
Assert.AreEqual(epCount, count); Assert.AreEqual(epCount, count);
@ -553,7 +556,7 @@ namespace EPAServeur.Tests.Services
[TestCase("13fbe621-1bc9-4f04-afde-b54ca076e239", 3)] [TestCase("13fbe621-1bc9-4f04-afde-b54ca076e239", 3)]
public async Task GetEPSignesCollaborateur(Guid idCollaborateur, int count) public async Task GetEPSignesCollaborateur(Guid idCollaborateur, int count)
{ {
IEpInformationService epInformationService = new EpInformationService(context, collaborateurService); IEpInformationService epInformationService = new EpInformationService(context, collaborateurService, transformDTO);
IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignesCollaborateur(idCollaborateur); IEnumerable<EpInformationDTO> epInformationDTOs = await epInformationService.GetEPSignesCollaborateur(idCollaborateur);
Assert.AreEqual(count, epInformationDTOs.Count()); Assert.AreEqual(count, epInformationDTOs.Count());
foreach(EpInformationDTO ep in epInformationDTOs) foreach(EpInformationDTO ep in epInformationDTOs)
@ -574,7 +577,7 @@ namespace EPAServeur.Tests.Services
[TestCase("de98a866-736f-4295-a669-92a8694e2ee3", true)] [TestCase("de98a866-736f-4295-a669-92a8694e2ee3", true)]
public async Task GetEPEnCoursCollaborateur(Guid idCollaborateur, bool existe) 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); EpInformationDTO epInformationDTO = await epInformationService.GetProchainEPCollaborateur(idCollaborateur);
if(existe) if(existe)
{ {

@ -22,6 +22,7 @@ namespace EPAServeur.Tests.Services
private EpContext epContext; private EpContext epContext;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
#endregion #endregion
#region Setup #region Setup
@ -36,7 +37,8 @@ namespace EPAServeur.Tests.Services
epContext = new EpContext(optionBuider); epContext = new EpContext(optionBuider);
collaborateurApi = new CollaborateurApi(); collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, epContext); transformDTO = new TransformDTO();
collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO);
epContext.Database.EnsureDeleted(); epContext.Database.EnsureDeleted();
epContext.Database.EnsureCreated(); epContext.Database.EnsureCreated();
epContext.SaveChanges(); epContext.SaveChanges();
@ -59,7 +61,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormation() public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormation()
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
FormationDTO formationDTO = await formationService.GetFormationByIdAsync(3); FormationDTO formationDTO = await formationService.GetFormationByIdAsync(3);
@ -85,7 +87,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormationSansParticipation() public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormationSansParticipation()
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
long idFormation = 11; long idFormation = 11;
// Act // Act
@ -114,7 +116,7 @@ namespace EPAServeur.Tests.Services
public void GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long idFormation) public void GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long idFormation)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
AsyncTestDelegate throwException = () => formationService.GetFormationByIdAsync(idFormation); 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) 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 // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
List<int?> idStatuts; List<int?> idStatuts;
if (arrIdStatuts != null) if (arrIdStatuts != null)
@ -156,7 +158,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesFormations(int? numPage, int? parPAge) public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesFormations(int? numPage, int? parPAge)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, numPage, parPAge, null, null, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPAge)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
int? nbFormationDeuxiemePage; int? nbFormationDeuxiemePage;
switch (parPAge) switch (parPAge)
@ -204,7 +206,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleCroissant(bool? asc, string tri) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleCroissant(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleDecroissant(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutCroissant(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutDecroissant(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParNombreDeParticipantsCroissant(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParNombreDeParticipantsDecroissant(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineCroissante(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineDecroissante(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateCroissante(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateDecroissante(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationCroissante(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationDecroissante(bool? asc, string tri)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamUneDateDeDebut_RetourneDesFormationsAvecUneDateDeDebutSuperieur(DateTime dateDebut)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, null); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamUneDateDeFin_RetourneDesFormationsAvecUneDateDeFinInferieur(DateTime dateFin)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, null, dateFin); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutEtUneDateDeFin_RetourneDesFormationsAvecUneDateDeDebutSuperieurUneDateDeFinInferieur(DateTime dateDebut, DateTime dateFin)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin); IEnumerable<FormationDetailsDTO> 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) public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutSuperieurEtUneDateDeFinInferieur_RetourneZeroFormation(DateTime dateDebut, DateTime dateFin)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin); IEnumerable<FormationDetailsDTO> 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) 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 // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
List<int?> idStatuts; List<int?> idStatuts;
if (arrIdStatuts != null) 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) public async Task GetFormationsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDeFormations(long? idAgence, int[] arrIdStatuts, string texte, DateTime? dateDebut, DateTime? dateFin)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
List<int?> idStatuts; List<int?> idStatuts;
if (arrIdStatuts != null) 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) public async Task GetFormationsCountAsync_PasseDesParamsInvalides_RetourneZero(long? idAgence, int[] arrIdStatuts, string texte, DateTime? dateDebut, DateTime? dateFin)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
List<int?> idStatuts; List<int?> idStatuts;
if (arrIdStatuts != null) if (arrIdStatuts != null)
@ -524,7 +526,7 @@ namespace EPAServeur.Tests.Services
public async Task GetModesFormationAsync_RetourneTousLesModesDeFormation() public async Task GetModesFormationAsync_RetourneTousLesModesDeFormation()
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<ModeFormationDTO> modeFormationDTOs = await formationService.GetModesFormationAsync(); IEnumerable<ModeFormationDTO> modeFormationDTOs = await formationService.GetModesFormationAsync();
@ -542,7 +544,7 @@ namespace EPAServeur.Tests.Services
public async Task GetOriginesAsyncFormation_RetourneToutesLesOriginesDeFormation() public async Task GetOriginesAsyncFormation_RetourneToutesLesOriginesDeFormation()
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<OrigineFormationDTO> origineFormationDTOs = await formationService.GetOriginesFormationAsync(); IEnumerable<OrigineFormationDTO> origineFormationDTOs = await formationService.GetOriginesFormationAsync();
@ -560,7 +562,7 @@ namespace EPAServeur.Tests.Services
public async Task GetStatutsFormationAsyncFormation_RetourneTousLesStatutsDeFormation() public async Task GetStatutsFormationAsyncFormation_RetourneTousLesStatutsDeFormation()
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<StatutFormationDTO> statutFormationDTOs = await formationService.GetStatutsFormationAsync(); IEnumerable<StatutFormationDTO> statutFormationDTOs = await formationService.GetStatutsFormationAsync();
@ -578,7 +580,7 @@ namespace EPAServeur.Tests.Services
public async Task GetTypesFormationAsync_RetourneTousLesTypesDeFormation() public async Task GetTypesFormationAsync_RetourneTousLesTypesDeFormation()
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<TypeFormationDTO> typeFormationDTOs = await formationService.GetTypesFormationAsync(); IEnumerable<TypeFormationDTO> typeFormationDTOs = await formationService.GetTypesFormationAsync();
@ -623,7 +625,7 @@ namespace EPAServeur.Tests.Services
EstCertifiee = false EstCertifiee = false
}; };
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
FormationDTO formationAjoute = await formationService.AddFormationAsync(formation); FormationDTO formationAjoute = await formationService.AddFormationAsync(formation);
@ -652,7 +654,7 @@ namespace EPAServeur.Tests.Services
// Arrange // Arrange
FormationDTO formation = null; FormationDTO formation = null;
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation);
@ -701,7 +703,7 @@ namespace EPAServeur.Tests.Services
EstCertifiee = false EstCertifiee = false
}; };
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation);
@ -747,7 +749,7 @@ namespace EPAServeur.Tests.Services
EstCertifiee = false EstCertifiee = false
}; };
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation);
@ -773,7 +775,7 @@ namespace EPAServeur.Tests.Services
OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine)
.Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); .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); FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation);
@ -837,7 +839,7 @@ namespace EPAServeur.Tests.Services
OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine)
.Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); .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); FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation);
@ -876,7 +878,7 @@ namespace EPAServeur.Tests.Services
OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine)
.Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); .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); FormationDTO formation = await formationService.GetFormationByIdAsync(1);
@ -914,7 +916,7 @@ namespace EPAServeur.Tests.Services
OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine)
.Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); .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 FormationDTO formation = new FormationDTO
{ {
@ -950,7 +952,7 @@ namespace EPAServeur.Tests.Services
public async Task DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long idFormation) public async Task DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long idFormation)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
bool existFormation = true; bool existFormation = true;
// Act // Act
@ -967,7 +969,7 @@ namespace EPAServeur.Tests.Services
public void DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdInvalide_LeveUneFormationNotFoundException(long idFormation) public void DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdInvalide_LeveUneFormationNotFoundException(long idFormation)
{ {
// Arrange // Arrange
FormationService formationService = new FormationService(epContext, collaborateurService); FormationService formationService = new FormationService(epContext, collaborateurService, transformDTO);
// Act // Act
AsyncTestDelegate throwException = () => formationService.DeleteFormationByIdAsync(idFormation); AsyncTestDelegate throwException = () => formationService.DeleteFormationByIdAsync(idFormation);

@ -21,6 +21,7 @@ namespace EPAServeur.Tests.Services
private EpContext context; private EpContext context;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
private Guid? auteur1, auteur2, auteur3; private Guid? auteur1, auteur2, auteur3;
private Guid? collaborateur1, collaborateur2, collaborateur3; private Guid? collaborateur1, collaborateur2, collaborateur3;
private Guid? auteurNonExistant, collaborateurNonExistant, collaborateurParti, referentParti; private Guid? auteurNonExistant, collaborateurNonExistant, collaborateurParti, referentParti;
@ -51,7 +52,8 @@ namespace EPAServeur.Tests.Services
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
collaborateurApi = new CollaborateurApi(); 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"); auteur1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696");
@ -81,7 +83,7 @@ namespace EPAServeur.Tests.Services
CollaborateurDTO collaborateur2DTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur2); CollaborateurDTO collaborateur2DTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur2);
CollaborateurDTO collaborateur3DTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur3); 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; DateTime date = DateTime.Now;
DetailsNoteDTO noteAjoutee1, noteAjoutee2; DetailsNoteDTO noteAjoutee1, noteAjoutee2;
@ -203,7 +205,7 @@ namespace EPAServeur.Tests.Services
CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); 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; DateTime date = DateTime.Now;
DetailsNoteDTO noteAjoutee1 = new DetailsNoteDTO() DetailsNoteDTO noteAjoutee1 = new DetailsNoteDTO()
@ -226,7 +228,7 @@ namespace EPAServeur.Tests.Services
{ {
CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); 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; DateTime date = DateTime.Now;
DetailsNoteDTO note = new DetailsNoteDTO() DetailsNoteDTO note = new DetailsNoteDTO()
@ -249,7 +251,7 @@ namespace EPAServeur.Tests.Services
CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1);
collaborateurDTO.Id = collaborateurNonExistant; collaborateurDTO.Id = collaborateurNonExistant;
INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context, transformDTO);
DateTime date = DateTime.Now; DateTime date = DateTime.Now;
DetailsNoteDTO note = new DetailsNoteDTO() DetailsNoteDTO note = new DetailsNoteDTO()
@ -274,7 +276,7 @@ namespace EPAServeur.Tests.Services
CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1); CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateur1);
CollaborateurDTO collaborateurPartiDTO = await collaborateurService.GetCollaborateurByIdAsync(collaborateurParti); 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; DateTime date = DateTime.Now;
@ -317,7 +319,7 @@ namespace EPAServeur.Tests.Services
[TestCase(9)] [TestCase(9)]
public async Task GetNote_NoteNotNull(long id) 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); DetailsNoteDTO detailsNoteDTO = await noteService.GetNoteByIdAsync(id);
Assert.NotNull(detailsNoteDTO); Assert.NotNull(detailsNoteDTO);
@ -341,7 +343,7 @@ namespace EPAServeur.Tests.Services
[TestCase(100)] [TestCase(100)]
public void GetNote_NoteNotFoundException(long id) 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); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id);
Assert.ThrowsAsync(typeof(NoteNotFoundException), exception); Assert.ThrowsAsync(typeof(NoteNotFoundException), exception);
} }
@ -350,7 +352,7 @@ namespace EPAServeur.Tests.Services
[TestCase(7)] [TestCase(7)]
public void GetNote_ReferentNotFoundException(long id) 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); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id);
Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception);
} }
@ -359,7 +361,7 @@ namespace EPAServeur.Tests.Services
[TestCase(10)] [TestCase(10)]
public void GetNote_CollaborateurNotFoundException(long id) 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); AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id);
Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception);
} }
@ -375,7 +377,7 @@ namespace EPAServeur.Tests.Services
[TestCase(8)] [TestCase(8)]
public async Task SupprimerNote_Succes(long id) 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); await noteService.SupprimerNoteAsync(id);
Note note = await context.Note.FindAsync(id); Note note = await context.Note.FindAsync(id);
@ -393,7 +395,7 @@ namespace EPAServeur.Tests.Services
[TestCase(100)] [TestCase(100)]
public void SupprimerNote_NoteNotFoundException(long id) 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); AsyncTestDelegate exception = () => noteService.SupprimerNoteAsync(id);
Assert.ThrowsAsync(typeof(NoteNotFoundException), exception); Assert.ThrowsAsync(typeof(NoteNotFoundException), exception);
@ -410,7 +412,7 @@ namespace EPAServeur.Tests.Services
[TestCase(9)] [TestCase(9)]
public async Task UpdateNote_UpdateTitreEtTexte(long id) 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); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id);
note.Titre = "Titre à jour " + id; note.Titre = "Titre à jour " + id;
note.Texte= "Texte à jour " + id; note.Texte= "Texte à jour " + id;
@ -433,7 +435,7 @@ namespace EPAServeur.Tests.Services
[TestCase(9)] [TestCase(9)]
public async Task UpdateNote_UpdateTexte(long id) 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); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id);
note.Texte = "Texte à jour " + id; note.Texte = "Texte à jour " + id;
DetailsNoteDTO noteUpdate = await noteService.UpdateNoteAsync(id, note); DetailsNoteDTO noteUpdate = await noteService.UpdateNoteAsync(id, note);
@ -455,7 +457,7 @@ namespace EPAServeur.Tests.Services
[TestCase(9)] [TestCase(9)]
public async Task UpdateNote_UpdateTitre(long id) 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); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id);
note.Titre = "Titre à jour " + id; note.Titre = "Titre à jour " + id;
DetailsNoteDTO noteUpdate = await noteService.UpdateNoteAsync(id, note); DetailsNoteDTO noteUpdate = await noteService.UpdateNoteAsync(id, note);
@ -479,7 +481,7 @@ namespace EPAServeur.Tests.Services
[TestCase(9,7)] [TestCase(9,7)]
public async Task UpdateNote_NoteIdImcompatibleExceptionId(long id, long mauvaisId) 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); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id);
note.Titre = "Titre à jour " + id; note.Titre = "Titre à jour " + id;
note.Texte = "Texte à jour " + id; note.Texte = "Texte à jour " + id;
@ -493,7 +495,7 @@ namespace EPAServeur.Tests.Services
[TestCase(9)] [TestCase(9)]
public async Task UpdateNote_NoteIdImcompatibleExceptionDate(long id) 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); DetailsNoteDTO note = await noteService.GetNoteByIdAsync(id);
note.Titre = "Titre à jour " + id; note.Titre = "Titre à jour " + id;
note.Texte = "Texte à jour " + id; note.Texte = "Texte à jour " + id;

@ -23,6 +23,7 @@ namespace EPAServeur.Tests.Services
private EpContext epContext; private EpContext epContext;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService; private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
#endregion #endregion
#region Setup #region Setup
@ -37,7 +38,8 @@ namespace EPAServeur.Tests.Services
epContext = new EpContext(optionBuider); epContext = new EpContext(optionBuider);
collaborateurApi = new CollaborateurApi(); collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, epContext); transformDTO = new TransformDTO();
collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO);
epContext.Database.EnsureDeleted(); epContext.Database.EnsureDeleted();
epContext.Database.EnsureCreated(); epContext.Database.EnsureCreated();
epContext.SaveChanges(); epContext.SaveChanges();
@ -61,7 +63,7 @@ namespace EPAServeur.Tests.Services
public async Task GetEvaluationCollaborateurAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneEvaluation() public async Task GetEvaluationCollaborateurAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneEvaluation()
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
// Act // Act
EvaluationDTO evaluationDTO = await participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation); EvaluationDTO evaluationDTO = await participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation);
@ -79,7 +81,7 @@ namespace EPAServeur.Tests.Services
public void GetEvaluationCollaborateurAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneParticipationFormationNotFoundException(long idParticipationFormation) public void GetEvaluationCollaborateurAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneParticipationFormationNotFoundException(long idParticipationFormation)
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
// Act // Act
AsyncTestDelegate throwException = () => participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation); AsyncTestDelegate throwException = () => participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation);
@ -97,7 +99,7 @@ namespace EPAServeur.Tests.Services
public async Task GetParticipationByCollaborateurAsync_PasseDesParamsValides_RetourneDesParticipationsFormations(Guid idCollaborateur) public async Task GetParticipationByCollaborateurAsync_PasseDesParamsValides_RetourneDesParticipationsFormations(Guid idCollaborateur)
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<ParticipationFormationDTO> participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); IEnumerable<ParticipationFormationDTO> participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur);
@ -111,7 +113,7 @@ namespace EPAServeur.Tests.Services
public async Task GetParticipationByCollaborateurAsync_PasseDesParamsInvalides_RetourneZeroParticipation(Guid idCollaborateur) public async Task GetParticipationByCollaborateurAsync_PasseDesParamsInvalides_RetourneZeroParticipation(Guid idCollaborateur)
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
// Act // Act
IEnumerable<ParticipationFormationDTO> participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); IEnumerable<ParticipationFormationDTO> participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur);
@ -128,7 +130,7 @@ namespace EPAServeur.Tests.Services
public async Task EvaluerFormationAsync_EvaluerUneFormationValide_EvaluationRealiseeAvecSucces() public async Task EvaluerFormationAsync_EvaluerUneFormationValide_EvaluationRealiseeAvecSucces()
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation)
@ -198,7 +200,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation)
@ -259,7 +261,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
bool? estCertifiee = null; bool? estCertifiee = null;
@ -321,7 +323,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
DateTime? dateDebut = null; DateTime? dateDebut = null;
@ -383,7 +385,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation)
@ -411,7 +413,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation)
@ -439,7 +441,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation)
@ -498,7 +500,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation)
@ -558,7 +560,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = null; EvaluationDTO evaluationDTO = null;
@ -574,7 +576,7 @@ namespace EPAServeur.Tests.Services
public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecte_LeveUneParticipationFormationIncompatibleIdException(long idParticipationFormationIncompatible) public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecte_LeveUneParticipationFormationIncompatibleIdException(long idParticipationFormationIncompatible)
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) 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) public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecteAuNiveauDuDTO_LeveUneParticipationFormationIncompatibleIdException(long? idParticipationFormationIncompatible)
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation)
@ -695,7 +697,7 @@ namespace EPAServeur.Tests.Services
{ {
// Arrange // Arrange
ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO);
long idParticipationFormation = 5; long idParticipationFormation = 5;
long idParticipationFormationInexistant = 0; long idParticipationFormationInexistant = 0;

@ -22,6 +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 ITransformDTO transformDTO;
private Guid? referent1; private Guid? referent1;
private Guid? collaborateur1, collaborateur2, collaborateur3; private Guid? collaborateur1, collaborateur2, collaborateur3;
private Guid? collaborateurNonExistant, collaborateurParti; private Guid? collaborateurNonExistant, collaborateurParti;
@ -48,7 +49,8 @@ namespace EPAServeur.Tests.Services
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
collaborateurApi = new CollaborateurApi(); 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"); referent1 = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696");

@ -1,4 +1,6 @@
using EPAServeur.Context; using EPAServeur.Context;
using EPAServeur.Models.EP;
using EPAServeur.Models.Formation;
using IO.Swagger.DTO; using IO.Swagger.DTO;
using IO.Swagger.ModelCollaborateur; using IO.Swagger.ModelCollaborateur;
using System; using System;
@ -19,7 +21,12 @@ namespace EPAServeur.IServices
Task<int> GetCollaborateursCountByReferentAsync(Guid? idReferent, string texte); Task<int> GetCollaborateursCountByReferentAsync(Guid? idReferent, string texte);
Task<IEnumerable<CollaborateurDTO>> GetReferentsPrecedentsEPAsync(Guid? idCollaborateur); Task<IEnumerable<CollaborateurDTO>> GetReferentsPrecedentsEPAsync(Guid? idCollaborateur);
Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(List<Guid?> guids); Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(List<Guid?> guids);
Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(List<ParticipationFormation> participationsFormation);
Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(IEnumerable<ParticipationFormation> participationsFormation);
Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(Engagement engagement);
Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(IEnumerable<Engagement> engagements);
Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(IEnumerable<Ep> eps);
Task<CollaborateurDTO> GetCollaborateurDTOAsync(Collaborateur collaborateur, bool chercherReferent);
} }

@ -0,0 +1,59 @@
using EPAServeur.Models.EP;
using EPAServeur.Models.Formation;
using EPAServeur.Models.Notes;
using EPAServeur.Models.SaisieChamp;
using IO.Swagger.DTO;
using IO.Swagger.ModelCollaborateur;
using System.Collections.Generic;
namespace EPAServeur.IServices
{
public interface ITransformDTO
{
// Collaborateur
AgenceDTO GetAgenceDTO(Agence agence);
BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit);
CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs);
// DemandeDelegation
DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable<CollaborateurDTO> collaborateurs);
// Engagement
EngagementDTO GetEngagementDTO(Engagement engagement, IEnumerable<CollaborateurDTO> collaborateurDTOs);
Engagement SetReponseEngagement(Engagement engagement, EngagementDTO engagementDTO);
// EpInformation
EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurs);
EpInformationDTO EpToEpDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs);
// Formation
FormationDTO GetFormationDTOWhitoutParticipationFormation(Formation formation);
FormationDTO GetFormationDTO(Formation formation, IEnumerable<CollaborateurDTO> collaborateurDTOs);
FormationDetailsDTO GetFormationDetailsDTO(Formation formation);
OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation);
StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation);
ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation);
TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation);
Formation SetFormation(Formation formation, FormationDTO formationDTO);
OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO);
StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO);
ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO);
TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO);
// Note
AffichageNoteDTO NoteToAffichageDTO(Note note, IEnumerable<Collaborateur> collaborateurs);
DetailsNoteDTO NoteToDetailSDTO(Note note, CollaborateurDTO collaborateur);
Note DetailsNoteDTOToNouvelleNote(DetailsNoteDTO detailsNoteDTO);
// ParticipationFormation
List<ParticipationFormationDTO> GetParticipationsFormationDTO(List<ParticipationFormation> participationsFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs);
ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs);
EvaluationDTO GetEvaluationDTO(ParticipationFormation participationFormation);
SaisieDTO GetSaisieDTO(Saisie saisie);
ChampDTO GetChampDTO(Champ champ);
Saisie GetSaisie(SaisieDTO saisieDTO);
Champ GetChamp(ChampDTO champDTO);
}
}

@ -2,6 +2,7 @@
using EPAServeur.Exceptions; using EPAServeur.Exceptions;
using EPAServeur.IServices; using EPAServeur.IServices;
using EPAServeur.Models.EP; using EPAServeur.Models.EP;
using EPAServeur.Models.Formation;
using IO.Swagger.ApiCollaborateur; using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO; using IO.Swagger.DTO;
using IO.Swagger.ModelCollaborateur; using IO.Swagger.ModelCollaborateur;
@ -26,6 +27,11 @@ namespace EPAServeur.Services
/// </summary> /// </summary>
private readonly ICollaborateurApi collaborateurApi; private readonly ICollaborateurApi collaborateurApi;
/// <summary>
/// Accès au service permettant de transformer un modèle en dto
/// </summary>
private readonly ITransformDTO transformDTO;
/// <summary> /// <summary>
/// Nombre d'éléments min à afficher par page /// Nombre d'éléments min à afficher par page
/// </summary> /// </summary>
@ -49,10 +55,11 @@ namespace EPAServeur.Services
#region Constructeurs #region Constructeurs
public CollaborateurService(ICollaborateurApi _collaborateurApi, EpContext _contexte) public CollaborateurService(ICollaborateurApi _collaborateurApi, EpContext _contexte, ITransformDTO _transformDTO)
{ {
collaborateurApi = _collaborateurApi; collaborateurApi = _collaborateurApi;
context = _contexte; context = _contexte;
transformDTO = _transformDTO;
} }
#endregion #endregion
@ -259,6 +266,125 @@ namespace EPAServeur.Services
return collaborateursDTO; return collaborateursDTO;
} }
/// <summary>
/// Transformer un collaborateur en collaborateurDTO de manière asynchrone.
/// </summary>
/// <param name="collaborateur">Collaborateur à transformer en collaborateurDTO</param>
/// <param name="chercherReferent">Indiquer si le référent du collaborateur doit être récupéré ou non</param>
/// <returns>Renvoie la transformation DTO du collaborateur</returns>
public async Task<CollaborateurDTO> GetCollaborateurDTOAsync(Collaborateur collaborateur, bool chercherReferent)
{
CollaborateurDTO collaborateurDTO = new CollaborateurDTO()
{
Id = collaborateur.Id,
Prenom = collaborateur.Prenom,
Nom = collaborateur.Nom,
MailApside = collaborateur.MailApside,
DateArrivee = collaborateur.DateArrivee,
};
collaborateurDTO.BusinessUnit = transformDTO.GetBusinessUnitDTO(collaborateur.BusinessUnit);
//Si le référent du collaborateur doit être récupérer en même temps
if (chercherReferent)
collaborateurDTO.Referent = await GetReferentAsync(collaborateurDTO);
return collaborateurDTO;
}
/// <summary>
/// Récupérer une liste de CollaborateurDTO contenant les collaborateurs et les référents.
/// </summary>
/// <param name="participationsFormation"></param>
/// <returns></returns>
public async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(List<ParticipationFormation> participationsFormation)
{
if (participationsFormation == null || participationsFormation.Count == 0)
return null;
List<Guid?> guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList();
return await GetCollaborateurDTOsAsync(guids);
}
/// <summary>
/// Récupérer une liste de CollaborateurDTO contenant les collaborateurs et les référents.
/// </summary>
/// <param name="participationsFormation"></param>
/// <returns></returns>
public async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(IEnumerable<ParticipationFormation> participationsFormation)
{
if (participationsFormation == null || !participationsFormation.Any())
return null;
List<Guid?> guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList();
return await GetCollaborateurDTOsAsync(guids);
}
/// <summary>
/// Récupérer le collaborateur et le référent qui sont présent dans l'EP qui est lié à l'engagement.
/// </summary>
/// <param name="engagement"></param>
/// <returns></returns>
public async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(Engagement engagement)
{
if (engagement == null)
return null;
List<Guid?> guids = new List<Guid?>();
guids.Add((Guid?)engagement.Ep.IdCollaborateur);
guids.Add(engagement.Ep.IdReferent);
return await GetCollaborateurDTOsAsync(guids);
}
/// <summary>
/// Récupérer les collaborateurs et les référents qui sont présent dans les EP qui sont liés aux engagements.
/// </summary>
/// <param name="engagements"></param>
/// <returns></returns>
public async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(IEnumerable<Engagement> engagements)
{
if (engagements == null || !engagements.Any())
return null;
List<Guid?> guids = engagements.SelectMany(engagement => new[] { (Guid?)engagement.Ep.IdCollaborateur, engagement.Ep.IdReferent }).ToList();
return await GetCollaborateurDTOsAsync(guids);
}
/// <summary>
/// Récupérer le collaborateur et le référent qui sont présent dans les EP.
/// </summary>
/// <param name="eps"></param>
/// <returns></returns>
public async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOsAsync(IEnumerable<Ep> eps)
{
if (eps == null || !eps.Any())
return null;
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList();
return await GetCollaborateurDTOsAsync(guids);
}
/// <summary>
/// Récupérer le référent EP d'un collaborateur de manière asynchrone s'il existe.
/// </summary>
/// <param name="collaborateur">Le collaborateur dont on cherche le référent EP</param>
/// <returns>Le référent EP du collaborateur</returns>
public async Task<CollaborateurDTO> GetReferentAsync(CollaborateurDTO collaborateur)
{
ReferentEP referentEP = await context.ReferentEP.FindAsync(collaborateur.Id);
//vérifier que le collaorateur a un référent EP
if (referentEP == null || referentEP.IdReferent == null || !referentEP.IdReferent.HasValue || referentEP.IdReferent.Value == null)
return null;
Collaborateur referent = await collaborateurApi.ChercherCollabIdAsync(referentEP.IdReferent);
if (referent == null)
return null;
return await GetCollaborateurDTOAsync(referent, false);
}
#endregion #endregion
@ -337,93 +463,5 @@ namespace EPAServeur.Services
} }
#endregion #endregion
#region DTO To Object
/// <summary>
/// Transformer une agence en agenceDTO
/// </summary>
/// <param name="agence">agence à transformer en agenceDTO</param>
/// <returns>Retourne la transformation DTO de l'agence</returns>
private AgenceDTO GetAgenceDTO(Agence agence)
{
if (agence == null)
return null;
AgenceDTO agenceDTO = new AgenceDTO()
{
Id = agence.Id,
Nom = agence.Nom,
Bu = new List<BusinessUnitDTO>()
};
agenceDTO.Bu = agence.Bus.Select(bu => new BusinessUnitDTO()
{
Id = bu.Id,
Nom = bu.Nom
}).ToList();
return agenceDTO;
}
/// <summary>
/// Transforme une businessUnit en businessUnitDTO
/// </summary>
/// <param name="businessUnit">businessUnit à transformer en businessUnitDTO</param>
/// <returns>Retourne la transformation DTO de la businessUnit</returns>
private BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit)
{
if (businessUnit == null)
return null;
BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO()
{
Id = businessUnit.Id,
Nom = businessUnit.Nom,
Agence = GetAgenceDTO(businessUnit.Agence)
};
return businessUnitDTO;
}
/// <summary>
/// Transforme un collaborateur en collaborateurDTO de manière asynchrone
/// </summary>
/// <param name="collaborateur">collaborateur à transformer en collaborateurDTO</param>
/// <param name="chercherReferent">Indiquer si le référent du collaborateur doit être récupéré ou non</param>
/// <returns>Renvoie la transformation DTO du collaborateur</returns>
private async Task<CollaborateurDTO> GetCollaborateurDTOAsync(Collaborateur collaborateur, bool chercherReferent)
{
CollaborateurDTO collaborateurDTO = new CollaborateurDTO()
{
Id = collaborateur.Id,
Prenom = collaborateur.Prenom,
Nom = collaborateur.Nom,
MailApside = collaborateur.MailApside,
DateArrivee = collaborateur.DateArrivee,
};
collaborateurDTO.BusinessUnit = GetBusinessUnitDTO(collaborateur.BusinessUnit);
//Si le référent du collaborateur doit être récupérer en même temps
if (chercherReferent)
collaborateurDTO.Referent = await GetReferentAsync(collaborateurDTO);
return collaborateurDTO;
}
/// <summary>
/// Récupérer le référent EP d'un collaborateur de manière asynchrone si il existe
/// </summary>
/// <param name="collaborateur">Le collaborateur dont on cherche le référent EP</param>
/// <returns>Le référent EP du collaborateur</returns>
private async Task<CollaborateurDTO> GetReferentAsync(CollaborateurDTO collaborateur)
{
ReferentEP referentEP = await context.ReferentEP.FindAsync(collaborateur.Id);
//vérifier que le collaorateur a un référent EP
if (referentEP == null || referentEP.IdReferent == null || !referentEP.IdReferent.HasValue || referentEP.IdReferent.Value == null)
return null;
Collaborateur referent = await collaborateurApi.ChercherCollabIdAsync(referentEP.IdReferent);
if (referent == null)
return null;
return await GetCollaborateurDTOAsync(referent, false);
}
#endregion
} }
} }

@ -17,16 +17,29 @@ namespace EPAServeur.Services
public class DemandeDelegationService : IDemandeDelegationService public class DemandeDelegationService : IDemandeDelegationService
{ {
#region variables #region variables
/// <summary>
/// Accès et gestion de la base de données
/// </summary>
private readonly EpContext context; private readonly EpContext context;
/// <summary>
/// Accès et service collaborateur
/// </summary>
private readonly ICollaborateurService collaborateurService; private readonly ICollaborateurService collaborateurService;
/// <summary>
/// Accès au service permettant de transformer un modèle en dto
/// </summary>
private readonly ITransformDTO transformDTO;
#endregion #endregion
#region constructeur #region constructeur
public DemandeDelegationService(ICollaborateurService _collaborateurService, EpContext _context) public DemandeDelegationService(ICollaborateurService _collaborateurService, EpContext _context, ITransformDTO _transformDTO)
{ {
context = _context; context = _context;
collaborateurService = _collaborateurService; collaborateurService = _collaborateurService;
transformDTO = _transformDTO;
} }
#endregion #endregion
@ -46,7 +59,7 @@ namespace EPAServeur.Services
throw new ReferentNotFoundException(); throw new ReferentNotFoundException();
} }
return demandesDelegation.Select(d => GetDemandeDelegationDTO(d, referent, collaborateursDTO)); return demandesDelegation.Select(d => transformDTO.GetDemandeDelegationDTO(d, referent, collaborateursDTO));
} }
@ -102,36 +115,6 @@ namespace EPAServeur.Services
return demandeDelegationDTO; return demandeDelegationDTO;
} }
private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurs)
{
return new EpInformationDTO()
{
Id = ep.IdEP,
Collaborateur = collaborateurs.FirstOrDefault(c => c.Id.Equals(ep.IdCollaborateur)),
Referent = collaborateurs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)),
DatePrevisionnelle = ep.DatePrevisionnelle,
DateDisponibilite = ep.DateDisponibilite,
Statut = ep.Statut,
Type = ep.TypeEP,
Obligatoire = ep.Obligatoire,
};
}
private DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable<CollaborateurDTO> collaborateurs)
{
return new DemandeDelegationDTO()
{
Id = demande.IdDemandeDelegation,
DateDemande = demande.DateDemande,
EtatDemande = demande.EtatDemande,
Referent = referent,
RaisonDemande = demande.RaisonDemande,
Ep = GetEpInformationDTO(demande.Ep, collaborateurs)
};
}
#endregion #endregion

@ -27,6 +27,11 @@ namespace EPAServeur.Services
/// </summary> /// </summary>
private readonly ICollaborateurService collaborateurService; private readonly ICollaborateurService collaborateurService;
/// <summary>
/// Accès au service permettant de transformer un modèle en dto
/// </summary>
private readonly ITransformDTO transformDTO;
/// <summary> /// <summary>
/// Nombre d'éléments min à afficher par page /// Nombre d'éléments min à afficher par page
/// </summary> /// </summary>
@ -60,10 +65,11 @@ namespace EPAServeur.Services
/// Constructeur de la classe EngagementService /// Constructeur de la classe EngagementService
/// </summary> /// </summary>
/// <param name="_epContext"></param> /// <param name="_epContext"></param>
public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService) public EngagementService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO)
{ {
epContext = _epContext; epContext = _epContext;
collaborateurService = _collaborateurService; collaborateurService = _collaborateurService;
transformDTO = _transformDTO;
} }
#endregion #endregion
@ -96,9 +102,9 @@ namespace EPAServeur.Services
engagements = await query.ToListAsync(); engagements = await query.ToListAsync();
collaborateurDTOs = await GetCollaborateurDTOs(engagements); collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagements);
engagementDTOs = engagements.Select(engagement => GetEngagementDTO(engagement, collaborateurDTOs)); engagementDTOs = engagements.Select(engagement => transformDTO.GetEngagementDTO(engagement, collaborateurDTOs));
engagementDTOs = CollaborateurFilter(engagementDTOs, texte); engagementDTOs = CollaborateurFilter(engagementDTOs, texte);
return engagementDTOs; return engagementDTOs;
@ -118,9 +124,9 @@ namespace EPAServeur.Services
engagements = await query.ToListAsync(); engagements = await query.ToListAsync();
collaborateurDTOs = await GetCollaborateurDTOs(engagements); collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagements);
engagementDTOs = engagements.Select(engagement => GetEngagementDTO(engagement, collaborateurDTOs)); engagementDTOs = engagements.Select(engagement => transformDTO.GetEngagementDTO(engagement, collaborateurDTOs));
engagementDTOs = CollaborateurFilter(engagementDTOs, texte); engagementDTOs = CollaborateurFilter(engagementDTOs, texte);
count = engagementDTOs.Count(); count = engagementDTOs.Count();
@ -149,13 +155,13 @@ namespace EPAServeur.Services
if (engagement == null) if (engagement == null)
throw new EngagementNotFoundException(); throw new EngagementNotFoundException();
collaborateurDTOs = await GetCollaborateurDTOs(engagement); collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(engagement);
engagement = SetReponseEngagement(engagement, engagementDTO); engagement = transformDTO.SetReponseEngagement(engagement, engagementDTO);
await epContext.SaveChangesAsync(); await epContext.SaveChangesAsync();
return GetEngagementDTO(engagement, collaborateurDTOs); return transformDTO.GetEngagementDTO(engagement, collaborateurDTOs);
} }
@ -323,134 +329,6 @@ namespace EPAServeur.Services
return query.Skip(skip).Take(take); return query.Skip(skip).Take(take);
} }
#region Object to DTO
/// <summary>
/// Récupère un objet EngagementDTO en fonction d'un objet Engagement et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="engagement"></param>
/// <returns></returns>
private EngagementDTO GetEngagementDTO(Engagement engagement, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (engagement == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
EngagementDTO engagementDTO = new EngagementDTO()
{
Id = engagement.IdEngagement,
Action = engagement.Action,
DateLimite = engagement.DateLimite,
Dispositif = engagement.Dispositif,
Modalite = engagement.Modalite,
RaisonNonRealisable = engagement.RaisonNonRealisable,
EtatEngagement = engagement.EtatEngagement,
Ep = GetEpInformationDTO(engagement.Ep, collaborateurDTOs)
};
return engagementDTO;
}
/// <summary>
/// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null si l'engagement est null.
/// </summary>
/// <param name="typeFormation"></param>
/// <returns></returns>
private async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOs(Engagement engagement)
{
if (engagement == null)
return null;
List<Guid?> guids = new List<Guid?>();
guids.Add((Guid?)engagement.Ep.IdCollaborateur);
guids.Add(engagement.Ep.IdReferent);
return await collaborateurService.GetCollaborateurDTOsAsync(guids); ;
}
/// <summary>
/// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucun engagement.
/// </summary>
/// <param name="typeFormation"></param>
/// <returns></returns>
private async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOs(IEnumerable<Engagement> engagements)
{
if (engagements == null || !engagements.Any())
return null;
List<Guid?> guids = engagements.SelectMany(engagement => new[] { (Guid?)engagement.Ep.IdCollaborateur, engagement.Ep.IdReferent }).ToList();
return await collaborateurService.GetCollaborateurDTOsAsync(guids);
}
/// <summary>
/// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="ep"></param>
/// <returns></returns>
private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
CollaborateurDTO collaborateur;
CollaborateurDTO referent;
if (ep == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
collaborateur = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur);
referent = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdReferent);
EpInformationDTO epInformationDTO = new EpInformationDTO()
{
Id = ep.IdEP,
Type = ep.TypeEP,
Statut = ep.Statut,
DateDisponibilite = ep.DateDisponibilite,
DatePrevisionnelle = ep.DatePrevisionnelle,
Obligatoire = ep.Obligatoire,
Collaborateur = collaborateur,
Referent = referent,
};
return epInformationDTO;
}
#endregion
#region DTO to Object
/// <summary>
/// Modifie la réponse d'un objet Engagement en fonction d'un objet EngagementDTO
/// </summary>
/// <param name="engagement"></param>
/// <param name="engagementDTO"></param>
/// <returns></returns>
private Engagement SetReponseEngagement(Engagement engagement, EngagementDTO engagementDTO)
{
if (engagement == null || engagementDTO == null)
return null;
engagement.EtatEngagement = engagementDTO.EtatEngagement;
switch (engagement.EtatEngagement)
{
case EtatEngagement.NonRealisable:
engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable;
break;
case EtatEngagement.DateLimitePassee:
engagement.RaisonNonRealisable = "La date limite pour respecter l'engagement est passée.";
break;
default:
engagement.RaisonNonRealisable = null;
break;
}
return engagement;
}
#endregion
#endregion #endregion
} }

@ -13,18 +13,43 @@ namespace EPAServeur.Services
public class EpInformationService : IEpInformationService public class EpInformationService : IEpInformationService
{ {
#region Variables #region Variables
private EpContext context; /// <summary>
private ICollaborateurService collaborateurService; /// Accès et gestion de la base de données
private int? minParPage = 5; /// </summary>
private int? maxParPage = 100; private readonly EpContext context;
private int? defaultParPage = 15;
/// <summary>
/// Accès et service collaborateur
/// </summary>
private readonly ICollaborateurService collaborateurService;
/// <summary>
/// Accès au service permettant de transformer un modèle en dto
/// </summary>
private readonly ITransformDTO transformDTO;
/// <summary>
/// Nombre d'éléments min à afficher par page
/// </summary>
private readonly int minParPage = 5;
/// <summary>
/// Nom d'éléments max à affichar par page
/// </summary>
private readonly int maxParPage = 100;
/// <summary>
/// Nombre d'éléments à afficher par défaut par page
/// </summary>
private readonly int defaultParPage = 15;
#endregion #endregion
#region constructeur #region constructeur
public EpInformationService(EpContext context, ICollaborateurService collaborateurService) public EpInformationService(EpContext context, ICollaborateurService collaborateurService, ITransformDTO _transformDTO)
{ {
this.context = context; this.context = context;
this.collaborateurService = collaborateurService; this.collaborateurService = collaborateurService;
this.transformDTO = _transformDTO;
} }
#endregion #endregion
@ -105,7 +130,7 @@ namespace EPAServeur.Services
if (ep == null) if (ep == null)
return null; return null;
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(new List<Guid?>() { ep.IdReferent, ep.IdCollaborateur }); IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(new List<Guid?>() { ep.IdReferent, ep.IdCollaborateur });
return EpToEpDTO(ep, collaborateurDTOs); return transformDTO.EpToEpDTO(ep, collaborateurDTOs);
} }
#endregion #endregion
@ -116,8 +141,8 @@ namespace EPAServeur.Services
{ {
eps = TriDate(eps, dateDebut, dateFin); eps = TriDate(eps, dateDebut, dateFin);
IEnumerable<CollaborateurDTO> collaborateurDTOs = await GetCollaborateurDTOs(eps); IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(eps);
IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => transformDTO.EpToEpDTO(ep, collaborateurDTOs));
if (!string.IsNullOrEmpty(texte)) if (!string.IsNullOrEmpty(texte))
epDTOs = epDTOs.Where(e => TriTexte(e, texte)); epDTOs = epDTOs.Where(e => TriTexte(e, texte));
@ -135,8 +160,8 @@ namespace EPAServeur.Services
eps = TriDate(eps, dateDebut, dateFin); eps = TriDate(eps, dateDebut, dateFin);
IEnumerable<CollaborateurDTO> collaborateurDTOs = await GetCollaborateurDTOs(eps); IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(eps);
IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => EpToEpDTO(ep, collaborateurDTOs)); IEnumerable<EpInformationDTO> epDTOs = eps.Select(ep => transformDTO.EpToEpDTO(ep, collaborateurDTOs));
if(!string.IsNullOrEmpty(texte)) if(!string.IsNullOrEmpty(texte))
epDTOs = epDTOs.Where(e => TriTexte(e, texte)); epDTOs = epDTOs.Where(e => TriTexte(e, texte));
@ -154,22 +179,6 @@ namespace EPAServeur.Services
return eps; return eps;
} }
private EpInformationDTO EpToEpDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
return new EpInformationDTO()
{
Id = ep.IdEP,
Collaborateur = collaborateurDTOs.Where(c => c.Id.Equals(ep.IdCollaborateur)).FirstOrDefault(),
DateDisponibilite = ep.DateDisponibilite,
DatePrevisionnelle = ep.DatePrevisionnelle,
Obligatoire = ep.Obligatoire,
Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)),
Statut = ep.Statut,
Type = ep.TypeEP
};
}
private IEnumerable<EpInformationDTO> TriColonne(IEnumerable<EpInformationDTO> epDTOs, string tri) private IEnumerable<EpInformationDTO> TriColonne(IEnumerable<EpInformationDTO> epDTOs, string tri)
{ {
switch (tri) switch (tri)
@ -223,12 +232,6 @@ namespace EPAServeur.Services
return (epDTOs.Collaborateur.Nom + " " + epDTOs.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (epDTOs.Collaborateur.Prenom + " " + epDTOs.Collaborateur.Nom).ToLower().Contains(texte.ToLower()); return (epDTOs.Collaborateur.Nom + " " + epDTOs.Collaborateur.Prenom).ToLower().Contains(texte.ToLower()) || (epDTOs.Collaborateur.Prenom + " " + epDTOs.Collaborateur.Nom).ToLower().Contains(texte.ToLower());
} }
private async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOs(IEnumerable<Ep> eps)
{
List<Guid?> guids = eps.SelectMany(ep => new Guid?[] { ep.IdReferent, ep.IdCollaborateur }).Distinct().ToList();
return await collaborateurService.GetCollaborateurDTOsAsync(guids);
}
#endregion #endregion
} }
} }

@ -26,6 +26,11 @@ namespace EPAServeur.Services
/// </summary> /// </summary>
private readonly ICollaborateurService collaborateurService; private readonly ICollaborateurService collaborateurService;
/// <summary>
/// Accès au service permettant de transformer un modèle en dto
/// </summary>
private readonly ITransformDTO transformDTO;
/// <summary> /// <summary>
/// Nombre d'éléments min à afficher par page /// Nombre d'éléments min à afficher par page
/// </summary> /// </summary>
@ -59,10 +64,11 @@ namespace EPAServeur.Services
/// Constructeur de la classe FormationService /// Constructeur de la classe FormationService
/// </summary> /// </summary>
/// <param name="_epContext"></param> /// <param name="_epContext"></param>
public FormationService(EpContext _epContext, ICollaborateurService _collaborateurService) public FormationService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO)
{ {
epContext = _epContext; epContext = _epContext;
collaborateurService = _collaborateurService; collaborateurService = _collaborateurService;
transformDTO = _transformDTO;
} }
#endregion #endregion
@ -91,12 +97,12 @@ namespace EPAServeur.Services
if (formation.ParticipationsFormation.Count > 0) if (formation.ParticipationsFormation.Count > 0)
{ {
IEnumerable<CollaborateurDTO> collaborateurDTOs = await GetCollaborateurDTOs(formation.ParticipationsFormation); IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(formation.ParticipationsFormation);
return GetFormationDTO(formation, collaborateurDTOs); return transformDTO.GetFormationDTO(formation, collaborateurDTOs);
} }
else else
{ {
return GetFormationDTO(formation); return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation);
} }
} }
@ -137,7 +143,7 @@ namespace EPAServeur.Services
formations = await query.ToListAsync(); formations = await query.ToListAsync();
formationDTOs = formations.Select(formation => GetFormationDetailsDTO(formation)); formationDTOs = formations.Select(formation => transformDTO.GetFormationDetailsDTO(formation));
return formationDTOs; return formationDTOs;
} }
@ -187,7 +193,7 @@ namespace EPAServeur.Services
modeFormations = await epContext.ModeFormation.ToListAsync(); modeFormations = await epContext.ModeFormation.ToListAsync();
modeFormationDTOs = modeFormations.Select(modeFormation => GetModeFormationDTO(modeFormation)); modeFormationDTOs = modeFormations.Select(modeFormation => transformDTO.GetModeFormationDTO(modeFormation));
return modeFormationDTOs; return modeFormationDTOs;
} }
@ -203,7 +209,7 @@ namespace EPAServeur.Services
origineFormations = await epContext.OrigineFormation.ToListAsync(); origineFormations = await epContext.OrigineFormation.ToListAsync();
origineFormationDTOs = origineFormations.Select(origineFormation => GetOrigineFormationDTO(origineFormation)); origineFormationDTOs = origineFormations.Select(origineFormation => transformDTO.GetOrigineFormationDTO(origineFormation));
return origineFormationDTOs; return origineFormationDTOs;
} }
@ -219,7 +225,7 @@ namespace EPAServeur.Services
statutFormations = await epContext.StatutFormation.ToListAsync(); statutFormations = await epContext.StatutFormation.ToListAsync();
statutFormationDTOs = statutFormations.Select(statutFormation => GetStatutFormationDTO(statutFormation)); statutFormationDTOs = statutFormations.Select(statutFormation => transformDTO.GetStatutFormationDTO(statutFormation));
return statutFormationDTOs; return statutFormationDTOs;
} }
@ -235,7 +241,7 @@ namespace EPAServeur.Services
typeFormations = await epContext.TypeFormation.ToListAsync(); typeFormations = await epContext.TypeFormation.ToListAsync();
typeFormationDTOs = typeFormations.Select(typeFormation => GetTypeFormationDTO(typeFormation)); typeFormationDTOs = typeFormations.Select(typeFormation => transformDTO.GetTypeFormationDTO(typeFormation));
return typeFormationDTOs; return typeFormationDTOs;
} }
@ -250,7 +256,7 @@ namespace EPAServeur.Services
IsFormationValide(formationDTO); IsFormationValide(formationDTO);
Formation formation = new Formation(); Formation formation = new Formation();
formation = SetFormation(formation, formationDTO); formation = transformDTO.SetFormation(formation, formationDTO);
epContext.StatutFormation.Attach(formation.Statut); epContext.StatutFormation.Attach(formation.Statut);
epContext.OrigineFormation.Attach(formation.Origine); epContext.OrigineFormation.Attach(formation.Origine);
@ -260,7 +266,7 @@ namespace EPAServeur.Services
await epContext.SaveChangesAsync(); await epContext.SaveChangesAsync();
return GetFormationDTO(formation); return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation);
} }
/// <summary> /// <summary>
@ -289,10 +295,10 @@ namespace EPAServeur.Services
throw new FormationNotFoundException(string.Format("Aucune formation trouvée avec l'id suivant: {0}.", idFormation)); throw new FormationNotFoundException(string.Format("Aucune formation trouvée avec l'id suivant: {0}.", idFormation));
formation = SetFormation(formation, formationDTO); formation = transformDTO.SetFormation(formation, formationDTO);
await epContext.SaveChangesAsync(); await epContext.SaveChangesAsync();
return GetFormationDTO(formation); return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation);
} }
/// <summary> /// <summary>
@ -318,7 +324,7 @@ namespace EPAServeur.Services
await epContext.SaveChangesAsync(); await epContext.SaveChangesAsync();
return GetFormationDTO(formation); return transformDTO.GetFormationDTOWhitoutParticipationFormation(formation);
} }
#endregion #endregion
@ -538,385 +544,6 @@ namespace EPAServeur.Services
} }
#region Object to DTO
/// <summary>
/// Récuperer un objet FormationDTO en fonction d'un objet Formation
/// </summary>
/// <param name="formation"></param>
/// <returns></returns>
private FormationDTO GetFormationDTO(Formation formation)
{
if (formation == null)
return null;
FormationDTO formationDTO = new FormationDTO()
{
Id = formation.IdFormation,
Intitule = formation.Intitule,
IdAgence = formation.IdAgence,
DateDebut = formation.DateDebut,
DateFin = formation.DateFin,
Heure = formation.Heure,
Jour = formation.Jour,
Organisme = formation.Organisme,
EstCertifiee = formation.EstCertifiee,
EstRealisee = formation.EstRealisee,
Origine = GetOrigineFormationDTO(formation.Origine),
Statut = GetStatutFormationDTO(formation.Statut),
Mode = GetModeFormationDTO(formation.ModeFormation),
Type = GetTypeFormationDTO(formation.TypeFormation),
};
return formationDTO;
}
/// <summary>
/// Récuperer un objet FormationDTO avec des participations en fonction d'un objet Formation et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="formation"></param>
/// <returns></returns>
private FormationDTO GetFormationDTO(Formation formation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (formation == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
FormationDTO formationDTO = new FormationDTO()
{
Id = formation.IdFormation,
Intitule = formation.Intitule,
IdAgence = formation.IdAgence,
DateDebut = formation.DateDebut,
DateFin = formation.DateFin,
Heure = formation.Heure,
Jour = formation.Jour,
Organisme = formation.Organisme,
EstCertifiee = formation.EstCertifiee,
EstRealisee = formation.EstRealisee,
Origine = GetOrigineFormationDTO(formation.Origine),
Statut = GetStatutFormationDTO(formation.Statut),
Mode = GetModeFormationDTO(formation.ModeFormation),
Type = GetTypeFormationDTO(formation.TypeFormation),
Participations = GetParticipationsFormationDTO(formation.ParticipationsFormation, collaborateurDTOs)
};
return formationDTO;
}
/// <summary>
/// Récuperer un objet FormationDetailsDTO en fonction d'un objet Formation
/// </summary>
/// <param name="formation"></param>
/// <returns></returns>
private FormationDetailsDTO GetFormationDetailsDTO(Formation formation)
{
if (formation == null)
return null;
FormationDetailsDTO formationDTO = new FormationDetailsDTO()
{
Id = formation.IdFormation,
Intitule = formation.Intitule,
DateDebut = formation.DateDebut,
DateFin = formation.DateFin,
Organisme = formation.Organisme,
EstCertifiee = formation.EstCertifiee,
NbParticipations = formation.ParticipationsFormation.Count,
Origine = GetOrigineFormationDTO(formation.Origine),
Statut = GetStatutFormationDTO(formation.Statut),
};
return formationDTO;
}
/// <summary>
/// Récuperer un objet OrigineFormationDTO en fonction d'un objet OrigineFormation
/// </summary>
/// <param name="origineFormation"></param>
/// <returns></returns>
private OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation)
{
if (origineFormation == null)
return null;
OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO()
{
Id = origineFormation.IdOrigineFormation,
Libelle = origineFormation.Libelle
};
return origineFormationDTO;
}
/// <summary>
/// Récuperer un objet StatutFormationDTO en fonction d'un objet StatutFormation
/// </summary>
/// <param name="statutFormation"></param>
/// <returns></returns>
private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation)
{
if (statutFormation == null)
return null;
StatutFormationDTO statutFormationDTO = new StatutFormationDTO()
{
Id = statutFormation.IdStatutFormation,
Libelle = statutFormation.Libelle
};
return statutFormationDTO;
}
/// <summary>
/// Récuperer un objet ModeFormationDTO en fonction d'un objet ModeFormation
/// </summary>
/// <param name="modeFormation"></param>
/// <returns></returns>
private ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation)
{
if (modeFormation == null)
return null;
ModeFormationDTO modeFormationDTO = new ModeFormationDTO()
{
Id = modeFormation.IdModeFormation,
Libelle = modeFormation.Libelle
};
return modeFormationDTO;
}
/// <summary>
/// Récuperer un objet TypeFormationDTO en fonction d'un objet TypeFormation
/// </summary>
/// <param name="typeFormation"></param>
/// <returns></returns>
private TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation)
{
if (typeFormation == null)
return null;
TypeFormationDTO typeFormationDTO = new TypeFormationDTO()
{
Id = typeFormation.IdTypeFormation,
Libelle = typeFormation.Libelle
};
return typeFormationDTO;
}
/// <summary>
/// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucune participation.
/// </summary>
/// <param name="typeFormation"></param>
/// <returns></returns>
private async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOs(List<ParticipationFormation> participationsFormation)
{
if (participationsFormation == null || participationsFormation.Count == 0)
return null;
List<Guid?> guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList();
return await collaborateurService.GetCollaborateurDTOsAsync(guids); ;
}
/// <summary>
/// Récuperer une liste de ParticipationFormationDTO en fonction d'une liste de ParticipationFormation et d'une liste de CollaborateurDTO. Retourne null s'il n'y a aucune participation ou aucun collaborateur.
/// </summary>
/// <param name="typeFormation"></param>
/// <returns></returns>
private List<ParticipationFormationDTO> GetParticipationsFormationDTO(List<ParticipationFormation> participationsFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
List<ParticipationFormationDTO> participationFormationDTOs;
if (participationsFormation == null || participationsFormation.Count == 0 || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
participationFormationDTOs = participationsFormation.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs))
.OrderBy(participationFormation => participationFormation.Collaborateur.Nom)
.ThenBy(participationFormation => participationFormation.Collaborateur.Prenom).ToList();
return participationFormationDTOs;
}
/// <summary>
/// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
ParticipationFormationDTO participationFormationDTO = new ParticipationFormationDTO()
{
Id = participationFormation.IdParticipationFormation,
DateCreation = participationFormation.DateCreation,
Intitule = participationFormation.Formation.Intitule,
DateDebut = participationFormation.Formation.DateDebut,
Statut = GetStatutFormationDTO(participationFormation.Formation.Statut),
Collaborateur = GetCollaborateurDTO(participationFormation, collaborateurDTOs),
Ep = GetEpInformationDTO(participationFormation.DemandeFormation.Ep, collaborateurDTOs)
};
return participationFormationDTO;
}
/// <summary>
/// Récupère un objet CollaborateurDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
private CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur);
}
/// <summary>
/// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="ep"></param>
/// <returns></returns>
private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
CollaborateurDTO collaborateur;
CollaborateurDTO referent;
if (ep == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
collaborateur = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur);
referent = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdReferent);
EpInformationDTO epInformationDTO = new EpInformationDTO()
{
Id = ep.IdEP,
Type = ep.TypeEP,
Statut = ep.Statut,
DateDisponibilite = ep.DateDisponibilite,
DatePrevisionnelle = ep.DatePrevisionnelle,
Obligatoire = ep.Obligatoire,
Collaborateur = collaborateur,
Referent = referent,
};
return epInformationDTO;
}
#endregion
#region DTO to Object
/// <summary>
/// Modifier un objet Formation en fonction d'un objet FormationDTO
/// </summary>
/// <param name="formation"></param>
/// <param name="formationDTO"></param>
/// <returns></returns>
private Formation SetFormation(Formation formation, FormationDTO formationDTO)
{
if (formation == null || formationDTO == null)
return null;
formation.Intitule = formationDTO.Intitule;
formation.IdAgence = formationDTO.IdAgence.Value;
formation.DateDebut = formationDTO.DateDebut.Value;
formation.DateFin = formationDTO.DateFin.Value;
formation.Heure = Convert.ToInt32(formationDTO.Heure.Value);
formation.Jour = Convert.ToInt32(formationDTO.Jour.Value);
formation.Organisme = formationDTO.Organisme;
formation.EstCertifiee = formationDTO.EstCertifiee.Value;
//formation.EstRealisee = formationDTO.EstRealisee.Value;
formation.Origine = GetOrigineFormation(formationDTO.Origine);
formation.Statut = GetStatutFormation(formationDTO.Statut);
formation.ModeFormation = GetModeFormation(formationDTO.Mode);
formation.TypeFormation = GetTypeFormation(formationDTO.Type);
return formation;
}
/// <summary>
/// Récuperer un objet OrigineFormation en fonction d'un objet OrigineFormationDTO
/// </summary>
/// <param name="origineFormationDTO"></param>
/// <returns></returns>
private OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO)
{
if (origineFormationDTO == null)
return null;
OrigineFormation origineFormation = new OrigineFormation()
{
IdOrigineFormation = origineFormationDTO.Id.Value,
Libelle = origineFormationDTO.Libelle
};
return origineFormation;
}
/// <summary>
/// Récuperer un objet StatutFormation en fonction d'un objet StatutFormationDTO
/// </summary>
/// <param name="statutFormationDTO"></param>
/// <returns></returns>
private StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO)
{
if (statutFormationDTO == null)
return null;
StatutFormation statutFormation = new StatutFormation()
{
IdStatutFormation = statutFormationDTO.Id.Value,
Libelle = statutFormationDTO.Libelle
};
return statutFormation;
}
/// <summary>
/// Récuperer un objet ModeFormation en fonction d'un objet ModeFormationDTO
/// </summary>
/// <param name="modeFormationDTO"></param>
/// <returns></returns>
private ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO)
{
if (modeFormationDTO == null)
return null;
ModeFormation modeFormation = new ModeFormation()
{
IdModeFormation = modeFormationDTO.Id.Value,
Libelle = modeFormationDTO.Libelle
};
return modeFormation;
}
/// <summary>
/// Récuperer un objet TypeFormation en fonction d'un objet TypeFormationDTO
/// </summary>
/// <param name="typeFormationDTO"></param>
/// <returns></returns>
private TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO)
{
if (typeFormationDTO == null)
return null;
TypeFormation typeFormation = new TypeFormation()
{
IdTypeFormation = typeFormationDTO.Id.Value,
Libelle = typeFormationDTO.Libelle
};
return typeFormation;
}
#endregion
#endregion #endregion
} }

@ -32,13 +32,19 @@ namespace EPAServeur.Services
/// Service collaborateur pour récupérer les données collaborateurs au format DTO /// Service collaborateur pour récupérer les données collaborateurs au format DTO
/// </summary> /// </summary>
private readonly ICollaborateurService collaborateurService; private readonly ICollaborateurService collaborateurService;
/// <summary>
/// Accès au service permettant de transformer un modèle en dto
/// </summary>
private readonly ITransformDTO transformDTO;
#endregion #endregion
#region Constructeurs #region Constructeurs
public NoteService(ICollaborateurApi _collaborateurApi, ICollaborateurService _collaborateurService, EpContext _context) public NoteService(ICollaborateurApi _collaborateurApi, ICollaborateurService _collaborateurService, EpContext _context, ITransformDTO _transformDTO)
{ {
collaborateurService = _collaborateurService; collaborateurService = _collaborateurService;
collaborateurApi = _collaborateurApi; collaborateurApi = _collaborateurApi;
context = _context; context = _context;
transformDTO = _transformDTO;
} }
#endregion #endregion
@ -66,7 +72,7 @@ namespace EPAServeur.Services
//transformer la note DTO en Note //transformer la note DTO en Note
Note note = DetailsNoteDTOToNouvelleNote(nouvelleNote); Note note = transformDTO.DetailsNoteDTOToNouvelleNote(nouvelleNote);
//ajouter la note et sauvegarder //ajouter la note et sauvegarder
await context.Note.AddAsync(note); await context.Note.AddAsync(note);
@ -111,7 +117,7 @@ namespace EPAServeur.Services
if (auteur == null) if (auteur == null)
throw new ReferentNotFoundException("L'auteur de la note n'existe pas"); throw new ReferentNotFoundException("L'auteur de la note n'existe pas");
return NoteToDetailSDTO(note, await collaborateurService.GetCollaborateurByIdAsync(note.IdCollaborateur)); return transformDTO.NoteToDetailSDTO(note, await collaborateurService.GetCollaborateurByIdAsync(note.IdCollaborateur));
} }
/// <summary> /// <summary>
@ -134,7 +140,7 @@ namespace EPAServeur.Services
List<Guid?> guids = notes.Select(n => (Guid?)n.IdCollaborateur).ToList(); List<Guid?> guids = notes.Select(n => (Guid?)n.IdCollaborateur).ToList();
IEnumerable<Collaborateur> collaborateurs = await collaborateurApi.ChercherCollabAsync(guids); IEnumerable<Collaborateur> collaborateurs = await collaborateurApi.ChercherCollabAsync(guids);
IEnumerable<AffichageNoteDTO> AffichageNoteDTO = notes.Select(note => NoteToAffichageDTO(note, collaborateurs)); IEnumerable<AffichageNoteDTO> AffichageNoteDTO = notes.Select(note => transformDTO.NoteToAffichageDTO(note, collaborateurs));
int skip = (numPage.Value - 1) * parPage.Value; int skip = (numPage.Value - 1) * parPage.Value;
@ -173,7 +179,7 @@ namespace EPAServeur.Services
List<Guid?> guids = notes.Select(n => (Guid?)n.IdCollaborateur).ToList(); List<Guid?> guids = notes.Select(n => (Guid?)n.IdCollaborateur).ToList();
IEnumerable<Collaborateur> collaborateurs = await collaborateurApi.ChercherCollabAsync(guids); IEnumerable<Collaborateur> collaborateurs = await collaborateurApi.ChercherCollabAsync(guids);
IEnumerable<AffichageNoteDTO> AffichageNoteDTO = notes.Select(note => NoteToAffichageDTO(note, collaborateurs)); IEnumerable<AffichageNoteDTO> AffichageNoteDTO = notes.Select(note => transformDTO.NoteToAffichageDTO(note, collaborateurs));
if (texte != null) if (texte != null)
{ {
@ -274,77 +280,5 @@ namespace EPAServeur.Services
} }
#endregion #endregion
#region ObjectToDTO
/// <summary>
/// Transformer un objet note en objet pour afficher un note dans dans un tableau
/// </summary>
/// <param name="note">Note à transformer</param>
/// <param name="collaborateurService">Service collaborateur pour récupérer les informations des collaborateurs</param>
/// <returns>La note transformée pour être affichée</returns>
private AffichageNoteDTO NoteToAffichageDTO(Note note, IEnumerable<Collaborateur> collaborateurs)
{
Collaborateur collaborateur = collaborateurs.FirstOrDefault(c => c.Id.Equals(note.IdCollaborateur));
string infoCollab = "Aucun collaborateur lié";
if (collaborateur != null)
infoCollab = collaborateur.Nom + " " + collaborateur.Prenom;
AffichageNoteDTO affichage = new AffichageNoteDTO()
{
Id = note.IdNote,
IdCollaborateur = note.IdCollaborateur,
Collaborateur = infoCollab,
Titre = note.Titre,
DateMiseAJour = note.DateMiseAJour
};
return affichage;
}
/// <summary>
/// Transformatino d'une note en DetailsNoteDTO de manière asynchrone
/// </summary>
/// <param name="note">Note à transformer</param>
/// <returns>Note transformer en DetailsNoteDTO</returns>
private DetailsNoteDTO NoteToDetailSDTO(Note note, CollaborateurDTO collaborateur)
{
if (collaborateur == null)
throw new CollaborateurNotFoundException("Il est impossible de récupérer une note donc le collaborateur n'existe plus");
DetailsNoteDTO details = new DetailsNoteDTO()
{
Id = note.IdNote,
DateCreation = note.DateCreation,
DateMiseAjour = note.DateMiseAJour,
Titre = note.Titre,
Texte = note.Texte,
IdAuteur = note.IdAuteur,
Collaborateur = collaborateur,
};
return details;
}
#endregion
#region DTOToObject
/// <summary>
/// Transformer l'objet DTO d'une note en note
/// </summary>
/// <remarks>En général, de base, cette méthode est prévue pour être utilisée qu'à la création d'une nouvelle note, dateCreation et dateUpdate sont donc initialisée à ce moment là</remarks>
/// <param name="detailsNoteDTO">Objet DTO à transformer en note</param>
/// <returns>L'objet DTO transformé en note</returns>
private Note DetailsNoteDTOToNouvelleNote(DetailsNoteDTO detailsNoteDTO)
{
Note note = new Note()
{
IdAuteur = detailsNoteDTO.IdAuteur.Value,
IdCollaborateur = detailsNoteDTO.Collaborateur.Id.Value,
Texte = detailsNoteDTO.Texte,
Titre = detailsNoteDTO.Titre,
DateCreation = detailsNoteDTO.DateCreation.Value,
DateMiseAJour = detailsNoteDTO.DateMiseAjour.Value
};
return note;
}
#endregion
} }
} }

@ -28,6 +28,11 @@ namespace EPAServeur.Services
/// </summary> /// </summary>
private readonly ICollaborateurService collaborateurService; private readonly ICollaborateurService collaborateurService;
/// <summary>
/// Accès au service permettant de transformer un modèle en dto
/// </summary>
private readonly ITransformDTO transformDTO;
#endregion #endregion
#region Contructeurs #region Contructeurs
@ -36,10 +41,11 @@ namespace EPAServeur.Services
/// Constructeur de la classe FormationService /// Constructeur de la classe FormationService
/// </summary> /// </summary>
/// <param name="_epContext"></param> /// <param name="_epContext"></param>
public ParticipationFormationService(EpContext _epContext, ICollaborateurService _collaborateurService) public ParticipationFormationService(EpContext _epContext, ICollaborateurService _collaborateurService, ITransformDTO _transformDTO)
{ {
epContext = _epContext; epContext = _epContext;
collaborateurService = _collaborateurService; collaborateurService = _collaborateurService;
transformDTO = _transformDTO;
} }
#endregion #endregion
@ -63,7 +69,7 @@ namespace EPAServeur.Services
if (participationFormation == null) if (participationFormation == null)
throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation)); throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation));
return GetEvaluationDTO(participationFormation); return transformDTO.GetEvaluationDTO(participationFormation);
} }
/// <summary> /// <summary>
@ -87,9 +93,9 @@ namespace EPAServeur.Services
participationFormations = await query.ToListAsync(); participationFormations = await query.ToListAsync();
IEnumerable<CollaborateurDTO> collaborateurDTOs = await GetCollaborateurDTOs(participationFormations); IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(participationFormations);
participationFormationDTOs = participationFormations.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs)); participationFormationDTOs = participationFormations.Select(participationFormation => transformDTO.GetParticipationFormationDTO(participationFormation, collaborateurDTOs));
return participationFormationDTOs; return participationFormationDTOs;
} }
@ -116,12 +122,12 @@ namespace EPAServeur.Services
if (participationFormation == null) if (participationFormation == null)
throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation)); throw new ParticipationFormationNotFoundException(string.Format("Aucune participation formation trouvée avec l'id suivant: {0}.", idParticipationFormation));
participationFormation.Evaluation = evaluationDTO.Saisies.Select(s => GetSaisie(s)).ToList(); participationFormation.Evaluation = evaluationDTO.Saisies.Select(s => transformDTO.GetSaisie(s)).ToList();
participationFormation.EstEvaluee = true; participationFormation.EstEvaluee = true;
await epContext.SaveChangesAsync(); await epContext.SaveChangesAsync();
return GetEvaluationDTO(participationFormation); return transformDTO.GetEvaluationDTO(participationFormation);
} }
#endregion #endregion
@ -163,238 +169,6 @@ namespace EPAServeur.Services
throw new ParticipationFormationInvalidException("Toutes les saisies de type compétence ou notation doivent posséder une note."); throw new ParticipationFormationInvalidException("Toutes les saisies de type compétence ou notation doivent posséder une note.");
} }
#region Object to DTO
/// <summary>
/// Récuperer un objet ParticipationFormationDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
private ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (participationFormation == null)
return null;
if (collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
ParticipationFormationDTO participationFormationDTO = new ParticipationFormationDTO()
{
Id = participationFormation.IdParticipationFormation,
DateCreation = participationFormation.DateCreation,
Intitule = participationFormation.Formation.Intitule,
DateDebut = participationFormation.Formation.DateDebut,
EstEvaluee = participationFormation.EstEvaluee,
Statut = GetStatutFormationDTO(participationFormation.Formation.Statut),
Collaborateur = GetCollaborateurDTO(participationFormation, collaborateurDTOs),
Ep = GetEpInformationDTO(participationFormation.DemandeFormation.Ep, collaborateurDTOs)
};
return participationFormationDTO;
}
/// <summary>
/// Récuperer un objet EvaluationDTO en fonction d'un objet ParticipationFormation
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
private EvaluationDTO GetEvaluationDTO(ParticipationFormation participationFormation)
{
if (participationFormation == null)
return null;
EvaluationDTO evaluationDTO = new EvaluationDTO()
{
Id = participationFormation.IdParticipationFormation,
Intitule = participationFormation.Formation.Intitule,
DateDebut = participationFormation.Formation.DateDebut,
EstCertifiee = participationFormation.Formation.EstCertifiee,
Saisies = participationFormation.Evaluation.Select(s => GetSaisieDTO(s)).ToList()
};
return evaluationDTO;
}
/// <summary>
/// Récuperer un objet SaisieDTO en fonction d'un objet Saisie
/// </summary>
/// <param name="saisie"></param>
/// <returns></returns>
private SaisieDTO GetSaisieDTO(Saisie saisie)
{
if (saisie == null)
return null;
SaisieDTO saisieDTO = new SaisieDTO()
{
Id = saisie.IdSaisie,
Note = saisie.Note,
Texte = saisie.Texte,
Champ = GetChampDTO(saisie.Champ),
TypeSaisie = saisie.TypeSaisie
};
return saisieDTO;
}
/// <summary>
/// Récuperer un objet ChampDTO en fonction d'un objet Champ
/// </summary>
/// <param name="champ"></param>
/// <returns></returns>
private ChampDTO GetChampDTO(Champ champ)
{
if (champ == null)
return null;
ChampDTO champDTO = new ChampDTO()
{
Id = champ.IdChamp,
Texte = champ.Texte,
Section = champ.Section,
Soussection = champ.SousSection,
Ordre = champ.Ordre,
TypeChamp = champ.TypeChamp,
TypeSaisie = champ.TypeSaisie
};
return champDTO;
}
/// <summary>
/// Récuperer un objet StatutFormationDTO en fonction d'un objet StatutFormation
/// </summary>
/// <param name="statutFormation"></param>
/// <returns></returns>
private StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation)
{
if (statutFormation == null)
return null;
StatutFormationDTO statutFormationDTO = new StatutFormationDTO()
{
Id = statutFormation.IdStatutFormation,
Libelle = statutFormation.Libelle
};
return statutFormationDTO;
}
/// <summary>
/// Récuperer une liste de CollaborateurDTO contenant les collaborateurs et les référents. Retourne null s'il n'y a aucune participation.
/// </summary>
/// <param name="participationsFormation"></param>
/// <returns></returns>
private async Task<IEnumerable<CollaborateurDTO>> GetCollaborateurDTOs(IEnumerable<ParticipationFormation> participationsFormation)
{
if (participationsFormation == null || !participationsFormation.Any())
return null;
List<Guid?> guids = participationsFormation.SelectMany(participationFormation => new[] { (Guid?)participationFormation.DemandeFormation.Ep.IdCollaborateur, participationFormation.DemandeFormation.Ep.IdReferent }).ToList();
return await collaborateurService.GetCollaborateurDTOsAsync(guids); ;
}
/// <summary>
/// Récupère un objet CollaborateurDTO en fonction d'un objet ParticipationFormation et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
private CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (participationFormation == null)
return null;
if (collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur);
}
/// <summary>
/// Récupère un objet EpInformationDTO en fonction d'un objet Ep et d'une liste de CollaborateurDTO
/// </summary>
/// <param name="ep"></param>
/// <returns></returns>
private EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
CollaborateurDTO collaborateur;
CollaborateurDTO referent;
if (ep == null)
return null;
if (collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
collaborateur = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur);
referent = collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdReferent);
EpInformationDTO epInformationDTO = new EpInformationDTO()
{
Id = ep.IdEP,
Type = ep.TypeEP,
Statut = ep.Statut,
DateDisponibilite = ep.DateDisponibilite,
DatePrevisionnelle = ep.DatePrevisionnelle,
Obligatoire = ep.Obligatoire,
Collaborateur = collaborateur,
Referent = referent,
};
return epInformationDTO;
}
#endregion
#region DTO to Object
/// <summary>
/// Récuperer un objet Saisie en fonction d'un objet SaisieDTO
/// </summary>
/// <param name="saisieDTO"></param>
/// <returns></returns>
private Saisie GetSaisie(SaisieDTO saisieDTO)
{
if (saisieDTO == null)
return null;
Saisie saisie = new Saisie()
{
//IdSaisie = saisieDTO.Id.Value,
Note = saisieDTO.Note,
Texte = saisieDTO.Texte,
Champ = GetChamp(saisieDTO.Champ),
TypeSaisie = saisieDTO.TypeSaisie
};
return saisie;
}
/// <summary>
/// Récuperer un objet Champ en fonction d'un objet ChampDTO
/// </summary>
/// <param name="champDTO"></param>
/// <returns></returns>
private Champ GetChamp(ChampDTO champDTO)
{
if (champDTO == null)
return null;
Champ champ = new Champ()
{
IdChamp = champDTO.Id.Value,
Texte = champDTO.Texte,
Section = champDTO.Section,
SousSection = champDTO.Soussection,
Ordre = champDTO.Ordre.Value,
TypeChamp = champDTO.TypeChamp,
TypeSaisie = champDTO.TypeSaisie
};
return champ;
}
#endregion
#endregion #endregion
} }

@ -0,0 +1,713 @@
using EPAServeur.Context;
using EPAServeur.Exceptions;
using EPAServeur.IServices;
using EPAServeur.Models.EP;
using EPAServeur.Models.Formation;
using EPAServeur.Models.Notes;
using EPAServeur.Models.SaisieChamp;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO;
using IO.Swagger.Enum;
using IO.Swagger.ModelCollaborateur;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Services
{
public class TransformDTO : ITransformDTO
{
/// <summary>
/// Transformer un objet DetailsNoteDTO en objet Note.
/// </summary>
/// <remarks>En général, de base, cette méthode est prévue pour être utilisée qu'à la création d'une nouvelle note, dateCreation et dateUpdate sont donc initialisée à ce moment là</remarks>
/// <param name="detailsNoteDTO">Objet DTO à transformer en note</param>
/// <returns>L'objet DTO transformé en note</returns>
public Note DetailsNoteDTOToNouvelleNote(DetailsNoteDTO detailsNoteDTO)
{
Note note = new Note()
{
IdAuteur = detailsNoteDTO.IdAuteur.Value,
IdCollaborateur = detailsNoteDTO.Collaborateur.Id.Value,
Texte = detailsNoteDTO.Texte,
Titre = detailsNoteDTO.Titre,
DateCreation = detailsNoteDTO.DateCreation.Value,
DateMiseAJour = detailsNoteDTO.DateMiseAjour.Value
};
return note;
}
/// <summary>
/// Transformer un objet Ep en objet EpInformationDTO.
/// La liste des collaborateurs est utilisé pour alimenter le collaborateur et le référent de l'objet EpInformationDTO.
/// </summary>
/// <param name="ep"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public EpInformationDTO EpToEpDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
return new EpInformationDTO()
{
Id = ep.IdEP,
Collaborateur = collaborateurDTOs.Where(c => c.Id.Equals(ep.IdCollaborateur)).FirstOrDefault(),
DateDisponibilite = ep.DateDisponibilite,
DatePrevisionnelle = ep.DatePrevisionnelle,
Obligatoire = ep.Obligatoire,
Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdReferent)),
Statut = ep.Statut,
Type = ep.TypeEP
};
}
/// <summary>
/// Transformer un objet Agence en objet AgenceDTO.
/// </summary>
/// <param name="agence"></param>
/// <returns></returns>
public AgenceDTO GetAgenceDTO(Agence agence)
{
if (agence == null)
return null;
AgenceDTO agenceDTO = new AgenceDTO()
{
Id = agence.Id,
Nom = agence.Nom,
Bu = new List<BusinessUnitDTO>()
};
agenceDTO.Bu = agence.Bus.Select(bu => new BusinessUnitDTO()
{
Id = bu.Id,
Nom = bu.Nom
}).ToList();
return agenceDTO;
}
/// <summary>
/// Transformer une objet BU en objet BusinessUnitDTO.
/// </summary>
/// <param name="businessUnit"></param>
/// <returns></returns>
public BusinessUnitDTO GetBusinessUnitDTO(BU businessUnit)
{
if (businessUnit == null)
return null;
BusinessUnitDTO businessUnitDTO = new BusinessUnitDTO()
{
Id = businessUnit.Id,
Nom = businessUnit.Nom,
Agence = GetAgenceDTO(businessUnit.Agence)
};
return businessUnitDTO;
}
/// <summary>
/// Récupérer un objet Champ en objet ChampDTO.
/// </summary>
/// <param name="champDTO"></param>
/// <returns></returns>
public Champ GetChamp(ChampDTO champDTO)
{
if (champDTO == null)
return null;
Champ champ = new Champ()
{
IdChamp = champDTO.Id.Value,
Texte = champDTO.Texte,
Section = champDTO.Section,
SousSection = champDTO.Soussection,
Ordre = champDTO.Ordre.Value,
TypeChamp = champDTO.TypeChamp,
TypeSaisie = champDTO.TypeSaisie
};
return champ;
}
/// <summary>
/// Transformer un objet Champ en objet ChampDTO.
/// </summary>
/// <param name="champ"></param>
/// <returns></returns>
public ChampDTO GetChampDTO(Champ champ)
{
if (champ == null)
return null;
ChampDTO champDTO = new ChampDTO()
{
Id = champ.IdChamp,
Texte = champ.Texte,
Section = champ.Section,
Soussection = champ.SousSection,
Ordre = champ.Ordre,
TypeChamp = champ.TypeChamp,
TypeSaisie = champ.TypeSaisie
};
return champDTO;
}
/// <summary>
/// Récupérer le collaborateur qui participe à la formation.
/// </summary>
/// <param name="participationFormation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public CollaborateurDTO GetCollaborateurDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (participationFormation == null)
return null;
if (collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
return collaborateurDTOs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == participationFormation.DemandeFormation.Ep.IdCollaborateur);
}
/// <summary>
/// Transformer un objet DemandeDelegation en objet DemandeDelegationDTO.
/// L'objet CollaborateurDTO est utilisé pour alimenter la propriété Referent de l'objet DemandeDelegationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Ep de l'objet DemandeDelegationDTO.
/// </summary>
/// <param name="demande"></param>
/// <param name="referent"></param>
/// <param name="collaborateurs"></param>
/// <returns></returns>
public DemandeDelegationDTO GetDemandeDelegationDTO(DemandeDelegation demande, CollaborateurDTO referent, IEnumerable<CollaborateurDTO> collaborateurs)
{
return new DemandeDelegationDTO()
{
Id = demande.IdDemandeDelegation,
DateDemande = demande.DateDemande,
EtatDemande = demande.EtatDemande,
Referent = referent,
RaisonDemande = demande.RaisonDemande,
Ep = GetEpInformationDTO(demande.Ep, collaborateurs)
};
}
/// <summary>
/// Transformer un objet Engagement en objet EngagementDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Ep de l'objet EngagementDTO.
/// </summary>
/// <param name="engagement"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public EngagementDTO GetEngagementDTO(Engagement engagement, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (engagement == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
EngagementDTO engagementDTO = new EngagementDTO()
{
Id = engagement.IdEngagement,
Action = engagement.Action,
DateLimite = engagement.DateLimite,
Dispositif = engagement.Dispositif,
Modalite = engagement.Modalite,
RaisonNonRealisable = engagement.RaisonNonRealisable,
EtatEngagement = engagement.EtatEngagement,
Ep = GetEpInformationDTO(engagement.Ep, collaborateurDTOs)
};
return engagementDTO;
}
/// <summary>
/// Transformer un objet Ep en objet EpInformationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Referent de l'objet EpInformationDTO.
/// </summary>
/// <param name="ep"></param>
/// <param name="collaborateurs"></param>
/// <returns></returns>
public EpInformationDTO GetEpInformationDTO(Ep ep, IEnumerable<CollaborateurDTO> collaborateurs)
{
CollaborateurDTO collaborateur;
CollaborateurDTO referent;
if (ep == null || collaborateurs == null || !collaborateurs.Any())
return null;
collaborateur = collaborateurs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdCollaborateur);
referent = collaborateurs.FirstOrDefault(collaborateurDTO => collaborateurDTO.Id == ep.IdReferent);
EpInformationDTO epInformationDTO = new EpInformationDTO()
{
Id = ep.IdEP,
Type = ep.TypeEP,
Statut = ep.Statut,
DateDisponibilite = ep.DateDisponibilite,
DatePrevisionnelle = ep.DatePrevisionnelle,
Obligatoire = ep.Obligatoire,
Collaborateur = collaborateur,
Referent = referent,
};
return epInformationDTO;
}
/// <summary>
/// Transformer un objet ParticipationFormation en objet EvaluationDTO.
/// </summary>
/// <param name="participationFormation"></param>
/// <returns></returns>
public EvaluationDTO GetEvaluationDTO(ParticipationFormation participationFormation)
{
if (participationFormation == null)
return null;
EvaluationDTO evaluationDTO = new EvaluationDTO()
{
Id = participationFormation.IdParticipationFormation,
Intitule = participationFormation.Formation.Intitule,
DateDebut = participationFormation.Formation.DateDebut,
EstCertifiee = participationFormation.Formation.EstCertifiee,
Saisies = participationFormation.Evaluation.Select(s => GetSaisieDTO(s)).ToList()
};
return evaluationDTO;
}
/// <summary>
/// Transformer un objet Formation en objet FormationDetailsDTO.
/// </summary>
/// <param name="formation"></param>
/// <returns></returns>
public FormationDetailsDTO GetFormationDetailsDTO(Formation formation)
{
if (formation == null)
return null;
FormationDetailsDTO formationDTO = new FormationDetailsDTO()
{
Id = formation.IdFormation,
Intitule = formation.Intitule,
DateDebut = formation.DateDebut,
DateFin = formation.DateFin,
Organisme = formation.Organisme,
EstCertifiee = formation.EstCertifiee,
NbParticipations = formation.ParticipationsFormation.Count,
Origine = GetOrigineFormationDTO(formation.Origine),
Statut = GetStatutFormationDTO(formation.Statut),
};
return formationDTO;
}
/// <summary>
/// Transformer un objet Formation en objet FormationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Participations de l'objet FormationDTO.
/// </summary>
/// <param name="formation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public FormationDTO GetFormationDTO(Formation formation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (formation == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
FormationDTO formationDTO = new FormationDTO()
{
Id = formation.IdFormation,
Intitule = formation.Intitule,
IdAgence = formation.IdAgence,
DateDebut = formation.DateDebut,
DateFin = formation.DateFin,
Heure = formation.Heure,
Jour = formation.Jour,
Organisme = formation.Organisme,
EstCertifiee = formation.EstCertifiee,
EstRealisee = formation.EstRealisee,
Origine = GetOrigineFormationDTO(formation.Origine),
Statut = GetStatutFormationDTO(formation.Statut),
Mode = GetModeFormationDTO(formation.ModeFormation),
Type = GetTypeFormationDTO(formation.TypeFormation),
Participations = GetParticipationsFormationDTO(formation.ParticipationsFormation, collaborateurDTOs)
};
return formationDTO;
}
/// <summary>
/// Transformer un objet Formation en objet FormationDTO et laisser la propriété Participations de l'objet FormationDTO null.
/// </summary>
/// <param name="formation"></param>
/// <returns></returns>
public FormationDTO GetFormationDTOWhitoutParticipationFormation(Formation formation)
{
if (formation == null)
return null;
FormationDTO formationDTO = new FormationDTO()
{
Id = formation.IdFormation,
Intitule = formation.Intitule,
IdAgence = formation.IdAgence,
DateDebut = formation.DateDebut,
DateFin = formation.DateFin,
Heure = formation.Heure,
Jour = formation.Jour,
Organisme = formation.Organisme,
EstCertifiee = formation.EstCertifiee,
EstRealisee = formation.EstRealisee,
Origine = GetOrigineFormationDTO(formation.Origine),
Statut = GetStatutFormationDTO(formation.Statut),
Mode = GetModeFormationDTO(formation.ModeFormation),
Type = GetTypeFormationDTO(formation.TypeFormation),
};
return formationDTO;
}
/// <summary>
/// Transformer un objet ModeFormationDTO en objet ModeFormation.
/// </summary>
/// <param name="modeFormationDTO"></param>
/// <returns></returns>
public ModeFormation GetModeFormation(ModeFormationDTO modeFormationDTO)
{
if (modeFormationDTO == null)
return null;
ModeFormation modeFormation = new ModeFormation()
{
IdModeFormation = modeFormationDTO.Id.Value,
Libelle = modeFormationDTO.Libelle
};
return modeFormation;
}
/// <summary>
/// Transformer un objet ModeFormation en objet ModeFormationDTO.
/// </summary>
/// <param name="modeFormation"></param>
/// <returns></returns>
public ModeFormationDTO GetModeFormationDTO(ModeFormation modeFormation)
{
if (modeFormation == null)
return null;
ModeFormationDTO modeFormationDTO = new ModeFormationDTO()
{
Id = modeFormation.IdModeFormation,
Libelle = modeFormation.Libelle
};
return modeFormationDTO;
}
/// <summary>
/// Transformer un objet OrigineFormationDTO en objet OrigineFormation.
/// </summary>
/// <param name="origineFormationDTO"></param>
/// <returns></returns>
public OrigineFormation GetOrigineFormation(OrigineFormationDTO origineFormationDTO)
{
if (origineFormationDTO == null)
return null;
OrigineFormation origineFormation = new OrigineFormation()
{
IdOrigineFormation = origineFormationDTO.Id.Value,
Libelle = origineFormationDTO.Libelle
};
return origineFormation;
}
/// <summary>
/// Transformer un objet OrigineFormation en objet OrigineFormationDTO.
/// </summary>
/// <param name="origineFormation"></param>
/// <returns></returns>
public OrigineFormationDTO GetOrigineFormationDTO(OrigineFormation origineFormation)
{
if (origineFormation == null)
return null;
OrigineFormationDTO origineFormationDTO = new OrigineFormationDTO()
{
Id = origineFormation.IdOrigineFormation,
Libelle = origineFormation.Libelle
};
return origineFormationDTO;
}
/// <summary>
/// Transformer un objet ParticipationFormation en objet ParticipationFormationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Ep de l'objet FormationDTO.
/// </summary>
/// <param name="participationFormation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public ParticipationFormationDTO GetParticipationFormationDTO(ParticipationFormation participationFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
if (participationFormation == null || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
ParticipationFormationDTO participationFormationDTO = new ParticipationFormationDTO()
{
Id = participationFormation.IdParticipationFormation,
DateCreation = participationFormation.DateCreation,
Intitule = participationFormation.Formation.Intitule,
DateDebut = participationFormation.Formation.DateDebut,
Statut = GetStatutFormationDTO(participationFormation.Formation.Statut),
Collaborateur = GetCollaborateurDTO(participationFormation, collaborateurDTOs),
Ep = GetEpInformationDTO(participationFormation.DemandeFormation.Ep, collaborateurDTOs)
};
return participationFormationDTO;
}
/// <summary>
/// Transformer une liste d'objets ParticipationFormation en liste d'objets ParticipationFormationDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur et la propriété Ep de l'objet FormationDTO.
/// </summary>
/// <param name="participationsFormation"></param>
/// <param name="collaborateurDTOs"></param>
/// <returns></returns>
public List<ParticipationFormationDTO> GetParticipationsFormationDTO(List<ParticipationFormation> participationsFormation, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
List<ParticipationFormationDTO> participationFormationDTOs;
if (participationsFormation == null || participationsFormation.Count == 0 || collaborateurDTOs == null || !collaborateurDTOs.Any())
return null;
participationFormationDTOs = participationsFormation.Select(participationFormation => GetParticipationFormationDTO(participationFormation, collaborateurDTOs))
.OrderBy(participationFormation => participationFormation.Collaborateur.Nom)
.ThenBy(participationFormation => participationFormation.Collaborateur.Prenom).ToList();
return participationFormationDTOs;
}
/// <summary>
/// Transformer un objet SaisieDTO en objet Saisie.
/// </summary>
/// <param name="saisieDTO"></param>
/// <returns></returns>
public Saisie GetSaisie(SaisieDTO saisieDTO)
{
if (saisieDTO == null)
return null;
Saisie saisie = new Saisie()
{
//IdSaisie = saisieDTO.Id.Value,
Note = saisieDTO.Note,
Texte = saisieDTO.Texte,
Champ = GetChamp(saisieDTO.Champ),
TypeSaisie = saisieDTO.TypeSaisie
};
return saisie;
}
/// <summary>
/// Transformer un objet Saisie en objet SaisieDTO.
/// </summary>
/// <param name="saisie"></param>
/// <returns></returns>
public SaisieDTO GetSaisieDTO(Saisie saisie)
{
if (saisie == null)
return null;
SaisieDTO saisieDTO = new SaisieDTO()
{
Id = saisie.IdSaisie,
Note = saisie.Note,
Texte = saisie.Texte,
Champ = GetChampDTO(saisie.Champ),
TypeSaisie = saisie.TypeSaisie
};
return saisieDTO;
}
/// <summary>
/// Transformer un objet StatutFormationDTO en objet StatutFormation.
/// </summary>
/// <param name="statutFormationDTO"></param>
/// <returns></returns>
public StatutFormation GetStatutFormation(StatutFormationDTO statutFormationDTO)
{
if (statutFormationDTO == null)
return null;
StatutFormation statutFormation = new StatutFormation()
{
IdStatutFormation = statutFormationDTO.Id.Value,
Libelle = statutFormationDTO.Libelle
};
return statutFormation;
}
/// <summary>
/// Transformer un objet StatutFormation en objet StatutFormationDTO.
/// </summary>
/// <param name="statutFormation"></param>
/// <returns></returns>
public StatutFormationDTO GetStatutFormationDTO(StatutFormation statutFormation)
{
if (statutFormation == null)
return null;
StatutFormationDTO statutFormationDTO = new StatutFormationDTO()
{
Id = statutFormation.IdStatutFormation,
Libelle = statutFormation.Libelle
};
return statutFormationDTO;
}
/// <summary>
/// Transformer un objet TypeFormationDTO en objet TypeFormation.
/// </summary>
/// <param name="typeFormationDTO"></param>
/// <returns></returns>
public TypeFormation GetTypeFormation(TypeFormationDTO typeFormationDTO)
{
if (typeFormationDTO == null)
return null;
TypeFormation typeFormation = new TypeFormation()
{
IdTypeFormation = typeFormationDTO.Id.Value,
Libelle = typeFormationDTO.Libelle
};
return typeFormation;
}
/// <summary>
/// Transformer un objet TypeFormation en objet TypeFormationDTO.
/// </summary>
/// <param name="typeFormation"></param>
/// <returns></returns>
public TypeFormationDTO GetTypeFormationDTO(TypeFormation typeFormation)
{
if (typeFormation == null)
return null;
TypeFormationDTO typeFormationDTO = new TypeFormationDTO()
{
Id = typeFormation.IdTypeFormation,
Libelle = typeFormation.Libelle
};
return typeFormationDTO;
}
/// <summary>
/// Transformer un objet Note en objet AffichageNoteDTO.
/// La liste de collaborateurs est utilisé pour alimenter la propriété Collaborateur (nom et prénom) de l'objet AffichageNoteDTO.
/// </summary>
/// <param name="note"></param>
/// <param name="collaborateurs"></param>
/// <returns></returns>
public AffichageNoteDTO NoteToAffichageDTO(Note note, IEnumerable<Collaborateur> collaborateurs)
{
Collaborateur collaborateur = collaborateurs.FirstOrDefault(c => c.Id.Equals(note.IdCollaborateur));
string infoCollab = "Aucun collaborateur lié";
if (collaborateur != null)
infoCollab = collaborateur.Nom + " " + collaborateur.Prenom;
AffichageNoteDTO affichage = new AffichageNoteDTO()
{
Id = note.IdNote,
IdCollaborateur = note.IdCollaborateur,
Collaborateur = infoCollab,
Titre = note.Titre,
DateMiseAJour = note.DateMiseAJour
};
return affichage;
}
/// <summary>
/// Transformer un objet Note en objet DetailsNoteDTO.
/// L'objet CollaborateurDTO est utilisé pour alimenter la propriété Collaborateur de l'objet DetailsNoteDTO.
/// </summary>
/// <param name="note"></param>
/// <param name="collaborateur"></param>
/// <returns></returns>
public DetailsNoteDTO NoteToDetailSDTO(Note note, CollaborateurDTO collaborateur)
{
if (collaborateur == null)
throw new CollaborateurNotFoundException("Il est impossible de récupérer une note donc le collaborateur n'existe plus");
DetailsNoteDTO details = new DetailsNoteDTO()
{
Id = note.IdNote,
DateCreation = note.DateCreation,
DateMiseAjour = note.DateMiseAJour,
Titre = note.Titre,
Texte = note.Texte,
IdAuteur = note.IdAuteur,
Collaborateur = collaborateur,
};
return details;
}
/// <summary>
/// Mettre à jour un objet Formation en fonction d'un objet FormationDTO.
/// </summary>
/// <param name="formation"></param>
/// <param name="formationDTO"></param>
/// <returns></returns>
public Formation SetFormation(Formation formation, FormationDTO formationDTO)
{
if (formation == null || formationDTO == null)
return null;
formation.Intitule = formationDTO.Intitule;
formation.IdAgence = formationDTO.IdAgence.Value;
formation.DateDebut = formationDTO.DateDebut.Value;
formation.DateFin = formationDTO.DateFin.Value;
formation.Heure = Convert.ToInt32(formationDTO.Heure.Value);
formation.Jour = Convert.ToInt32(formationDTO.Jour.Value);
formation.Organisme = formationDTO.Organisme;
formation.EstCertifiee = formationDTO.EstCertifiee.Value;
//formation.EstRealisee = formationDTO.EstRealisee.Value;
formation.Origine = GetOrigineFormation(formationDTO.Origine);
formation.Statut = GetStatutFormation(formationDTO.Statut);
formation.ModeFormation = GetModeFormation(formationDTO.Mode);
formation.TypeFormation = GetTypeFormation(formationDTO.Type);
return formation;
}
/// <summary>
/// Mettre à jour la réponse d'un objet Engagement en fonction d'un objet EngagementDTO.
/// </summary>
/// <param name="engagement"></param>
/// <param name="engagementDTO"></param>
/// <returns></returns>
public Engagement SetReponseEngagement(Engagement engagement, EngagementDTO engagementDTO)
{
if (engagement == null || engagementDTO == null)
return null;
engagement.EtatEngagement = engagementDTO.EtatEngagement;
switch (engagement.EtatEngagement)
{
case EtatEngagement.NonRealisable:
engagement.RaisonNonRealisable = engagementDTO.RaisonNonRealisable;
break;
case EtatEngagement.DateLimitePassee:
engagement.RaisonNonRealisable = "La date limite pour respecter l'engagement est passée.";
break;
default:
engagement.RaisonNonRealisable = null;
break;
}
return engagement;
}
}
}

@ -122,6 +122,7 @@ namespace EPAServeur
//Services //Services
services.AddScoped<ITransformDTO, TransformDTO>();
services.AddScoped<ICollaborateurService, CollaborateurService>(); services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IEpInformationService, EpInformationService>(); services.AddScoped<IEpInformationService, EpInformationService>();
services.AddScoped<IFormationService, FormationService>(); services.AddScoped<IFormationService, FormationService>();

Loading…
Cancel
Save