Mise à jour du jeu de données et utilisation du service collaborateur du serveur à la place du service collaborateur distant dans le service demande délégation

develop
Yanaël GRETTE 4 years ago
parent 95ed1e83ac
commit f13fcc25b7
  1. 4
      EPAServeur.Tests/Controllers/DemandeDelegationApiTests.cs
  2. 24
      EPAServeur.Tests/Services/DemandeDelegationServiceTests.cs
  3. 21
      EPAServeur/Context/DataSeeder.cs
  4. 2
      EPAServeur/Controllers/DemandesDelegationApi.cs
  5. 35
      EPAServeur/Services/DemandeDelegationService.cs

@ -24,6 +24,7 @@ namespace EPAServeur.Tests.Controllers
private ILogger<DemandesDelegationApiController> logger; private ILogger<DemandesDelegationApiController> logger;
IDemandeDelegationService demandeDelegationService; IDemandeDelegationService demandeDelegationService;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService;
#endregion #endregion
#region Setup #region Setup
@ -54,7 +55,8 @@ namespace EPAServeur.Tests.Controllers
} }
collaborateurApi = new CollaborateurApi(); collaborateurApi = new CollaborateurApi();
demandeDelegationService = new DemandeDelegationService(collaborateurApi, context); collaborateurService = new CollaborateurService(collaborateurApi, context);
demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
} }
#endregion #endregion

@ -22,6 +22,7 @@ namespace EPAServeur.Tests.Services
#region variables #region variables
private EpContext context; private EpContext context;
private ICollaborateurApi collaborateurApi; private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService;
#endregion #endregion
#region Setup #region Setup
@ -51,6 +52,7 @@ namespace EPAServeur.Tests.Services
entity.State = EntityState.Detached; entity.State = EntityState.Detached;
} }
collaborateurApi = new CollaborateurApi(); collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, context);
} }
#endregion #endregion
@ -63,7 +65,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(collaborateurApi, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
IEnumerable<DemandeDelegationDTO> demandesDelegation = await demandeDelegationService.RecupererDemandesDelegation(idReferent); IEnumerable<DemandeDelegationDTO> demandesDelegation = await demandeDelegationService.RecupererDemandesDelegation(idReferent);
foreach (DemandeDelegationDTO demandeDelegation in demandesDelegation) foreach (DemandeDelegationDTO demandeDelegation in demandesDelegation)
{ {
@ -78,7 +80,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(collaborateurApi, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
AsyncTestDelegate exception = () => demandeDelegationService.RecupererDemandesDelegation(idReferent); AsyncTestDelegate exception = () => demandeDelegationService.RecupererDemandesDelegation(idReferent);
Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception);
} }
@ -91,8 +93,8 @@ 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(collaborateurApi, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
DemandeDelegation demandeDelegation = await context.DemandeDelegations.FindAsync(id); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id);
long idEp = demandeDelegation.IdEP; long idEp = demandeDelegation.IdEP;
Ep ep = await context.Ep.FindAsync(idEp); Ep ep = await context.Ep.FindAsync(idEp);
@ -111,7 +113,7 @@ namespace EPAServeur.Tests.Services
} }
}; };
DemandeDelegationDTO reponse = await demandeDelegationService.UpdateDemandeDelegation(id, demandeDTO); DemandeDelegationDTO reponse = await demandeDelegationService.UpdateDemandeDelegation(id, demandeDTO);
demandeDelegation = await context.DemandeDelegations.FindAsync(id); demandeDelegation = await context.DemandeDelegation.FindAsync(id);
Assert.IsNull(reponse); Assert.IsNull(reponse);
Assert.IsNull(demandeDelegation); Assert.IsNull(demandeDelegation);
ep = await context.Ep.FindAsync(idEp); ep = await context.Ep.FindAsync(idEp);
@ -123,8 +125,8 @@ 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(collaborateurApi, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
DemandeDelegation demandeDelegation = await context.DemandeDelegations.FindAsync(id); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id);
long idEp = demandeDelegation.IdEP; long idEp = demandeDelegation.IdEP;
Ep ep = await context.Ep.FindAsync(idEp); Ep ep = await context.Ep.FindAsync(idEp);
@ -154,7 +156,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(collaborateurApi, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO() DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO()
{ {
Id = id, Id = id,
@ -174,7 +176,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(collaborateurApi, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO() DemandeDelegationDTO demandeDTO = new DemandeDelegationDTO()
{ {
Id = id, Id = id,
@ -197,8 +199,8 @@ 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(collaborateurApi, context); IDemandeDelegationService demandeDelegationService = new DemandeDelegationService(collaborateurService, context);
DemandeDelegation demandeDelegation = await context.DemandeDelegations.FindAsync(id); DemandeDelegation demandeDelegation = await context.DemandeDelegation.FindAsync(id);
long idEp = demandeDelegation.IdEP; long idEp = demandeDelegation.IdEP;
Ep ep = await context.Ep.FindAsync(idEp); Ep ep = await context.Ep.FindAsync(idEp);

@ -1683,6 +1683,7 @@ namespace EPAServeur.Context
NumeroEp = 1, NumeroEp = 1,
DateCreation = new DateTime(2020, 7, 7), DateCreation = new DateTime(2020, 7, 7),
DatePrevisionnelle = new DateTime(2020, 7, 8), DatePrevisionnelle = new DateTime(2020, 7, 8),
DateDisponibilite = new DateTime(2020, 6, 8),
Obligatoire = false, Obligatoire = false,
Statut = StatutEp.DatesProposees, Statut = StatutEp.DatesProposees,
CV = "CV.pdf", CV = "CV.pdf",
@ -1693,7 +1694,7 @@ namespace EPAServeur.Context
dm1 = new DemandeDelegation() dm1 = new DemandeDelegation()
{ {
IdDemandeDelegation = 1, IdDemandeDelegation = 1,
DateDemande = new DateTime(), DateDemande = DateTime.Now,
Ep = ep21, Ep = ep21,
IdReferent = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), IdReferent = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"),
EtatDemande = EtatDemande.EnAttente, EtatDemande = EtatDemande.EnAttente,
@ -1712,6 +1713,7 @@ namespace EPAServeur.Context
TypeEP = TypeEp.EPA, TypeEP = TypeEp.EPA,
NumeroEp = 1, NumeroEp = 1,
DateCreation = new DateTime(2020, 7, 7), DateCreation = new DateTime(2020, 7, 7),
DateDisponibilite = new DateTime(2020, 6, 8),
DatePrevisionnelle = new DateTime(2020, 7, 8), DatePrevisionnelle = new DateTime(2020, 7, 8),
Obligatoire = false, Obligatoire = false,
Statut = StatutEp.DatesProposees, Statut = StatutEp.DatesProposees,
@ -1723,7 +1725,7 @@ namespace EPAServeur.Context
dm2 = new DemandeDelegation() dm2 = new DemandeDelegation()
{ {
IdDemandeDelegation = 2, IdDemandeDelegation = 2,
DateDemande = new DateTime(), DateDemande = DateTime.Now,
Ep = ep22, Ep = ep22,
IdReferent = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), IdReferent = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"),
EtatDemande = EtatDemande.EnAttente, EtatDemande = EtatDemande.EnAttente,
@ -1743,6 +1745,7 @@ namespace EPAServeur.Context
NumeroEp = 1, NumeroEp = 1,
DateCreation = new DateTime(2020, 7, 7), DateCreation = new DateTime(2020, 7, 7),
DatePrevisionnelle = new DateTime(2020, 7, 8), DatePrevisionnelle = new DateTime(2020, 7, 8),
DateDisponibilite = new DateTime(2020, 6, 8),
Obligatoire = false, Obligatoire = false,
Statut = StatutEp.DatesProposees, Statut = StatutEp.DatesProposees,
CV = "CV.pdf", CV = "CV.pdf",
@ -1753,7 +1756,7 @@ namespace EPAServeur.Context
dm3 = new DemandeDelegation() dm3 = new DemandeDelegation()
{ {
IdDemandeDelegation = 3, IdDemandeDelegation = 3,
DateDemande = new DateTime(), DateDemande = DateTime.Now,
Ep = ep23, Ep = ep23,
IdReferent = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"), IdReferent = new Guid("01ee85ff-d7f3-494b-b1de-26ced8fbfa0d"),
EtatDemande = EtatDemande.EnAttente, EtatDemande = EtatDemande.EnAttente,
@ -1773,6 +1776,7 @@ namespace EPAServeur.Context
NumeroEp = 1, NumeroEp = 1,
DateCreation = new DateTime(2020, 7, 7), DateCreation = new DateTime(2020, 7, 7),
DatePrevisionnelle = new DateTime(2020, 7, 8), DatePrevisionnelle = new DateTime(2020, 7, 8),
DateDisponibilite = new DateTime(2020, 6, 8),
Obligatoire = false, Obligatoire = false,
Statut = StatutEp.DatesProposees, Statut = StatutEp.DatesProposees,
CV = "CV.pdf", CV = "CV.pdf",
@ -1783,7 +1787,7 @@ namespace EPAServeur.Context
dm4 = new DemandeDelegation() dm4 = new DemandeDelegation()
{ {
IdDemandeDelegation = 4, IdDemandeDelegation = 4,
DateDemande = new DateTime(), DateDemande = DateTime.Now,
Ep = ep24, Ep = ep24,
IdReferent = new Guid("0afd1573-de75-4e5b-bfcb-1985259d8370"), IdReferent = new Guid("0afd1573-de75-4e5b-bfcb-1985259d8370"),
EtatDemande = EtatDemande.EnAttente, EtatDemande = EtatDemande.EnAttente,
@ -1803,6 +1807,7 @@ namespace EPAServeur.Context
NumeroEp = 1, NumeroEp = 1,
DateCreation = new DateTime(2020, 7, 7), DateCreation = new DateTime(2020, 7, 7),
DatePrevisionnelle = new DateTime(2020, 7, 8), DatePrevisionnelle = new DateTime(2020, 7, 8),
DateDisponibilite = new DateTime(2020, 6, 8),
Obligatoire = false, Obligatoire = false,
Statut = StatutEp.DatesProposees, Statut = StatutEp.DatesProposees,
CV = "CV.pdf", CV = "CV.pdf",
@ -1813,7 +1818,7 @@ namespace EPAServeur.Context
dm5 = new DemandeDelegation() dm5 = new DemandeDelegation()
{ {
IdDemandeDelegation = 5, IdDemandeDelegation = 5,
DateDemande = new DateTime(), DateDemande = DateTime.Now,
Ep = ep25, Ep = ep25,
IdReferent = new Guid("de98a866-736f-4295-a669-92a8694e2ee3"), IdReferent = new Guid("de98a866-736f-4295-a669-92a8694e2ee3"),
EtatDemande = EtatDemande.EnAttente, EtatDemande = EtatDemande.EnAttente,
@ -1833,6 +1838,7 @@ namespace EPAServeur.Context
NumeroEp = 1, NumeroEp = 1,
DateCreation = new DateTime(2020, 7, 7), DateCreation = new DateTime(2020, 7, 7),
DatePrevisionnelle = new DateTime(2020, 7, 8), DatePrevisionnelle = new DateTime(2020, 7, 8),
DateDisponibilite = new DateTime(2020, 6, 8),
Obligatoire = false, Obligatoire = false,
Statut = StatutEp.DatesProposees, Statut = StatutEp.DatesProposees,
CV = "CV.pdf", CV = "CV.pdf",
@ -1843,7 +1849,7 @@ namespace EPAServeur.Context
dm6 = new DemandeDelegation() dm6 = new DemandeDelegation()
{ {
IdDemandeDelegation = 6, IdDemandeDelegation = 6,
DateDemande = new DateTime(), DateDemande = DateTime.Now,
Ep = ep26, Ep = ep26,
IdReferent = new Guid("17b87130-0e9d-4b78-b0e3-a11e5f70318d"), IdReferent = new Guid("17b87130-0e9d-4b78-b0e3-a11e5f70318d"),
EtatDemande = EtatDemande.EnAttente, EtatDemande = EtatDemande.EnAttente,
@ -1864,6 +1870,7 @@ namespace EPAServeur.Context
NumeroEp = 1, NumeroEp = 1,
DateCreation = new DateTime(2020, 7, 7), DateCreation = new DateTime(2020, 7, 7),
DatePrevisionnelle = new DateTime(2020, 7, 8), DatePrevisionnelle = new DateTime(2020, 7, 8),
DateDisponibilite = new DateTime(2020, 6, 8),
Obligatoire = false, Obligatoire = false,
Statut = StatutEp.DatesProposees, Statut = StatutEp.DatesProposees,
CV = "CV.pdf", CV = "CV.pdf",
@ -1874,7 +1881,7 @@ namespace EPAServeur.Context
dm7 = new DemandeDelegation() dm7 = new DemandeDelegation()
{ {
IdDemandeDelegation = 7, IdDemandeDelegation = 7,
DateDemande = new DateTime(), DateDemande = DateTime.Now,
Ep = ep27, Ep = ep27,
IdReferent = new Guid("17b87130-0e9d-4b78-b0e3-a11e5f70318d"), IdReferent = new Guid("17b87130-0e9d-4b78-b0e3-a11e5f70318d"),
EtatDemande = EtatDemande.Rejetee, EtatDemande = EtatDemande.Rejetee,

@ -138,7 +138,7 @@ namespace IO.Swagger.Controllers
/// <response code="500">Une erreur est survenue sur le serveur</response> /// <response code="500">Une erreur est survenue sur le serveur</response>
[HttpPut] [HttpPut]
[Route("/api/demandesdelegation/{idDemandeDelegation}")] [Route("/api/demandesdelegation/{idDemandeDelegation}")]
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)] //[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
[ValidateModelState] [ValidateModelState]
[SwaggerOperation("UpdateDemandeDelegation")] [SwaggerOperation("UpdateDemandeDelegation")]
[SwaggerResponse(statusCode: 200, type: typeof(DemandeDelegationDTO), description: "Demande de délégation mise à jour avec succès")] [SwaggerResponse(statusCode: 200, type: typeof(DemandeDelegationDTO), description: "Demande de délégation mise à jour avec succès")]

@ -19,13 +19,15 @@ namespace EPAServeur.Services
#region variables #region variables
private readonly EpContext context; private readonly EpContext context;
private static ICollaborateurApi collaborateurAPI; private static ICollaborateurApi collaborateurAPI;
private static ICollaborateurService collaborateurService;
#endregion #endregion
#region constructeur #region constructeur
public DemandeDelegationService(ICollaborateurApi _collaborateurApi, EpContext _context) public DemandeDelegationService(ICollaborateurService _collaborateurService, EpContext _context)
{ {
context = _context; context = _context;
collaborateurAPI = _collaborateurApi; collaborateurService = _collaborateurService;
} }
#endregion #endregion
@ -33,11 +35,16 @@ namespace EPAServeur.Services
#region services async #region services async
public async Task<IEnumerable<DemandeDelegationDTO>> RecupererDemandesDelegation(Guid? idReferent) public async Task<IEnumerable<DemandeDelegationDTO>> RecupererDemandesDelegation(Guid? idReferent)
{ {
Collaborateur referent = await collaborateurAPI.ChercherCollabIdAsync(idReferent); CollaborateurDTO referentDTO;
if (referent == null) try
{
referentDTO = await collaborateurService.GetCollaborateurByIdAsync(idReferent);
}
catch(CollaborateurNotFoundException)
{
throw new ReferentNotFoundException(); throw new ReferentNotFoundException();
}
CollaborateurDTO referentDTO = GetCollaborateurDTO(referent);
var tasks = from demandeDelegation in context.DemandeDelegation.Include( d => d.Ep) var tasks = from demandeDelegation in context.DemandeDelegation.Include( d => d.Ep)
where demandeDelegation.IdReferent.Equals(idReferent) && demandeDelegation.EtatDemande.Equals(EtatDemande.EnAttente) where demandeDelegation.IdReferent.Equals(idReferent) && demandeDelegation.EtatDemande.Equals(EtatDemande.EnAttente)
@ -67,13 +74,9 @@ namespace EPAServeur.Services
} }
return demandeDelegationDTO; return demandeDelegationDTO;
} }
#endregion #endregion
#region méthodes privées #region méthodes privées
private async Task<DemandeDelegationDTO> AccepterDemandeDelegation(DemandeDelegationDTO demandeDelegationDTO) private async Task<DemandeDelegationDTO> AccepterDemandeDelegation(DemandeDelegationDTO demandeDelegationDTO)
{ {
@ -103,24 +106,16 @@ namespace EPAServeur.Services
return demandeDelegationDTO; return demandeDelegationDTO;
} }
private static CollaborateurDTO GetCollaborateurDTO(Collaborateur collaborateur)
{
return new CollaborateurDTO()
{
Id = collaborateur.Id,
Nom = collaborateur.Nom,
Prenom = collaborateur.Prenom,
};
}
private static async Task<EpInformationDTO> GetEpInformationDTO(Ep ep) private static async Task<EpInformationDTO> GetEpInformationDTO(Ep ep)
{ {
return new EpInformationDTO() return new EpInformationDTO()
{ {
Id = ep.IdEP, Id = ep.IdEP,
Collaborateur = GetCollaborateurDTO(await collaborateurAPI.ChercherCollabIdAsync(ep.IdCollaborateur)), Collaborateur = await collaborateurService.GetCollaborateurByIdAsync(ep.IdCollaborateur),
Referent = GetCollaborateurDTO(await collaborateurAPI.ChercherCollabIdAsync(ep.IdReferent)), Referent = await collaborateurService.GetCollaborateurByIdAsync(ep.IdReferent),
DatePrevisionnelle = ep.DatePrevisionnelle, DatePrevisionnelle = ep.DatePrevisionnelle,
DateDisponibilite = ep.DateDisponibilite,
Statut = ep.Statut, Statut = ep.Statut,
Type = ep.TypeEP, Type = ep.TypeEP,
Obligatoire = ep.Obligatoire, Obligatoire = ep.Obligatoire,

Loading…
Cancel
Save