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.
636 lines
29 KiB
636 lines
29 KiB
using EPAServeur.Context;
|
|
using EPAServeur.Exceptions;
|
|
using EPAServeur.IServices;
|
|
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 EngagementServiceTests
|
|
{
|
|
#region Variables
|
|
|
|
private EpContext epContext;
|
|
private ICollaborateurApi collaborateurApi;
|
|
private ICollaborateurService collaborateurService;
|
|
#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();
|
|
collaborateurService = new CollaborateurService(collaborateurApi, epContext);
|
|
epContext.Database.EnsureDeleted();
|
|
epContext.Database.EnsureCreated();
|
|
epContext.SaveChanges();
|
|
|
|
// Ajout du jeu de données pour les tests
|
|
DataSeeder.AddEngagements(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 GetEngagementsAsync
|
|
|
|
[TestCase(new long[] { 1, 2 })]
|
|
public async Task GetEngagementsAsync_PasseDesParamsDesIdBUValides_RetourneDesEngagements(long[] arrIdBUs)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = arrIdBUs.Select(x => x).ToList();
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, null, null, null, null, null);
|
|
|
|
// Assert
|
|
Assert.Less(0, engagementDTOs.Count());
|
|
}
|
|
|
|
[TestCase(new EtatEngagement[] { EtatEngagement.EnAttente, EtatEngagement.Respecte })]
|
|
[TestCase(new EtatEngagement[] { EtatEngagement.DateLimitePassee })]
|
|
public async Task GetEngagementsAsync_PasseDesParamsDesEtatsDEngagementsValides_RetourneDesEngagements(EtatEngagement[] arrEtatsEngagement)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
List<EtatEngagement> etatEngagements = arrEtatsEngagement.Select(x => x).ToList();
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, etatEngagements, null, null, null, null, null);
|
|
|
|
// Assert
|
|
Assert.Less(0, engagementDTOs.Count());
|
|
}
|
|
|
|
[TestCase(1, 5)]
|
|
[TestCase(1, 10)]
|
|
public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesEngagements(int? numPage, int? parPage)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, null, numPage, parPage, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(parPage, engagementDTOs.Count());
|
|
}
|
|
|
|
[TestCase(2, 5)]
|
|
[TestCase(2, 6)]
|
|
[TestCase(2, 10)]
|
|
[TestCase(2, 15)]
|
|
public async Task GetEngagementsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPage)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
int? nbEngagementDeuxiemePage;
|
|
|
|
switch (parPage)
|
|
{
|
|
case 5:
|
|
nbEngagementDeuxiemePage = 5;
|
|
break;
|
|
case 6:
|
|
nbEngagementDeuxiemePage = 6;
|
|
break;
|
|
case 10:
|
|
nbEngagementDeuxiemePage = 2;
|
|
break;
|
|
default:
|
|
nbEngagementDeuxiemePage = 0;
|
|
break;
|
|
}
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, null, numPage, parPage, null, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(nbEngagementDeuxiemePage, engagementDTOs.Count());
|
|
}
|
|
|
|
[TestCase(true, "action")]
|
|
[TestCase(true, null)]
|
|
[TestCase(true, "toto")]
|
|
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionCroissant(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, asc, null, null, null, tri);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Je m'engage à attribuer 5 jours de congés supplémentaire.", engagementDTOs.First().Action);
|
|
Assert.AreEqual("Je m'engage à trouver une formation sur le Cobol.", engagementDTOs.Last().Action);
|
|
}
|
|
|
|
[TestCase(false, "action")]
|
|
[TestCase(false, null)]
|
|
[TestCase(false, "toto")]
|
|
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParActionDecroissant(bool? asc, string tri)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, asc, null, null, null, tri);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Je m'engage à trouver une formation sur le Cobol.", engagementDTOs.First().Action);
|
|
Assert.AreEqual("Je m'engage à attribuer 5 jours de congés supplémentaire.", engagementDTOs.Last().Action);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifCroissant()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
bool? asc = true;
|
|
string tri = "dispositif";
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, asc, null, null, null, tri);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Contacter le client pour planifier un rendez-vous.", engagementDTOs.First().Dispositif);
|
|
Assert.AreEqual("Planifier un point hebdomadaire sur Teams.", engagementDTOs.Last().Dispositif);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDispositifDecroissant()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
bool? asc = false;
|
|
string tri = "dispositif";
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, asc, null, null, null, tri);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Planifier un point hebdomadaire sur Teams.", engagementDTOs.First().Dispositif);
|
|
Assert.AreEqual("Contacter le client pour planifier un rendez-vous.", engagementDTOs.Last().Dispositif);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteCroissante()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
bool? asc = true;
|
|
string tri = "modalite";
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, asc, null, null, null, tri);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Hors temps", engagementDTOs.First().Modalite);
|
|
Assert.AreEqual("Sur temps de travail", engagementDTOs.Last().Modalite);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParModaliteDecroissante()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
bool? asc = false;
|
|
string tri = "modalite";
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, asc, null, null, null, tri);
|
|
|
|
// Assert
|
|
Assert.AreEqual("Sur temps de travail", engagementDTOs.First().Modalite);
|
|
Assert.AreEqual("Hors temps", engagementDTOs.Last().Modalite);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateCroissante()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
bool? asc = true;
|
|
string tri = "date";
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, asc, null, null, null, tri);
|
|
|
|
// Assert
|
|
Assert.AreEqual(new DateTime(2020, 9, 1), engagementDTOs.First().DateLimite);
|
|
Assert.AreEqual(new DateTime(2021, 1, 31), engagementDTOs.Last().DateLimite);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetEngagementsAsync_PasseEnParamAscEtTri_RetourneDesEngagementsOrdonnancesParDateDecroissante()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>() { 1, 2, 3 };
|
|
bool? asc = false;
|
|
string tri = "date";
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, asc, null, null, null, tri);
|
|
|
|
// Assert
|
|
Assert.AreEqual(new DateTime(2021, 1, 31), engagementDTOs.First().DateLimite);
|
|
Assert.AreEqual(new DateTime(2020, 9, 1), engagementDTOs.Last().DateLimite);
|
|
}
|
|
|
|
[TestCase(new long[] { 0 }, null )]
|
|
[TestCase(new long[] { 4 }, null)]
|
|
[TestCase(new long[] { 1, 2 }, "azerty")]
|
|
|
|
public async Task GetEngagementsAsync_PasseDesParamsInvalides_RetourneZeroEngagement(long[] arrIdBUs, string texte)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs;
|
|
|
|
if (arrIdBUs != null)
|
|
idBUs = arrIdBUs.Select(x => x).ToList();
|
|
else
|
|
idBUs = new List<long>();
|
|
|
|
// Act
|
|
IEnumerable<EngagementDTO> engagementDTOs = await engagementService.GetEngagementsAsync(idBUs, null, null, null, null, texte, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(0, engagementDTOs.Count());
|
|
}
|
|
|
|
[Test]
|
|
public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUVide_LeveUneEngagementInvalidException()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = new List<long>();
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => engagementService.GetEngagementsAsync(idBUs, null, null, null, null, null, null);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(EngagementInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void GetEngagementsAsync_PasseDesParamsUneListeDIdsBUNull_LeveUneEngagementInvalidException()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs = null;
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => engagementService.GetEngagementsAsync(idBUs, null, null, null, null, null, null);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(EngagementInvalidException), throwException);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Tests GetEngagementsCountAsync
|
|
|
|
[TestCase(new long[] { 1, 2, 3 }, "formation")]
|
|
[TestCase(new long[] { 1 }, null)]
|
|
public async Task GetEngagementsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDEngagements(long[] arrIdBUs, string texte)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs;
|
|
|
|
if (arrIdBUs != null)
|
|
idBUs = arrIdBUs.Select(x => x).ToList();
|
|
else
|
|
idBUs = new List<long>();
|
|
|
|
// Act
|
|
long count = await engagementService.GetEngagementsCountAsync(idBUs, null, null, null, null, texte, null);
|
|
|
|
// Assert
|
|
Assert.Less(0, count);
|
|
}
|
|
|
|
[TestCase(new long[] { 0 }, null)]
|
|
[TestCase(new long[] { 4 }, null)]
|
|
[TestCase(new long[] { 1, 2 }, "azerty")]
|
|
public async Task GetEngagementsCountAsync_PasseDesParamsInvalides_RetourneZero(long[] arrIdBUs, string texte)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
List<long> idBUs;
|
|
|
|
if (arrIdBUs != null)
|
|
idBUs = arrIdBUs.Select(x => x).ToList();
|
|
else
|
|
idBUs = new List<long>();
|
|
|
|
// Act
|
|
long count = await engagementService.GetEngagementsCountAsync(idBUs, null, null, null, null, texte, null);
|
|
|
|
// Assert
|
|
Assert.AreEqual(0, count);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Tests RepondreEngagementAsync
|
|
|
|
[TestCase(1, 9, EtatEngagement.Respecte, null)]
|
|
[TestCase(1, 9, EtatEngagement.EnAttente, null)]
|
|
[TestCase(2, 9, EtatEngagement.NonRealisable, "Impossible de respecter cet engagement car hors budget.")]
|
|
public async Task RepondreEngagementAsync_ModifieUnEngagementValide_EngagementModifieAvecSucces(long idEngagement, long idEp, EtatEngagement etatEngagement, string raisonNonRealisable)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
|
|
EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
|
|
.Select(ep => new EpInformationDTO
|
|
{
|
|
Id = ep.IdEP,
|
|
Type = ep.TypeEP,
|
|
Statut = ep.Statut,
|
|
DateDisponibilite = ep.DateDisponibilite,
|
|
DatePrevisionnelle = ep.DatePrevisionnelle,
|
|
Obligatoire = ep.Obligatoire
|
|
}).FirstOrDefault();
|
|
|
|
EngagementDTO engagementDTO =new EngagementDTO
|
|
{
|
|
Id = idEngagement,
|
|
Action = "Je m'engage à trouver une formation sur l'Asp.Net Core.",
|
|
Dispositif = "Demande de formation RH.",
|
|
Modalite = "Sur temps de travail",
|
|
DateLimite = new DateTime(2020, 9, 1),
|
|
EtatEngagement = etatEngagement,
|
|
RaisonNonRealisable = raisonNonRealisable,
|
|
Ep = epInformationDTO
|
|
};
|
|
|
|
// Act
|
|
EngagementDTO engagementModifie = await engagementService.RepondreEngagementAsync(engagementDTO, idEngagement);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(engagementModifie);
|
|
Assert.AreEqual(idEngagement, engagementModifie.Id);
|
|
Assert.AreEqual(engagementDTO.Id, engagementModifie.Id);
|
|
Assert.AreEqual(engagementDTO.EtatEngagement, engagementModifie.EtatEngagement);
|
|
Assert.AreEqual(engagementDTO.RaisonNonRealisable, engagementModifie.RaisonNonRealisable);
|
|
}
|
|
|
|
[Test]
|
|
public async Task RepondreEngagementAsync_ModifieUnEngagementAvecUneDateLimitePasseeValide_EngagementModifieAvecSucces()
|
|
{
|
|
long idEngagement = 3;
|
|
long idEp = 9;
|
|
EtatEngagement etatEngagement = EtatEngagement.DateLimitePassee;
|
|
string raisonNonRealisableAvantUpdate = null;
|
|
string raisonNonRealisableApresUpdate = "La date limite pour respecter l'engagement est passée.";
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
|
|
EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
|
|
.Select(ep => new EpInformationDTO
|
|
{
|
|
Id = ep.IdEP,
|
|
Type = ep.TypeEP,
|
|
Statut = ep.Statut,
|
|
DateDisponibilite = ep.DateDisponibilite,
|
|
DatePrevisionnelle = ep.DatePrevisionnelle,
|
|
Obligatoire = ep.Obligatoire
|
|
}).FirstOrDefault();
|
|
|
|
EngagementDTO engagementDTO = new EngagementDTO
|
|
{
|
|
Id = idEngagement,
|
|
Action = "Je m'engage à trouver une formation sur l'Asp.Net Core.",
|
|
Dispositif = "Demande de formation RH.",
|
|
Modalite = "Sur temps de travail",
|
|
DateLimite = new DateTime(2020, 9, 1),
|
|
EtatEngagement = etatEngagement,
|
|
RaisonNonRealisable = raisonNonRealisableAvantUpdate,
|
|
Ep = epInformationDTO
|
|
};
|
|
|
|
// Act
|
|
EngagementDTO engagementModifie = await engagementService.RepondreEngagementAsync(engagementDTO, idEngagement);
|
|
|
|
// Assert
|
|
Assert.IsNotNull(engagementModifie);
|
|
Assert.AreEqual(idEngagement, engagementModifie.Id);
|
|
Assert.AreEqual(engagementDTO.Id, engagementModifie.Id);
|
|
Assert.AreEqual(engagementDTO.EtatEngagement, engagementModifie.EtatEngagement);
|
|
Assert.AreEqual(raisonNonRealisableApresUpdate, engagementModifie.RaisonNonRealisable);
|
|
}
|
|
|
|
[TestCase(1, 0, "Je m'engage à trouver une formation sur l'Asp.Net Core.", "Demande de formation RH.", "Sur temps de travail", "2020-9-11", EtatEngagement.Respecte, null)]
|
|
[TestCase(1, 11, "Je m'engage à trouver une formation sur l'Asp.Net Core.", "Demande de formation RH.", "Sur temps de travail", "2020-9-11", EtatEngagement.Respecte, null)]
|
|
[TestCase(1, 9, "", "Demande de formation RH.", "Sur temps de travail", "2020-9-11", EtatEngagement.Respecte, null)]
|
|
[TestCase(1, 9, "Je m'engage à trouver une formation sur l'Asp.Net Core.", "", "Sur temps de travail", "2020-9-11", EtatEngagement.Respecte, null)]
|
|
[TestCase(1, 9, "Je m'engage à trouver une formation sur l'Asp.Net Core.", "Demande de formation RH.", "", "2020-9-11", EtatEngagement.Respecte, null)]
|
|
[TestCase(1, 9, "Je m'engage à trouver une formation sur l'Asp.Net Core.", "Demande de formation RH.", "Sur temps de travail", null, EtatEngagement.Respecte, null)]
|
|
[TestCase(1, 9, "Je m'engage à trouver une formation sur l'Asp.Net Core.", "Demande de formation RH.", "Sur temps de travail", "2020-9-11", EtatEngagement.NonRealisable, null)]
|
|
public void RepondreEngagementAsync_ModifieUnEngagementAvecDesProprietesInvalide_LeveUneEngagementInvalidException(long idEngagement, long idEp, string action, string dispositif, string modalite, DateTime? dateLimite, EtatEngagement etatEngagement, string raisonNonRealisable)
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
|
|
EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
|
|
.Select(ep => new EpInformationDTO
|
|
{
|
|
Id = ep.IdEP,
|
|
Type = ep.TypeEP,
|
|
Statut = ep.Statut,
|
|
DateDisponibilite = ep.DateDisponibilite,
|
|
DatePrevisionnelle = ep.DatePrevisionnelle,
|
|
Obligatoire = ep.Obligatoire
|
|
}).FirstOrDefault();
|
|
|
|
EngagementDTO engagementDTO = new EngagementDTO
|
|
{
|
|
Id = idEngagement,
|
|
Action = action,
|
|
Dispositif = dispositif,
|
|
Modalite = modalite,
|
|
DateLimite = dateLimite,
|
|
EtatEngagement = etatEngagement,
|
|
RaisonNonRealisable = raisonNonRealisable,
|
|
Ep = epInformationDTO
|
|
};
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => engagementService.RepondreEngagementAsync(engagementDTO, idEngagement);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(EngagementInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void RepondreEngagementAsync_ModifieUnEngagementNull_LeveUneEngagementInvalidException()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
EngagementDTO engagementDTO = null;
|
|
long idEngagement = 1;
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => engagementService.RepondreEngagementAsync(engagementDTO, idEngagement);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(EngagementInvalidException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void RepondreEngagementAsync_ModifieUnEngagementAvecUnEPInexistantDansLaBDD_LeveUneEngagementInvalidException()
|
|
{
|
|
// Arrange
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
long idEngagement = 1;
|
|
EpInformationDTO epInformationDTO = new EpInformationDTO
|
|
{
|
|
Id = 999,
|
|
Type = TypeEp.EPA,
|
|
Statut = StatutEp.Signe,
|
|
DateDisponibilite = DateTime.Now,
|
|
DatePrevisionnelle = DateTime.Now,
|
|
Obligatoire = false
|
|
};
|
|
|
|
EngagementDTO engagementDTO = new EngagementDTO
|
|
{
|
|
Id = idEngagement,
|
|
Action = "Je m'engage à trouver une formation sur l'Asp.Net Core.",
|
|
Dispositif = "Demande de formation RH.",
|
|
Modalite = "Sur temps de travail",
|
|
DateLimite = new DateTime(2020, 9, 1),
|
|
EtatEngagement = EtatEngagement.Respecte,
|
|
RaisonNonRealisable = null,
|
|
Ep = epInformationDTO
|
|
};
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => engagementService.RepondreEngagementAsync(engagementDTO, idEngagement);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(EngagementInvalidException), throwException);
|
|
}
|
|
|
|
|
|
|
|
[TestCase(1)]
|
|
[TestCase(null)]
|
|
public void RepondreEngagementAsync_ModifieUnEngagementAvecUnIdIncorrecte_LeveUneEngagementnIncompatibleIdException(long? idEngagement)
|
|
{
|
|
// Arrange
|
|
long idEngagementIncorrecte = 2;
|
|
long idEp = 9;
|
|
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
|
|
EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
|
|
.Select(ep => new EpInformationDTO
|
|
{
|
|
Id = ep.IdEP,
|
|
Type = ep.TypeEP,
|
|
Statut = ep.Statut,
|
|
DateDisponibilite = ep.DateDisponibilite,
|
|
DatePrevisionnelle = ep.DatePrevisionnelle,
|
|
Obligatoire = ep.Obligatoire
|
|
}).FirstOrDefault();
|
|
|
|
EngagementDTO engagementDTO = new EngagementDTO
|
|
{
|
|
Id = idEngagement,
|
|
Action = "Je m'engage à trouver une formation sur l'Asp.Net Core.",
|
|
Dispositif = "Demande de formation RH.",
|
|
Modalite = "Sur temps de travail",
|
|
DateLimite = new DateTime(2020, 9, 1),
|
|
EtatEngagement = EtatEngagement.Respecte,
|
|
RaisonNonRealisable = null,
|
|
Ep = epInformationDTO
|
|
};
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => engagementService.RepondreEngagementAsync(engagementDTO, idEngagementIncorrecte);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(EngagementIncompatibleIdException), throwException);
|
|
}
|
|
|
|
[Test]
|
|
public void RepondreEngagementAsync_ModifieUnEngagementAvecUnIdInexistant_LeveUneEngagementNotFoundException()
|
|
{
|
|
// Arrange
|
|
long idEngagement = 0;
|
|
long idEp = 9;
|
|
|
|
EngagementService engagementService = new EngagementService(epContext, collaborateurService);
|
|
|
|
EpInformationDTO epInformationDTO = epContext.Ep.Where(ep => ep.IdEP == idEp)
|
|
.Select(ep => new EpInformationDTO
|
|
{
|
|
Id = ep.IdEP,
|
|
Type = ep.TypeEP,
|
|
Statut = ep.Statut,
|
|
DateDisponibilite = ep.DateDisponibilite,
|
|
DatePrevisionnelle = ep.DatePrevisionnelle,
|
|
Obligatoire = ep.Obligatoire
|
|
}).FirstOrDefault();
|
|
|
|
EngagementDTO engagementDTO = new EngagementDTO
|
|
{
|
|
Id = idEngagement,
|
|
Action = "Je m'engage à trouver une formation sur l'Asp.Net Core.",
|
|
Dispositif = "Demande de formation RH.",
|
|
Modalite = "Sur temps de travail",
|
|
DateLimite = new DateTime(2020, 9, 1),
|
|
EtatEngagement = EtatEngagement.Respecte,
|
|
RaisonNonRealisable = null,
|
|
Ep = epInformationDTO
|
|
};
|
|
|
|
// Act
|
|
AsyncTestDelegate throwException = () => engagementService.RepondreEngagementAsync(engagementDTO, idEngagement);
|
|
|
|
// Assert
|
|
Assert.ThrowsAsync(typeof(EngagementNotFoundException), throwException);
|
|
}
|
|
#endregion
|
|
}
|
|
} |