You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
296 lines
8.5 KiB
296 lines
8.5 KiB
using EPAServeur.Context;
|
|
using EPAServeur.Exceptions;
|
|
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
|
|
{
|
|
[TestFixture]
|
|
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.AddTypesEntretien(context);
|
|
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
|
|
[TestCase(-999)]
|
|
[TestCase(20)]
|
|
[TestCase(100)]
|
|
[TestCase(0)]
|
|
public void GetEPById_NotFoundException(long idEp)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
AsyncTestDelegate exception = () => epDetailsService.GetEp(idEp);
|
|
Assert.ThrowsAsync(typeof(EpNotFoundException), exception);
|
|
}
|
|
#endregion
|
|
|
|
#region Récupérer EP avec Engagements
|
|
[TestCase(6, 3)]
|
|
[TestCase(8, 0)]
|
|
[TestCase(10, 1)]
|
|
public async Task GetEPById_GetEngagement(long idEP, int count)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEP);
|
|
if(count == 0)
|
|
{
|
|
Assert.IsNull(epDTO.Engagements);
|
|
}
|
|
else
|
|
{
|
|
Assert.IsNotNull(epDTO.Engagements);
|
|
Assert.AreEqual(count, epDTO.Engagements.Count);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Récupérer EP avec participant EP
|
|
[TestCase(1,0)]
|
|
[TestCase(3,2)]
|
|
[TestCase(5,1)]
|
|
[TestCase(11,2)]
|
|
public async Task GetEpById_GetParticipantEP(long idEP, int count)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEP);
|
|
if (count == 0)
|
|
{
|
|
Assert.IsNull(epDTO.Participants);
|
|
}
|
|
else
|
|
{
|
|
Assert.IsNotNull(epDTO.Participants);
|
|
Assert.AreEqual(count, epDTO.Participants.Count);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Récupérer EP avec CommentaireAssistant
|
|
[TestCase(2, 2)]
|
|
[TestCase(4, 0)]
|
|
[TestCase(16, 1)]
|
|
public async Task GetEpById_GetCommentairesAssistant(long idEP, int count)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEP);
|
|
if (count == 0)
|
|
{
|
|
Assert.IsNull(epDTO.CommentairesAssistant);
|
|
}
|
|
else
|
|
{
|
|
Assert.IsNotNull(epDTO.CommentairesAssistant);
|
|
Assert.AreEqual(count, epDTO.CommentairesAssistant.Count);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Récupérer EP avec demandes de délégation
|
|
[TestCase(1, false)]
|
|
[TestCase(2, true)]
|
|
[TestCase(4, true)]
|
|
[TestCase(8, true)]
|
|
[TestCase(9, false)]
|
|
[TestCase(12, false)]
|
|
public async Task GetEpById_GetDemandeDelegation(long idEp, bool possedeDemandeDelegation)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEp);
|
|
if(possedeDemandeDelegation)
|
|
Assert.IsNotNull(epDTO.DemandesDelegation);
|
|
else
|
|
Assert.IsNull(epDTO.DemandesDelegation);
|
|
}
|
|
#endregion
|
|
|
|
#region Récupérer EP avec RDV entretiens
|
|
[TestCase(2)]
|
|
[TestCase(5)]
|
|
[TestCase(12)]
|
|
public async Task GetEp_GetRDVEntretien(long idEp)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEp);
|
|
Assert.IsNotNull(epDTO);
|
|
Assert.IsNotNull(epDTO.RdvEntretien);
|
|
Assert.IsNotNull(epDTO.RdvEntretien.DateEntretien);
|
|
}
|
|
|
|
[TestCase(1, 0)]
|
|
[TestCase(2, 3)]
|
|
[TestCase(5, 2)]
|
|
[TestCase(11, 0)]
|
|
[TestCase(13, 0)]
|
|
public async Task GetEp_GetPropositionRDVEntretien(long idEp, int count)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEp);
|
|
Assert.IsNotNull(epDTO);
|
|
if( count == 0)
|
|
{
|
|
Assert.IsNull(epDTO.PropositionsEntretien);
|
|
}
|
|
else
|
|
{
|
|
Assert.IsNotNull(epDTO.PropositionsEntretien);
|
|
Assert.AreEqual(epDTO.PropositionsEntretien.Count, count);
|
|
Assert.IsTrue(epDTO.PropositionsEntretien.Count <= 3);
|
|
Assert.IsTrue(epDTO.PropositionsEntretien.Count > 0);
|
|
Assert.Less(epDTO.Statut, StatutEp.Effectue);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Récupérer EP avec choix type entretien
|
|
[TestCase(1, 0)]
|
|
[TestCase(2, 4)]
|
|
[TestCase(4, 1)]
|
|
[TestCase(5, 2)]
|
|
[TestCase(10, 0)]
|
|
[TestCase(12, 0)]
|
|
public async Task GetEp_GetChoixTypeEntretien(long idEp, int count)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEp);
|
|
Assert.IsNotNull(epDTO);
|
|
if (count == 0)
|
|
{
|
|
Assert.IsNull(epDTO.ChoixTypeEntretien);
|
|
}
|
|
else
|
|
{
|
|
Assert.IsNotNull(epDTO.ChoixTypeEntretien);
|
|
Assert.AreEqual(epDTO.ChoixTypeEntretien.Count, count);
|
|
Assert.Less(epDTO.Statut, StatutEp.Effectue);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Objectifs
|
|
[TestCase(3, true)]
|
|
[TestCase(7, false)]
|
|
[TestCase(10, true)]
|
|
public async Task GetEp_Objectifs_ObjectifsPrecedents(long idEp, bool possedeObjectifsPref)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEp);
|
|
Assert.IsNotNull(epDTO);
|
|
Assert.IsNotNull(epDTO.Objectifs);
|
|
Assert.AreEqual(3, epDTO.Objectifs.Count);
|
|
if (possedeObjectifsPref)
|
|
{
|
|
Assert.IsNotNull(epDTO.ObjectifsPrecedent);
|
|
Assert.AreEqual(3, epDTO.ObjectifsPrecedent.Count);
|
|
}else
|
|
{
|
|
Assert.IsNull(epDTO.ObjectifsPrecedent);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Demande EPI
|
|
[TestCase(4)]
|
|
[TestCase(8)]
|
|
[TestCase(13)]
|
|
public async Task GetEp_GetDemandeEPI(long idEp)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEp);
|
|
Assert.IsNotNull(epDTO);
|
|
Assert.IsNotNull(epDTO.DemandeEPI);
|
|
Assert.IsTrue(epDTO.Collaborateur.Id.Equals(epDTO.DemandeEPI.Collaborateur.Id));
|
|
Assert.AreEqual(epDTO.DemandeEPI.EtatDemande, EtatDemande.Validee);
|
|
}
|
|
#endregion
|
|
|
|
#region Récupérer EP avec demandes de formation
|
|
[TestCase(1,0)]
|
|
[TestCase(2,0)]
|
|
[TestCase(3,1)]
|
|
[TestCase(12,3)]
|
|
[TestCase(16,0)]
|
|
public async Task GetEp_GetpDemandesFormation(long idEp, int count)
|
|
{
|
|
IEpDetailsService epDetailsService = new EpDetailsService(context, transformDTO, collaborateurService);
|
|
EpDTO epDTO = await epDetailsService.GetEp(idEp);
|
|
Assert.IsNotNull(epDTO);
|
|
if(count == 0)
|
|
{
|
|
Assert.IsNull(epDTO.DemandesFormation);
|
|
}
|
|
else
|
|
{
|
|
Assert.IsNotNull(epDTO.DemandesFormation);
|
|
Assert.AreEqual(epDTO.DemandesFormation.Count, count);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|