Implémentation de la récupération des détails d'un EP

develop
Yanaël GRETTE 3 years ago
parent a9edf6c89f
commit 8f3aed1f24
  1. 115
      EPAServeur.Tests/Services/EpDetailsServiceTests.cs
  2. 1
      EPAServeur/Context/DataSeeder.cs
  3. 31
      EPAServeur/Exceptions/EpNotFoundException.cs
  4. 32
      EPAServeur/Services/EpDetailsService.cs
  5. 16
      EPAServeur/Services/TransformDTO.cs

@ -0,0 +1,115 @@
using EPAServeur.Context;
using EPAServeur.IServices;
using EPAServeur.Models.EP;
using EPAServeur.Services;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO;
using IO.Swagger.Enum;
using Microsoft.EntityFrameworkCore;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace EPAServeur.Tests.Services
{
public class EpDetailsServiceTests
{
#region variables
private EpContext context;
private ICollaborateurService collaborateurService;
private ITransformDTO transformDTO;
#endregion
#region Setup
[SetUp]
public void Setup()
{
// Utilisation d'une base de données en mémoire
var optionBuider = new DbContextOptionsBuilder<EpContext>()
.UseInMemoryDatabase("server_ep_test")
.Options;
context = new EpContext(optionBuider);
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.SaveChanges();
DataSeeder.AddEp(context);
foreach (var entity in context.ChangeTracker.Entries())
{
entity.State = EntityState.Detached;
}
transformDTO = new TransformDTO();
collaborateurService = new CollaborateurService(new CollaborateurApi(), context, transformDTO);
}
#endregion
#region Récupérer EP simple
[TestCase(1, "301ba7f3-095e-4912-8998-a7c942dc5f23", StatutEp.Disponible)]
[TestCase(2, "e7820f92-eab1-42f5-ae96-5c16e71ff1e6", StatutEp.DatesProposees)]
[TestCase(5, "17b87130-0e9d-4b78-b0e3-a11e5f70318d", StatutEp.AttenteEntretien)]
[TestCase(14, "a0f40e2a-cc03-4032-a627-5389e1281c64", StatutEp.Signe)]
public async Task GetEpById(long idEP, Guid? idCollaborateur, StatutEp statutEp)
{
Ep ep = await context.Ep.FindAsync(idEP);
Assert.IsNotNull(ep);
Assert.AreEqual(idEP, ep.IdEP);
Assert.AreEqual(idCollaborateur, ep.IdCollaborateur);
Assert.AreEqual(statutEp, ep.Statut);
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
EpDTO epDTO = await epDetailsService.GetEp(ep.IdEP);
Assert.IsNotNull(epDTO);
Assert.AreEqual(epDTO.Collaborateur.Id, ep.IdCollaborateur);
Assert.AreEqual(epDTO.Statut, ep.Statut);
Assert.AreEqual(epDTO.Id, ep.IdEP);
}
#endregion
#region Récupérer EP exceptions
#endregion
#region Récupérer EP avec Engagements
#endregion
#region Récupérer EP avec participant EP
#endregion
#region Récupérer EP avec RDV entretiens
#endregion
#region Récupérer EP avec type entretien
#endregion
#region Récupérer EP avec CommentaireAssistant
#endregion
#region Récupérer EP avec demandes de délégation
#endregion
#region Récupérer EP avec demandes de formation
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
#region
#endregion
}
}

@ -2005,5 +2005,6 @@ namespace EPAServeur.Context
context.SaveChanges();
}
}
}

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
namespace EPAServeur.Exceptions
{
/// <summary>
/// Exceptin pour gérer les EP non trouvé
/// </summary>
public class EpNotFoundException : Exception
{
public EpNotFoundException()
{
}
public EpNotFoundException(string message) : base(message)
{
}
public EpNotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
protected EpNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}

@ -1,4 +1,8 @@
using EPAServeur.IServices;
using EPAServeur.Context;
using EPAServeur.Exceptions;
using EPAServeur.IServices;
using EPAServeur.Models.EP;
using IO.Swagger.ApiCollaborateur;
using IO.Swagger.DTO;
using System;
using System.Collections.Generic;
@ -9,10 +13,32 @@ namespace EPAServeur.Services
{
public class EpDetailsService : IEpDetailsService
{
private EpContext context;
private ITransformDTO transformDTO;
private ICollaborateurService collaborateurService;
public Task<EpDTO> GetEp(long id)
public EpDetailsService(EpContext context, ITransformDTO transformDTO, ICollaborateurService collaborateurService)
{
throw new NotImplementedException();
this.context = context;
this.transformDTO = transformDTO;
this.collaborateurService = collaborateurService;
}
public async Task<EpDTO> GetEp(long id)
{
Ep ep = await context.Ep.FindAsync(id);
if (ep == null)
throw new EpNotFoundException();
List<Guid?> guids = new List<Guid?>();
guids.Add(ep.IdCollaborateur);
if (ep.IdReferent.HasValue)
guids.Add(ep.IdCollaborateur);
IEnumerable<CollaborateurDTO> collaborateurDTOs = await collaborateurService.GetCollaborateurDTOsAsync(guids) ;
EpDTO epDTO = transformDTO.EpToEpDetails(ep, collaborateurDTOs);
return epDTO;
}
public void RappelSignature(long idEp)

@ -47,7 +47,21 @@ namespace EPAServeur.Services
/// <returns>L'EP transformé en DTO</returns>
public EpDTO EpToEpDetails(Ep ep, IEnumerable<CollaborateurDTO> collaborateurDTOs)
{
throw new NotImplementedException();
return new EpDTO()
{
Id = ep.IdEP,
Collaborateur = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdCollaborateur)),
Referent = collaborateurDTOs.FirstOrDefault(c => c.Id.Equals(ep.IdCollaborateur)),
DateDisponibilite = ep.DateDisponibilite,
DatePrevisionnelle = ep.DatePrevisionnelle,
DateSaisie = ep.DateSaisie,
DateSignatureCollaborateur = ep.DateSignatureCollaborateur,
DateSignatureReferent = ep.DateSignatureReferent,
Obligatoire = ep.Obligatoire,
Statut = ep.Statut,
Type = ep.TypeEP,
Cv = ep.CV
};
}
/// <summary>

Loading…
Cancel
Save