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.
1604 lines
75 KiB
1604 lines
75 KiB
using EPAServeur.Context;
|
|
using EPAServeur.Exceptions;
|
|
using EPAServeur.IServices;
|
|
using EPAServeur.Models.EP;
|
|
using EPAServeur.Models.Formation;
|
|
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.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EPAServeur.Tests.Services
|
|
{
|
|
[TestFixture]
|
|
public class DemandeFormationServiceTests
|
|
{
|
|
#region Variables
|
|
|
|
private EpContext epContext;
|
|
private ICollaborateurApi collaborateurApi;
|
|
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;
|
|
|
|
epContext = new EpContext(optionBuider);
|
|
collaborateurApi = new CollaborateurApi();
|
|
transformDTO = new TransformDTO();
|
|
collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO);
|
|
epContext.Database.EnsureDeleted();
|
|
epContext.Database.EnsureCreated();
|
|
epContext.SaveChanges();
|
|
|
|
// Ajout du jeu de données pour les tests
|
|
DataSeeder.AddFormations(epContext);
|
|
|
|
// Détache les entités du context car la base de données InMemory créé des conflits
|
|
// entre les clés primaires lors d'un Update ou d'un Insert
|
|
foreach (var entity in epContext.ChangeTracker.Entries())
|
|
{
|
|
entity.State = EntityState.Detached;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region Tests GetDemandesFormationAsync
|
|
|
|
[TestCase(new EtatDemande[] { EtatDemande.EnAttente, EtatDemande.Validee, EtatDemande.Rejetee }, new long[] { 1, 2 }, true, 1, 20, "gaillard", null, null, null)]
|
|
[TestCase(new EtatDemande[] { EtatDemande.EnAttente, EtatDemande.Validee, EtatDemande.Rejetee }, new long[] { 1 }, false, 1, 5, "gaillard", null, null, null)]
|
|
[TestCase(null, null, null, 2, 5, null, null, null, null)]
|
|
[TestCase(null, new long[] { 1 }, null, 1, 10, null, null, null, null)]
|
|
[TestCase(new EtatDemande[] { EtatDemande.Rejetee }, null, null, 1, 10, "gai", null, null, null)]
|
|
[TestCase(new EtatDemande[] { EtatDemande.EnAttente, EtatDemande.Validee, EtatDemande.Rejetee }, new long[] { }, null, 1, 50, "gai", null, null, null)]
|
|
public async Task GetDemandesFormationAsync_PasseDesParamsValides_RetourneDesDemandesDeFormations(EtatDemande[] arrEtatDemandes, long[] arrIdBUs, bool? asc, int? numPage, int? parPAge, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
List<long?> idBUs;
|
|
List<EtatDemande> etatDemandes;
|
|
|
|
if (arrEtatDemandes != null)
|
|
etatDemandes = arrEtatDemandes.ToList();
|
|
else
|
|
etatDemandes = null;
|
|
|
|
if (arrIdBUs != null)
|
|
idBUs = arrIdBUs.Select(idBu => (long?)idBu).ToList();
|
|
else
|
|
idBUs = null;
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(etatDemandes, idBUs, asc, numPage, parPAge, texte, tri, dateDebut, dateFin);
|
|
|
|
// Assert
|
|
Assert.Less(0, demandeFormationDTOs.Count());
|
|
}
|
|
|
|
[TestCase(1, 5)]
|
|
[TestCase(1, 10)]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesFormations(int? numPage, int? parPage)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, null, numPage, parPage, null, null, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(parPage, demandeFormationDTOs.Count());
|
|
}
|
|
|
|
[TestCase(2, 5)]
|
|
[TestCase(2, 6)]
|
|
[TestCase(2, 10)]
|
|
[TestCase(2, 15)]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPage)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
int nbDemandeFormationDeuxiemePage;
|
|
|
|
switch (parPage)
|
|
{
|
|
case 5:
|
|
nbDemandeFormationDeuxiemePage = 5;
|
|
break;
|
|
case 6:
|
|
nbDemandeFormationDeuxiemePage = 4;
|
|
break;
|
|
case 10:
|
|
nbDemandeFormationDeuxiemePage = 0;
|
|
break;
|
|
default:
|
|
nbDemandeFormationDeuxiemePage = 0;
|
|
break;
|
|
}
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, null, numPage, parPage, null, null, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(nbDemandeFormationDeuxiemePage, demandeFormationDTOs.Count());
|
|
}
|
|
|
|
[TestCase(true, "businessunit")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParBuCroissante(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Orléans", demandeFormationDTOs.First().Collaborateur.BusinessUnit.Nom);
|
|
Assert.AreEqual("Tours", demandeFormationDTOs.Last().Collaborateur.BusinessUnit.Nom);
|
|
}
|
|
|
|
[TestCase(false, "businessunit")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParBuDecroissante(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Tours", demandeFormationDTOs.First().Collaborateur.BusinessUnit.Nom);
|
|
Assert.AreEqual("Orléans", demandeFormationDTOs.Last().Collaborateur.BusinessUnit.Nom);
|
|
|
|
}
|
|
|
|
[TestCase(true, "collaborateur")]
|
|
[TestCase(true, null)]
|
|
[TestCase(true, "toto")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParNomDuCollaborateurCroissant(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Gaillard", demandeFormationDTOs.First().Collaborateur.Nom);
|
|
Assert.AreEqual("Vasseur", demandeFormationDTOs.Last().Collaborateur.Nom);
|
|
|
|
}
|
|
|
|
[TestCase(false, "collaborateur")]
|
|
[TestCase(false, null)]
|
|
[TestCase(false, "toto")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParNomDuCollaborateurDecroissant(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Vasseur", demandeFormationDTOs.First().Collaborateur.Nom);
|
|
Assert.AreEqual("Gaillard", demandeFormationDTOs.Last().Collaborateur.Nom);
|
|
|
|
}
|
|
|
|
[TestCase(true, "datedemande")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParDateDemandeCroissante(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(new DateTime(2020, 1, 22, 9, 0, 0), demandeFormationDTOs.First().DateDemande);
|
|
Assert.AreEqual(new DateTime(2020, 12, 22, 9, 0, 0), demandeFormationDTOs.Last().DateDemande);
|
|
}
|
|
|
|
[TestCase(false, "datedemande")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParDateDemandeDecroissante(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(new DateTime(2020, 12, 22, 9, 0, 0), demandeFormationDTOs.First().DateDemande);
|
|
Assert.AreEqual(new DateTime(2020, 1, 22, 9, 0, 0), demandeFormationDTOs.Last().DateDemande);
|
|
}
|
|
|
|
[TestCase(true, "demanderh")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParDemandeRHCroissant(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.IsFalse(demandeFormationDTOs.First().DemandeRH);
|
|
Assert.IsTrue(demandeFormationDTOs.Last().DemandeRH);
|
|
}
|
|
|
|
[TestCase(false, "demanderh")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParDemandeRHDecroissant(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.IsTrue(demandeFormationDTOs.First().DemandeRH);
|
|
Assert.IsFalse(demandeFormationDTOs.Last().DemandeRH);
|
|
}
|
|
|
|
[TestCase(true, "etat")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParEtatCroissant(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(EtatDemande.EnAttente, demandeFormationDTOs.First().EtatDemande);
|
|
Assert.AreEqual(EtatDemande.Rejetee, demandeFormationDTOs.Last().EtatDemande);
|
|
}
|
|
|
|
[TestCase(false, "etat")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParEtatDecroissant(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(EtatDemande.Rejetee, demandeFormationDTOs.First().EtatDemande);
|
|
Assert.AreEqual(EtatDemande.EnAttente, demandeFormationDTOs.Last().EtatDemande);
|
|
|
|
}
|
|
|
|
[TestCase(true, "datereponse")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParDateDerniereReponseCroissante(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.IsNull(demandeFormationDTOs.First().DateDerniereReponse);
|
|
Assert.AreEqual(new DateTime(2020, 12, 27, 9, 0, 0), demandeFormationDTOs.Last().DateDerniereReponse);
|
|
}
|
|
|
|
[TestCase(false, "datereponse")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamAscEtTri_RetourneDesDemandesDeFormationsOrdonnanceeParDateDerniereReponseDecroissante(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, asc, null, null, null, tri, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(new DateTime(2020, 12, 27, 9, 0, 0), demandeFormationDTOs.First().DateDerniereReponse);
|
|
Assert.IsNull(demandeFormationDTOs.Last().DateDerniereReponse);
|
|
}
|
|
|
|
[TestCase("2020-06-19")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamUneDateDeDebut_RetourneDesDemandesDeFormationsAvecUneDateDeDebutSuperieur(DateTime dateDebut)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, null, null, null, null, null, dateDebut, null);
|
|
|
|
// Assert
|
|
Assert.IsTrue(demandeFormationDTOs.Any(d => d.DateDemande >= dateDebut));
|
|
}
|
|
|
|
[TestCase("2020-05-01")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamUneDateDeFin_RetourneDesDemandesDeFormationsAvecUneDateDeFinInferieur(DateTime dateFin)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, null, null, null, null, null, null, dateFin);
|
|
|
|
// Assert
|
|
Assert.IsTrue(demandeFormationDTOs.Any(d => d.DateDemande <= dateFin));
|
|
}
|
|
|
|
[TestCase("2020-10-01", "2020-12-01")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamUneDateDeDebutEtUneDateDeFin_RetourneDesDemandesDeFormationsAvecUneDateDeDebutSuperieurUneDateDeFinInferieur(DateTime dateDebut, DateTime dateFin)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, null, null, null, null, null, dateDebut, dateFin);
|
|
|
|
// Assert
|
|
Assert.IsTrue(demandeFormationDTOs.Any(d => d.DateDemande >= dateDebut && d.DateDemande <= dateFin));
|
|
}
|
|
|
|
[TestCase("2020-11-01", "2020-10-01")]
|
|
public async Task GetDemandesFormationAsync_PasseEnParamUneDateDeDebutSuperieurEtUneDateDeFinInferieur_RetourneZeroDemandeDeFormation(DateTime dateDebut, DateTime dateFin)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, null, null, null, null, null, null, dateDebut, dateFin);
|
|
|
|
// Assert
|
|
Assert.Zero(demandeFormationDTOs.Count());
|
|
}
|
|
|
|
[TestCase(new long[] { 1, 2 }, "azerty", null, null)]
|
|
[TestCase(new long[] { -1 }, "gaillard", null, null)]
|
|
[TestCase(null, null, "2021-11-01", null)]
|
|
[TestCase(null, null, null, "2019-11-01")]
|
|
public async Task GetDemandesFormationAsync_PasseDesParamsInvalides_RetourneZeroDemandeDeFormation(long[] arrIdBUs, string texte, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
List<long?> idBUs;
|
|
|
|
if (arrIdBUs != null)
|
|
idBUs = arrIdBUs.Select(idBu => (long?)idBu).ToList();
|
|
else
|
|
idBUs = null;
|
|
|
|
// Act
|
|
IEnumerable<DemandeFormationDTO> demandeFormationDTOs = await demandeFormationService.GetDemandesFormationAsync(null, idBUs, null, null, null, texte, null, dateDebut, dateFin);
|
|
|
|
// Assert
|
|
Assert.Zero(demandeFormationDTOs.Count());
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Tests GetDemandesFormationCountAsync
|
|
|
|
[TestCase(new long[] { 1, 2 }, null, null, null)]
|
|
[TestCase(null, "gaillard", null, null)]
|
|
[TestCase(null, null, "2020-10-01", "2020-12-01")]
|
|
[TestCase(null, null, "2020-11-01", null)]
|
|
[TestCase(null, null, null, "2020-11-01")]
|
|
[TestCase(null, null, null, null)]
|
|
public async Task GetDemandesFormationCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDeDemandesDeFormation(long[] arrIdBUs, string texte, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
List<long?> idBUs;
|
|
|
|
if (arrIdBUs != null)
|
|
idBUs = arrIdBUs.Select(idBu => (long?)idBu).ToList();
|
|
else
|
|
idBUs = null;
|
|
|
|
// Act
|
|
long count = await demandeFormationService.GetDemandesFormationCountAsync(null, idBUs, texte, dateDebut, dateFin);
|
|
|
|
// Assert
|
|
Assert.Less(0, count);
|
|
}
|
|
|
|
[TestCase(new long[] { 1, 2 }, "azerty", null, null)]
|
|
[TestCase(new long[] { -1 }, "demande", null, null)]
|
|
[TestCase(null, null, "2021-11-01", null)]
|
|
[TestCase(null, null, null, "2019-11-01")]
|
|
public async Task GetDemandesFormationCountAsync_PasseDesParamsInvalides_RetourneZero(long[] arrIdBUs, string texte, DateTime? dateDebut, DateTime? dateFin)
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
List<long?> idBUs;
|
|
|
|
if (arrIdBUs != null)
|
|
idBUs = arrIdBUs.Select(idBu => (long?)idBu).ToList();
|
|
else
|
|
idBUs = null;
|
|
|
|
// Act
|
|
long count = await demandeFormationService.GetDemandesFormationCountAsync(null, idBUs, texte, dateDebut, dateFin);
|
|
|
|
// Assert
|
|
Assert.AreEqual(0, count);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Tests GetOriginesDemandeFormationAsync
|
|
|
|
[Test]
|
|
public async Task GetOriginesDemandeFormationAsync_RetourneToutesLesOriginesDeDemandeDeFormation()
|
|
{
|
|
// Arrange
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
IEnumerable<OrigineDemandeFormationDTO> origineDemandeFormationDTOs = await demandeFormationService.GetOriginesDemandeFormationAsync();
|
|
|
|
// Assert
|
|
Assert.IsNotNull(origineDemandeFormationDTOs);
|
|
Assert.AreEqual(5, origineDemandeFormationDTOs.Count()); // Nombre total d'origines de demande de formation dans la classe DataSeeder le 2020-03-08
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Tests AddDemandeFormationAsync
|
|
|
|
[Test]
|
|
public async Task AddDemandeFormationAsync_AjouteUneDemandeDeFormationValide_DemandeDeFormationAjouteeAvecSucces()
|
|
{
|
|
// Arrange
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Libelle = "Formation React",
|
|
Description = "Demande de formation React avec Redux",
|
|
DemandeRH = true,
|
|
DateDemande = DateTime.Now,
|
|
EtatDemande = EtatDemande.EnAttente,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
DemandeFormationDTO demandeDeFormationAjoute = await demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Vérifie si la nouvelle demande de formation est bien liée au prochain EP du collaborateur Lemoine Coty
|
|
Ep ep = await epContext.Ep.FirstOrDefaultAsync(e => e.IdEP == 12);
|
|
bool exist = ep.DemandesFormation.Any(d => d.IdDemandeFormation == 13);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(demandeDeFormationAjoute);
|
|
Assert.AreEqual(13, demandeDeFormationAjoute.Id);
|
|
Assert.AreEqual(demandeFormation.Libelle, demandeDeFormationAjoute.Libelle);
|
|
Assert.AreEqual(demandeFormation.Description, demandeDeFormationAjoute.Description);
|
|
Assert.AreEqual(demandeFormation.DemandeRH, demandeDeFormationAjoute.DemandeRH);
|
|
Assert.AreEqual(demandeFormation.DateDemande, demandeDeFormationAjoute.DateDemande);
|
|
Assert.AreEqual(demandeFormation.EtatDemande, demandeDeFormationAjoute.EtatDemande);
|
|
Assert.AreEqual(demandeFormation.Origine, demandeDeFormationAjoute.Origine);
|
|
Assert.AreEqual(demandeFormation.Collaborateur.Id, demandeDeFormationAjoute.Collaborateur.Id);
|
|
Assert.AreEqual(demandeFormation.Collaborateur.Nom, demandeDeFormationAjoute.Collaborateur.Nom);
|
|
Assert.AreEqual(demandeFormation.Collaborateur.Prenom, demandeDeFormationAjoute.Collaborateur.Prenom);
|
|
Assert.IsTrue(exist);
|
|
}
|
|
|
|
[Test]
|
|
public void AddDemandeFormationAsync_AjouteUneDemandeDeFormationNull_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
|
|
// Arrange
|
|
DemandeFormationDTO demandeFormation = null;
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[TestCase("", "Demande de formation React avec Redux", true, "2021-03-10")]
|
|
[TestCase("Formation React", "", true, "2021-03-10")]
|
|
[TestCase("Formation React", "Demande de formation React avec Redux", null, "2021-03-10")]
|
|
[TestCase("Formation React", "Demande de formation React avec Redux", true, null)]
|
|
public void AddDemandeFormationAsync_AjouteUneDemandeDeFormationAvecDesProprietesInvalides_LeveUneDemandeFormationInvalidException(string libelle, string description, bool? demandeRH, DateTime? dateDemande)
|
|
{
|
|
|
|
// Arrange
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Libelle = libelle,
|
|
Description = description,
|
|
DemandeRH = demandeRH,
|
|
DateDemande = dateDemande,
|
|
EtatDemande = EtatDemande.EnAttente,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void AddDemandeFormationAsync__AjouteUneDemandeDeFormationQuiNestPasEnAttente_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Libelle = "Formation React",
|
|
Description = "Demande de formation React avec Redux",
|
|
DemandeRH = true,
|
|
DateDemande = DateTime.Now,
|
|
EtatDemande = EtatDemande.Validee,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void AddDemandeFormationAsync_AjouteUneDemandeDeFormationAvecUnCollaborateurNull_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = null;
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Libelle = "Formation React",
|
|
Description = "Demande de formation React avec Redux",
|
|
DemandeRH = true,
|
|
DateDemande = DateTime.Now,
|
|
EtatDemande = EtatDemande.EnAttente,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void AddDemandeFormationAsync_AjouteUneDemandeDeFormationAvecUnIdCollaborateurNull_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = null,
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Libelle = "Formation React",
|
|
Description = "Demande de formation React avec Redux",
|
|
DemandeRH = true,
|
|
DateDemande = DateTime.Now,
|
|
EtatDemande = EtatDemande.EnAttente,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void AddDemandeFormationAsync_AjouteUneDemandeDeFormationAvecUneOrigineNull_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = null;
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Libelle = "Formation React",
|
|
Description = "Demande de formation React avec Redux",
|
|
DemandeRH = true,
|
|
DateDemande = DateTime.Now,
|
|
EtatDemande = EtatDemande.EnAttente,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void AddDemandeFormationAsync_AjouteUneDemandeDeFormationAvecUnIdOrigineNull_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = null, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Libelle = "Formation React",
|
|
Description = "Demande de formation React avec Redux",
|
|
DemandeRH = true,
|
|
DateDemande = DateTime.Now,
|
|
EtatDemande = EtatDemande.EnAttente,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void AddDemandeFormationAsync_AjouteUneDemandeDeFormationQuiEstLieeAUnEpSigne_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("301ba7f3-095e-4912-8998-a7c942dc5f23"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 1, Nom = "Tours", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Rousseau",
|
|
Prenom = "Lamar",
|
|
MailApside = "lamar.rousseau@apside-groupe.com",
|
|
DateArrivee = new DateTime(2020, 8, 1, 13, 21, 39, 799),
|
|
DateDepart = null,
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Libelle = "Formation React",
|
|
Description = "Demande de formation React avec Redux",
|
|
DemandeRH = true,
|
|
DateDemande = DateTime.Now,
|
|
EtatDemande = EtatDemande.EnAttente,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.AddDemandeFormationAsync(demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Tests UpdateDemandeFormationAsync
|
|
|
|
[Test]
|
|
public async Task UpdateDemandeFormationAsync_AccepteUneDemandeDeDemandeFormationEtAjouteLeParticipantALaListeDesParticipantsVide_DemandeAccepteeAvecSucces()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 1;
|
|
int nbParticipant = 0;
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = 1,
|
|
Intitule = "Formation Mainframe Complète",
|
|
DateDebut = new DateTime(2020, 1, 25, 10, 0, 0),
|
|
DateFin = new DateTime(2020, 1, 27),
|
|
Organisme = "Organisme1",
|
|
Origine = new OrigineFormationDTO { Id = 2, Libelle = "Exigence client" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = false,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation Cobol",
|
|
Description = "Demande de formation Cobol avec Mainframe",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 1, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Validee,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
DemandeFormationDTO demandeFormationAcceptee = await demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
bool participationFormationCree = await epContext.ParticipationFormation.Include(p => p.DemandeFormation).AnyAsync(p => p.DemandeFormation.IdDemandeFormation == idDemandeFormation);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(demandeFormationAcceptee);
|
|
Assert.AreEqual(idDemandeFormation, demandeFormationAcceptee.Id);
|
|
Assert.AreEqual(demandeFormation.Libelle, demandeFormationAcceptee.Libelle);
|
|
Assert.AreEqual(demandeFormation.Description, demandeFormationAcceptee.Description);
|
|
Assert.AreEqual(demandeFormation.EtatDemande, demandeFormationAcceptee.EtatDemande);
|
|
Assert.IsNotNull(demandeFormationAcceptee.DateDerniereReponse);
|
|
Assert.IsTrue(participationFormationCree);
|
|
Assert.Less(nbParticipant, demandeFormationAcceptee.Formation.NbParticipations);
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateDemandeFormationAsync_AccepteUneDemandeDeDemandeFormationEtAjouteLeParticipantALaListeDesParticipantsNonVide_DemandeAccepteeAvecSucces()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 3;
|
|
int nbParticipant = 1;
|
|
OrigineDemandeFormationDTO origineDemandeFormationClient = new OrigineDemandeFormationDTO { Id = 3, Libelle = "Exigence Client" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("a0f40e2a-cc03-4032-a627-5389e1281c64"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Vasseur",
|
|
Prenom = "Florencio",
|
|
MailApside = "florencio.vasseur@apside-groupe.com",
|
|
DateArrivee = new DateTime(2016, 1, 15, 10, 22, 30, 778),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = 3,
|
|
Intitule = "Apprendre C# et le développement de logiciels avec WPF",
|
|
DateDebut = new DateTime(2020, 5, 25, 14, 0, 0),
|
|
DateFin = new DateTime(2020, 5, 27),
|
|
Organisme = "Organisme2",
|
|
Origine = new OrigineFormationDTO { Id = 3, Libelle = "Exigence Apside" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = true,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 3, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Validee,
|
|
Origine = origineDemandeFormationClient,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
DemandeFormationDTO demandeFormationAcceptee = await demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
bool participationFormationCree = await epContext.ParticipationFormation.Include(p => p.DemandeFormation).AnyAsync(p => p.DemandeFormation.IdDemandeFormation == idDemandeFormation);
|
|
|
|
|
|
// Assert
|
|
Assert.IsNotNull(demandeFormationAcceptee);
|
|
Assert.AreEqual(idDemandeFormation, demandeFormationAcceptee.Id);
|
|
Assert.AreEqual(demandeFormation.Libelle, demandeFormationAcceptee.Libelle);
|
|
Assert.AreEqual(demandeFormation.Description, demandeFormationAcceptee.Description);
|
|
Assert.AreEqual(demandeFormation.EtatDemande, demandeFormationAcceptee.EtatDemande);
|
|
Assert.IsNotNull(demandeFormationAcceptee.DateDerniereReponse);
|
|
Assert.IsTrue(participationFormationCree);
|
|
Assert.Less(nbParticipant, demandeFormationAcceptee.Formation.NbParticipations);
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateDemandeFormationAsync_MettreAJourUneDemandeEnAttente_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 1;
|
|
int nbParticipant = 0;
|
|
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = 1,
|
|
Intitule = "Formation Mainframe Complète",
|
|
DateDebut = new DateTime(2020, 1, 25, 10, 0, 0),
|
|
DateFin = new DateTime(2020, 1, 27),
|
|
Organisme = "Organisme1",
|
|
Origine = new OrigineFormationDTO { Id = 2, Libelle = "Exigence client" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = false,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation Cobol",
|
|
Description = "Demande de formation Cobol avec Mainframe",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 1, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.EnAttente,
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateDemandeFormationAsync_AccepteUneDemandeAvecUnIdIncorrecte_LeveUneDemandeFormationIncompatibleIdException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 1;
|
|
long idDemandeFormationIncorrecte = 0;
|
|
int nbParticipant = 1;
|
|
OrigineDemandeFormationDTO origineDemandeFormationClient = new OrigineDemandeFormationDTO { Id = 3, Libelle = "Exigence Client" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("a0f40e2a-cc03-4032-a627-5389e1281c64"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Vasseur",
|
|
Prenom = "Florencio",
|
|
MailApside = "florencio.vasseur@apside-groupe.com",
|
|
DateArrivee = new DateTime(2016, 1, 15, 10, 22, 30, 778),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = 3,
|
|
Intitule = "Apprendre C# et le développement de logiciels avec WPF",
|
|
DateDebut = new DateTime(2020, 5, 25, 14, 0, 0),
|
|
DateFin = new DateTime(2020, 5, 27),
|
|
Organisme = "Organisme2",
|
|
Origine = new OrigineFormationDTO { Id = 3, Libelle = "Exigence Apside" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = true,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormationIncorrecte,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 3, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Validee,
|
|
Origine = origineDemandeFormationClient,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationIncompatibleIdException), throwException);
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateDemandeFormationAsync_AccepteUneDemandeAvecUnIdDemandeFormationNull_LeveUneDemandeFormationIncompatibleIdException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 1;
|
|
long? idDemandeFormationIncorrecte = null;
|
|
int nbParticipant = 1;
|
|
OrigineDemandeFormationDTO origineDemandeFormationClient = new OrigineDemandeFormationDTO { Id = 3, Libelle = "Exigence Client" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("a0f40e2a-cc03-4032-a627-5389e1281c64"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Vasseur",
|
|
Prenom = "Florencio",
|
|
MailApside = "florencio.vasseur@apside-groupe.com",
|
|
DateArrivee = new DateTime(2016, 1, 15, 10, 22, 30, 778),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = 3,
|
|
Intitule = "Apprendre C# et le développement de logiciels avec WPF",
|
|
DateDebut = new DateTime(2020, 5, 25, 14, 0, 0),
|
|
DateFin = new DateTime(2020, 5, 27),
|
|
Organisme = "Organisme2",
|
|
Origine = new OrigineFormationDTO { Id = 3, Libelle = "Exigence Apside" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = true,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormationIncorrecte,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 3, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Validee,
|
|
Origine = origineDemandeFormationClient,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationIncompatibleIdException), throwException);
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateDemandeFormationAsync_AccepteUneDemandeInexistante_LeveUneDemandeFormationNotFoundException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 0;
|
|
int nbParticipant = 1;
|
|
OrigineDemandeFormationDTO origineDemandeFormationClient = new OrigineDemandeFormationDTO { Id = 3, Libelle = "Exigence Client" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("a0f40e2a-cc03-4032-a627-5389e1281c64"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Vasseur",
|
|
Prenom = "Florencio",
|
|
MailApside = "florencio.vasseur@apside-groupe.com",
|
|
DateArrivee = new DateTime(2016, 1, 15, 10, 22, 30, 778),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = 3,
|
|
Intitule = "Apprendre C# et le développement de logiciels avec WPF",
|
|
DateDebut = new DateTime(2020, 5, 25, 14, 0, 0),
|
|
DateFin = new DateTime(2020, 5, 27),
|
|
Organisme = "Organisme2",
|
|
Origine = new OrigineFormationDTO { Id = 3, Libelle = "Exigence Apside" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = true,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 3, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Validee,
|
|
Origine = origineDemandeFormationClient,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationNotFoundException), throwException);
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateDemandeFormationAsync_AccepteUneDemandeAvecUneFormationNull_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 3;
|
|
OrigineDemandeFormationDTO origineDemandeFormationClient = new OrigineDemandeFormationDTO { Id = 3, Libelle = "Exigence Client" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("a0f40e2a-cc03-4032-a627-5389e1281c64"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Vasseur",
|
|
Prenom = "Florencio",
|
|
MailApside = "florencio.vasseur@apside-groupe.com",
|
|
DateArrivee = new DateTime(2016, 1, 15, 10, 22, 30, 778),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = null;
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 3, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Validee,
|
|
Origine = origineDemandeFormationClient,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateDemandeFormationAsync_AccepteUneDemandeAvecUnIdFormationNull_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 3;
|
|
long? idFormation = null;
|
|
int nbParticipant = 1;
|
|
OrigineDemandeFormationDTO origineDemandeFormationClient = new OrigineDemandeFormationDTO { Id = 3, Libelle = "Exigence Client" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("a0f40e2a-cc03-4032-a627-5389e1281c64"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Vasseur",
|
|
Prenom = "Florencio",
|
|
MailApside = "florencio.vasseur@apside-groupe.com",
|
|
DateArrivee = new DateTime(2016, 1, 15, 10, 22, 30, 778),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = idFormation,
|
|
Intitule = "Apprendre C# et le développement de logiciels avec WPF",
|
|
DateDebut = new DateTime(2020, 5, 25, 14, 0, 0),
|
|
DateFin = new DateTime(2020, 5, 27),
|
|
Organisme = "Organisme2",
|
|
Origine = new OrigineFormationDTO { Id = 3, Libelle = "Exigence Apside" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = true,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 3, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Validee,
|
|
Origine = origineDemandeFormationClient,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateDemandeFormationAsync_RefuseUneDemandeDeFormationEnAttente_DemandeRefuseeAvecSucces()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 1;
|
|
OrigineDemandeFormationDTO origineDemandeFormationApside = new OrigineDemandeFormationDTO { Id = 5, Libelle = "Demande Apside" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation Cobol",
|
|
Description = "Demande de formation Cobol avec Mainframe",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 1, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Rejetee,
|
|
CommentaireRefus= "Formation indisponible pour le moment",
|
|
Origine = origineDemandeFormationApside,
|
|
Collaborateur = collaborateur
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
DemandeFormationDTO demandeFormationAcceptee = await demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
bool participationFormationExistante = await epContext.ParticipationFormation.Include(p => p.DemandeFormation).AnyAsync(p => p.DemandeFormation.IdDemandeFormation == idDemandeFormation);
|
|
|
|
|
|
// Assert
|
|
Assert.IsNotNull(demandeFormationAcceptee);
|
|
Assert.AreEqual(idDemandeFormation, demandeFormationAcceptee.Id);
|
|
Assert.AreEqual(demandeFormation.Libelle, demandeFormationAcceptee.Libelle);
|
|
Assert.AreEqual(demandeFormation.Description, demandeFormationAcceptee.Description);
|
|
Assert.AreEqual(demandeFormation.EtatDemande, demandeFormationAcceptee.EtatDemande);
|
|
Assert.IsNotNull(demandeFormationAcceptee.DateDerniereReponse);
|
|
Assert.IsFalse(participationFormationExistante);
|
|
}
|
|
|
|
[Test]
|
|
public async Task UpdateDemandeFormationAsync_RefuseUneDemandeDeFormationAccepteeEtSupprimeLaParticipation_DemandeRefuseeAvecSucces()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 5;
|
|
int nbParticipant = 1;
|
|
OrigineDemandeFormationDTO origineDemandeFormationEP = new OrigineDemandeFormationDTO { Id = 2, Libelle = "Demande EP" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Lemoine",
|
|
Prenom = "Coty",
|
|
MailApside = "coty.lemoine@apside-groupe.com",
|
|
DateArrivee = new DateTime(2017, 2, 10, 20, 37, 58, 741),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = 3,
|
|
Intitule = "Apprendre C# et le développement de logiciels avec WPF",
|
|
DateDebut = new DateTime(2020, 5, 25, 14, 0, 0),
|
|
DateFin = new DateTime(2020, 5, 27),
|
|
Organisme = "Organisme2",
|
|
Origine = new OrigineFormationDTO { Id = 3, Libelle = "Exigence Apside" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = true,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 5, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Rejetee,
|
|
CommentaireRefus = "Formation indisponible pour le moment",
|
|
Origine = origineDemandeFormationEP,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
DemandeFormationDTO demandeFormationAcceptee = await demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
bool participationFormationExistante = await epContext.ParticipationFormation.Include(p => p.DemandeFormation).AnyAsync(p => p.DemandeFormation.IdDemandeFormation == idDemandeFormation);
|
|
|
|
|
|
// Assert
|
|
Assert.IsNotNull(demandeFormationAcceptee);
|
|
Assert.AreEqual(idDemandeFormation, demandeFormationAcceptee.Id);
|
|
Assert.AreEqual(demandeFormation.Libelle, demandeFormationAcceptee.Libelle);
|
|
Assert.AreEqual(demandeFormation.Description, demandeFormationAcceptee.Description);
|
|
Assert.AreEqual(demandeFormation.EtatDemande, demandeFormationAcceptee.EtatDemande);
|
|
Assert.IsNotNull(demandeFormationAcceptee.DateDerniereReponse);
|
|
Assert.IsFalse(participationFormationExistante);
|
|
Assert.Greater(nbParticipant, demandeFormationAcceptee.Formation.NbParticipations);
|
|
}
|
|
|
|
[TestCase(null)]
|
|
[TestCase("")]
|
|
[TestCase(" ")]
|
|
public void UpdateDemandeFormationAsync_RefuseUneDemandeSansCommentaireRefus_LeveUneDemandeFormationInvalidException(string commentaireRefus)
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 3;
|
|
OrigineDemandeFormationDTO origineDemandeFormationClient = new OrigineDemandeFormationDTO { Id = 3, Libelle = "Exigence Client" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("a0f40e2a-cc03-4032-a627-5389e1281c64"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Vasseur",
|
|
Prenom = "Florencio",
|
|
MailApside = "florencio.vasseur@apside-groupe.com",
|
|
DateArrivee = new DateTime(2016, 1, 15, 10, 22, 30, 778),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = null;
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 3, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Rejetee,
|
|
CommentaireRefus = commentaireRefus,
|
|
Origine = origineDemandeFormationClient,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
|
|
}
|
|
|
|
[Test]
|
|
public void UpdateDemandeFormationAsync_RefuseUneDemandeInexistante_LeveUneDemandeFormationNotFoundException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 0;
|
|
int nbParticipant = 1;
|
|
OrigineDemandeFormationDTO origineDemandeFormationClient = new OrigineDemandeFormationDTO { Id = 3, Libelle = "Exigence Client" };
|
|
|
|
List<BusinessUnitDTO> Bus = new List<BusinessUnitDTO>() {
|
|
new BusinessUnitDTO { Id = 1, Nom = "Tours" },
|
|
new BusinessUnitDTO { Id = 2, Nom = "Orléans" },
|
|
};
|
|
|
|
CollaborateurDTO collaborateur = new CollaborateurDTO
|
|
{
|
|
Id = Guid.Parse("a0f40e2a-cc03-4032-a627-5389e1281c64"),
|
|
BusinessUnit = new BusinessUnitDTO { Id = 2, Nom = "Orléans", Agence = new AgenceDTO { Id = 1, Nom = "TOP", Bu = Bus } },
|
|
Nom = "Vasseur",
|
|
Prenom = "Florencio",
|
|
MailApside = "florencio.vasseur@apside-groupe.com",
|
|
DateArrivee = new DateTime(2016, 1, 15, 10, 22, 30, 778),
|
|
DateDepart = null,
|
|
};
|
|
|
|
FormationDetailsDTO formation = new FormationDetailsDTO
|
|
{
|
|
Id = 3,
|
|
Intitule = "Apprendre C# et le développement de logiciels avec WPF",
|
|
DateDebut = new DateTime(2020, 5, 25, 14, 0, 0),
|
|
DateFin = new DateTime(2020, 5, 27),
|
|
Organisme = "Organisme2",
|
|
Origine = new OrigineFormationDTO { Id = 3, Libelle = "Exigence Apside" },
|
|
Statut = new StatutFormationDTO { Id = 1, Libelle = "Planifiée" },
|
|
EstCertifiee = true,
|
|
NbParticipations = nbParticipant
|
|
};
|
|
|
|
DemandeFormationDTO demandeFormation = new DemandeFormationDTO
|
|
{
|
|
Id = idDemandeFormation,
|
|
Libelle = "Formation C#",
|
|
Description = "Demande de formation C# avec WPF",
|
|
DemandeRH = false,
|
|
DateDemande = new DateTime(2020, 3, 22, 9, 0, 0),
|
|
EtatDemande = EtatDemande.Rejetee,
|
|
CommentaireRefus = "Formation indisponible pour le moment",
|
|
Origine = origineDemandeFormationClient,
|
|
Collaborateur = collaborateur,
|
|
Formation = formation,
|
|
};
|
|
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.UpdateDemandeFormationAsync(idDemandeFormation, demandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationNotFoundException), throwException);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Tests DeleteDemandeFormationAsync
|
|
|
|
[Test]
|
|
public async Task DeleteDemandeFormationAsync_SupprimeUneDemandeDeFormation_DemandeDeFormationSupprimeeAvecSucces()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 5;
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
bool demandeFormationSupprimee = await demandeFormationService.DeleteDemandeFormationAsync(idDemandeFormation);
|
|
bool demandeRetireeDansEp = await epContext.Ep.Include(e => e.DemandesFormation).AnyAsync(e => e.DemandesFormation.Any(d => d.IdDemandeFormation == idDemandeFormation));
|
|
bool demandeRetireeDansParticipation = await epContext.ParticipationFormation.Include(p => p.DemandeFormation).AnyAsync(p => p.DemandeFormation.IdDemandeFormation == idDemandeFormation);
|
|
bool demandeFormationExiste = await epContext.DemandeFormation.AnyAsync(d => d.IdDemandeFormation == idDemandeFormation);
|
|
|
|
// Assert
|
|
Assert.IsTrue(demandeFormationSupprimee);
|
|
Assert.IsFalse(demandeRetireeDansEp);
|
|
Assert.IsFalse(demandeRetireeDansParticipation);
|
|
Assert.IsFalse(demandeFormationExiste);
|
|
}
|
|
|
|
[Test]
|
|
public void DeleteDemandeFormationAsync_SupprimeUneDemandeDeFormationInexistante_LeveUneDemandeFormationNotFoundException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 0;
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.DeleteDemandeFormationAsync(idDemandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationNotFoundException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void DeleteDemandeFormationAsync_SupprimeUneDemandeDeFormationConcernantUnEpSigne_LeveUneDemandeFormationInvalidException()
|
|
{
|
|
// Arrange
|
|
long idDemandeFormation = 2;
|
|
DemandeFormationService demandeFormationService = new DemandeFormationService(epContext, collaborateurService, transformDTO);
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => demandeFormationService.DeleteDemandeFormationAsync(idDemandeFormation);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(DemandeFormationInvalidException), throwException);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |