From 7de1183ad484492cc1a3d80b62226710edddb910 Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Fri, 26 Feb 2021 13:14:16 +0100 Subject: [PATCH] Fin des tests unitaires pour le service et l'api des participations aux formations --- .../ParticipationFormationApiTests.cs | 438 ++++++++++ .../ParticipationFormationServiceTests.cs | 765 ++++++++++++++---- 2 files changed, 1046 insertions(+), 157 deletions(-) create mode 100644 EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs diff --git a/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs b/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs new file mode 100644 index 0000000..1f8da96 --- /dev/null +++ b/EPAServeur.Tests/Controllers/ParticipationFormationApiTests.cs @@ -0,0 +1,438 @@ +using EPAServeur.Context; +using EPAServeur.Exceptions; +using EPAServeur.Models.Formation; +using EPAServeur.Services; +using IO.Swagger.Controllers; +using IO.Swagger.DTO; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.DependencyInjection; +using EPAServeur.IServices; +using Moq; +using IO.Swagger.ApiCollaborateur; +using IO.Swagger.Enum; + +namespace EPAServeur.Tests.Controllers +{ + [TestFixture] + public class ParticipationFormationApiTests + { + #region Variables + + private IParticipationFormationService participationFormationService; + private Mock mockEnvironment; + private EpContext epContext; + #endregion + + #region Setup + + [SetUp] + public void Setup() + { + // Création d'une collection de services pour l'injection de dépendance + var services = new ServiceCollection(); + + // Utilisation d'une base de données en mémoire + var optionBuider = new DbContextOptionsBuilder() + .UseInMemoryDatabase("server_ep_test") + .Options; + + services.AddDbContext(b => b.UseInMemoryDatabase("server_ep_test")); + + epContext = new EpContext(optionBuider); + + epContext.Database.EnsureDeleted(); + epContext.Database.EnsureCreated(); + epContext.SaveChanges(); + + // Ajout du jeu de données pour les tests + DataSeeder.AddFormations(epContext); + DataSeeder.AddChamps(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; + } + + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + // Récupère le service qui sera utilsé pour tester le contrôleur + var serviceProvider = services.BuildServiceProvider(); + participationFormationService = serviceProvider.GetService(); + + // Simule l'interface IWebHostEnvironment avec Moq + mockEnvironment = new Mock(); + + mockEnvironment + .Setup(m => m.EnvironmentName) + .Returns("Development"); + + } + + #endregion + + #region Tests GetEvaluationCollaborateur + + [Test] + public void GetEvaluationCollaborateur_PasseEnParamUnIdInconnu_RetourneUnObjetNotFoundResult() + { + // Arrange + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + long idParticipationFormation = 99999; + + // Act + var notFoundResult = ParticipationsFormationsApiController.GetEvaluationCollaborateur(idParticipationFormation); + + // Assert + Assert.IsInstanceOf(notFoundResult.Result); + } + + [Test] + public void GetEvaluationCollaborateur_PasseEnParamUnIdConnu_RetourneUnObjetOkResult() + { + // Arrange + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + long idParticipationFormation = 5; + + // Act + var okResult = ParticipationsFormationsApiController.GetEvaluationCollaborateur(idParticipationFormation); + + // Assert + Assert.IsInstanceOf(okResult.Result); + } + + + [Test] + public void GetEvaluationCollaborateur_PasseEnParamUnIdConnu_RetourneLaBonneEvaluation() + { + // Arrange + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + long idParticipationFormation = 5; + + + // Act + var okResult = ParticipationsFormationsApiController.GetEvaluationCollaborateur(idParticipationFormation).Result as OkObjectResult; + + // Assert + Assert.IsInstanceOf(okResult.Value); + Assert.AreEqual(idParticipationFormation, (okResult.Value as EvaluationDTO).Id); + } + #endregion + + #region Tests GetParticipationsByCollaborateur + + [Test] + public void GetParticipationByCollaborateur_PasseDesParamsPresentsDansLaBDD_RetourneUnObjetOkResult() + { + // Arrange + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + Guid idCollaborateur = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"); + + // Act + var okResult = ParticipationsFormationsApiController.GetParticipationsByCollaborateur(idCollaborateur); + + // Assert + Assert.IsInstanceOf(okResult.Result); + } + + [Test] + public void GetParticipationByCollaborateur_PasseDesParamsPresentsDansLaBDD_RetourneLesParticipationsDUnCollaborateur() + { + // Arrange + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + Guid idCollaborateur = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8"); + int nbFormation = 1; + int idFirstParticipationFormation = 5; + + // Act + var okResult = ParticipationsFormationsApiController.GetParticipationsByCollaborateur(idCollaborateur).Result as OkObjectResult; + + // Assert + Assert.IsInstanceOf>(okResult.Value); + Assert.AreEqual(nbFormation, (okResult.Value as IEnumerable).Count()); + Assert.AreEqual(idFirstParticipationFormation, (okResult.Value as IEnumerable).First().Id); + } + + #endregion + + #region Tests EvaluerFormation + + [Test] + public async Task EvaluerFormation_EvaluerUneFormationAvecDesObjetsEnfantsInvalides_RetourneUnObjetObjectResultDansCatchParticipationFormationInvalidException() + { + // Arrange + long idParticipationFormation = 5; + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + // Act + var objectResult = ParticipationsFormationsApiController.EvaluerFormation(evaluationDTO, idParticipationFormation); + + // Assert + Assert.IsInstanceOf(objectResult.Result); + } + + [Test] + public async Task EvaluerFormation_EvaluerUneFormationAvecDesObjetsEnfantsInvalides_RetourneUnObjetObjectResultDansCatchParticipationFormationIncompatibleIdException() + { + // Arrange + long idParticipationFormation = 5; + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + idParticipationFormation = 1; + + // Act + var objectResult = ParticipationsFormationsApiController.EvaluerFormation(evaluationDTO, idParticipationFormation); + + // Assert + Assert.IsInstanceOf(objectResult.Result); + } + + [Test] + public async Task EvaluerFormation_EvaluerUneFormationInexistante_RetourneUnObjetObjectResultDansCatchParticipationFormationNotFoundExceptionn() + { + // Arrange + long idParticipationFormation = 5; + long idParticipationFormationInexistant = 999; + + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + evaluationDTO.Id = idParticipationFormationInexistant; + + // Act + var objectResult = ParticipationsFormationsApiController.EvaluerFormation(evaluationDTO, idParticipationFormationInexistant); + + // Assert + Assert.IsInstanceOf(objectResult.Result); + } + + [Test] + public async Task EvaluerFormation_EvaluerUneFormationValide_RetourneUnObjetOkObjectResult() + { + // Arrange + long idParticipationFormation = 5; + + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + // Act + var okObjectResult = ParticipationsFormationsApiController.EvaluerFormation(evaluationDTO, idParticipationFormation); + + // Assert + Assert.IsInstanceOf(okObjectResult.Result); + } + + [Test] + public async Task EvaluerFormation_EvaluerUneFormationValide_RetourneLEvaluationEvaluee() + { + // Arrange + long idParticipationFormation = 5; + + ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger(), mockEnvironment.Object); + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + + // Act + var okObjectResult = ParticipationsFormationsApiController.EvaluerFormation(evaluationDTO, idParticipationFormation).Result as OkObjectResult; + + // Assert + Assert.IsInstanceOf(okObjectResult.Value); + Assert.AreEqual(idParticipationFormation, (okObjectResult.Value as EvaluationDTO).Id); + } + + #endregion + + } +} \ No newline at end of file diff --git a/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs b/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs index cbe581c..cafddf1 100644 --- a/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs +++ b/EPAServeur.Tests/Services/ParticipationFormationServiceTests.cs @@ -5,6 +5,7 @@ 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; @@ -43,6 +44,7 @@ namespace EPAServeur.Tests.Services // Ajout du jeu de données pour les tests DataSeeder.AddFormations(epContext); + DataSeeder.AddChamps(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 @@ -60,14 +62,14 @@ namespace EPAServeur.Tests.Services { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); - int idParticipationFormation = 5; + long idParticipationFormation = 5; // Act EvaluationDTO evaluationDTO = await participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation); // Assert Assert.AreEqual(idParticipationFormation, evaluationDTO.Id); Assert.AreEqual(new DateTime(2020, 5, 25, 14, 0, 0), evaluationDTO.DateDebut); - Assert.True(evaluationDTO.EstCertifie); + Assert.True(evaluationDTO.EstCertifiee); Assert.AreEqual("Apprendre C# et le développement de logiciels avec WPF", evaluationDTO.Intitule); } @@ -88,17 +90,17 @@ namespace EPAServeur.Tests.Services #endregion - #region Tests GetParticipationByCollaborateur + #region Tests GetParticipationsByCollaborateurAsync [TestCase("842650db-a548-4472-a3af-4c5fff3c1ab8")] [TestCase("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491")] - public async Task GetParticipationByCollaborateur_PasseDesParamsValides_RetourneDesParticipationsFormations(Guid idCollaborateur) + public async Task GetParticipationByCollaborateurAsync_PasseDesParamsValides_RetourneDesParticipationsFormations(Guid idCollaborateur) { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); // Act - IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationByCollaborateurAsync(idCollaborateur); + IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); // Assert Assert.Less(0, participationFormationDTOs.Count()); @@ -106,205 +108,654 @@ namespace EPAServeur.Tests.Services [TestCase("e7820f92-eab1-42f5-ae96-5c16e71ff1e6")] [TestCase("b5254c6c-7caa-435f-a4bb-e0cf92559832")] - public async Task GetFormationsAsync_PasseDesParamsInvalides_RetourneZeroFormation(Guid idCollaborateur) + public async Task GetParticipationByCollaborateurAsync_PasseDesParamsInvalides_RetourneZeroParticipation(Guid idCollaborateur) { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); // Act - IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationByCollaborateurAsync(idCollaborateur); + IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); // Assert Assert.AreEqual(0, participationFormationDTOs.Count()); } #endregion - /* - #region Tests UpdateFormationAsync - [TestCase(1, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - public async Task UpdateFormationAsync_ModifieUneFormationValide_FormationModifieeAvecSucces(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) + #region Tests EvaluerFormationAsync + + [Test] + public async Task EvaluerFormationAsync_EvaluerUneFormationValide_EvaluationRealiseeAvecSucces() { // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) - .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - - FormationService formationService = new FormationService(epContext, collaborateurService); - - FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation); - - formation.Intitule = intitule; - formation.IdAgence = idAgence; - formation.DateDebut = dateDebut; - formation.DateFin = dateFin; - formation.Heure = 2; - formation.Jour = 1; - formation.Mode = modeExterne; - formation.Type = typeELearning; - formation.Organisme = organisme; - formation.Origine = origineFormationCollaborateur; - formation.Statut = statutPlanifie; - formation.EstCertifiee = false; + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); // Act - FormationDTO formationModifie = await formationService.UpdateFormationAsync(idFormation, formation); + EvaluationDTO evaluationModifiee = await participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); + bool EstEvaluee = await epContext.ParticipationFormation.Where(p => p.IdParticipationFormation == idParticipationFormation).Select(p => p.EstEvaluee).FirstOrDefaultAsync(); // Assert - Assert.IsNotNull(formationModifie); - Assert.AreEqual(idFormation, formationModifie.Id); - Assert.AreEqual(formation.Intitule, formationModifie.Intitule); - Assert.AreEqual(formation.IdAgence, formationModifie.IdAgence); - Assert.AreEqual(formation.DateDebut, formationModifie.DateDebut); - Assert.AreEqual(formation.DateFin, formationModifie.DateFin); - Assert.AreEqual(formation.Heure, formationModifie.Heure); - Assert.AreEqual(formation.Jour, formationModifie.Jour); - Assert.AreEqual(formation.Mode, formationModifie.Mode); - Assert.AreEqual(formation.Type, formationModifie.Type); - Assert.AreEqual(formation.Organisme, formationModifie.Organisme); - Assert.AreEqual(formation.Origine, formationModifie.Origine); - Assert.AreEqual(formation.Statut, formationModifie.Statut); - Assert.AreEqual(formation.EstCertifiee, formationModifie.EstCertifiee); + Assert.IsNotNull(evaluationModifiee); + Assert.True(EstEvaluee); + Assert.AreEqual(evaluationDTO.Id, evaluationModifiee.Id); + Assert.AreEqual(evaluationDTO.Intitule, evaluationModifiee.Intitule); + Assert.AreEqual(evaluationDTO.Saisies.Count, evaluationModifiee.Saisies.Count); + Assert.AreEqual(evaluationDTO.DateDebut, evaluationModifiee.DateDebut); + Assert.AreEqual(evaluationDTO.EstCertifiee, evaluationModifiee.EstCertifiee); } - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-10-30")] - [TestCase(1, 0, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 0, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 0, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 0, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 0, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, null, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, null, "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", null, "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", null, "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", null)] - public async Task UpdateFormationAsync_ModifieUneFormationAvecDesProprietesInvalides_LeveUneFormationInvalidException(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) + + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public async Task EvaluerFormationAsync_EvaluerUneFormationSansIntitule_LeveUneParticipationFormationInvalidException(string intitule) { // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) - .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - - FormationService formationService = new FormationService(epContext, collaborateurService); - - FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation); - - formation.Intitule = intitule; - formation.IdAgence = idAgence; - formation.DateDebut = dateDebut; - formation.DateFin = dateFin; - formation.Heure = 2; - formation.Jour = 1; - formation.Mode = modeExterne; - formation.Type = typeELearning; - formation.Organisme = organisme; - formation.Origine = origineFormationCollaborateur; - formation.Statut = statutPlanifie; - formation.EstCertifiee = false; + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + evaluationDTO.Intitule = intitule; // Act - AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(idFormation, formation); + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); // Assert - Assert.ThrowsAsync(typeof(FormationInvalidException), throwException); + Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); } - [TestCase(2, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - [TestCase(0, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - [TestCase(null, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - public async Task UpdateFormationAsync_ModifieUneFormationAvecUnIdIncorrecte_LeveUneFormationIncompatibleIdException(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) + [Test] + public async Task EvaluerFormationAsync_EvaluerUneFormationSansEstCertifiee_LeveUneParticipationFormationInvalidException() { + // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) - .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - - FormationService formationService = new FormationService(epContext, collaborateurService); - - FormationDTO formation = await formationService.GetFormationByIdAsync(1); - - formation.Id = idFormation; - formation.Intitule = intitule; - formation.IdAgence = idAgence; - formation.DateDebut = dateDebut; - formation.DateFin = dateFin; - formation.Heure = 2; - formation.Jour = 1; - formation.Mode = modeExterne; - formation.Type = typeELearning; - formation.Organisme = organisme; - formation.Origine = origineFormationCollaborateur; - formation.Statut = statutPlanifie; - formation.EstCertifiee = false; + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + bool? estCertifiee = null; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + evaluationDTO.EstCertifiee = estCertifiee; // Act - AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(1, formation); + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); // Assert - Assert.ThrowsAsync(typeof(FormationIncompatibleIdException), throwException); + Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); } - [TestCase(0, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - public void UpdateFormationAsync_ModifieUneFormationAvecUnIdInexistant_RetourneUnObjetNull(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) + [Test] + public async Task EvaluerFormationAsync_EvaluerUneFormationSansDateDebut_LeveUneParticipationFormationInvalidException() { + // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) - .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - - FormationService formationService = new FormationService(epContext, collaborateurService); - - FormationDTO formation = new FormationDTO - { - Id = idFormation, - Intitule = intitule, - IdAgence = idAgence, - DateDebut = dateDebut, - DateFin = dateFin, - Heure = 2, - Jour = 1, - Mode = modeExterne, - Type = typeELearning, - Organisme = organisme, - Origine = origineFormationCollaborateur, - Statut = statutPlanifie, - EstCertifiee = false - }; + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + DateTime? dateDebut = null; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + evaluationDTO.DateDebut = dateDebut; + + // Act + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); + + // Assert + Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); + } + + [Test] + public async Task EvaluerFormationAsync_EvaluerUneFormationSansSaisie_LeveUneParticipationFormationInvalidException() + { + + // Arrange + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + evaluationDTO.Saisies = null; + + // Act + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); + + // Assert + Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); + } + + [Test] + public async Task EvaluerFormationAsync_EvaluerUneFormationAvecZeroSaisie_LeveUneParticipationFormationInvalidException() + { + + // Arrange + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + evaluationDTO.Saisies = new List(); // Act - AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(idFormation, formation); + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); // Assert - Assert.ThrowsAsync(typeof(FormationNotFoundException), throwException); + Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); + } + + [Test] + public async Task EvaluerFormationAsync_EvaluerUneFormationAvecDesSaisiesSansNotesEtUnTypeDeSaisieCompetence_LeveUneParticipationFormationInvalidException() + { + + // Arrange + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = null, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + // Act + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); + + // Assert + Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); + } + + [Test] + public async Task EvaluerFormationAsync_EvaluerUneFormationAvecDesSaisiesSansNotesEtUnTypeDeSaisieNotation_LeveUneParticipationFormationInvalidException() + { + + // Arrange + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Notation }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = null, Texte = "", TypeSaisie = TypeSaisie.Notation, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + // Act + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); + + // Assert + Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); + } + + + [Test] + public void EvaluerFormationAsync_EvaluerUneFormationAvecUnDTONull_LeveUneParticipationFormationInvalidException() + { + + // Arrange + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + EvaluationDTO evaluationDTO = null; + + // Act + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); + + // Assert + Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); + } + + [TestCase(0)] + [TestCase(6)] + public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecte_LeveUneParticipationFormationIncompatibleIdException(long idParticipationFormationIncompatible) + { + // Arrange + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + // Act + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormationIncompatible, evaluationDTO); + + // Assert + Assert.ThrowsAsync(typeof(ParticipationFormationIncompatibleIdException), throwException); + } + + [TestCase(0)] + [TestCase(6)] + [TestCase(null)] + public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdIncorrecteAuNiveauDuDTO_LeveUneParticipationFormationIncompatibleIdException(long? idParticipationFormationIncompatible) + { + // Arrange + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + evaluationDTO.Id = idParticipationFormationIncompatible; + + // Act + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); + + // Assert + Assert.ThrowsAsync(typeof(ParticipationFormationIncompatibleIdException), throwException); + } + + [Test] + public async Task EvaluerFormationAsync_EvaluerUneFormationAvecUnIdInexistant_LeveUneParticipationFormationNotFoundException() + { + + // Arrange + ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService); + long idParticipationFormation = 5; + long idParticipationFormationInexistant = 0; + + EvaluationDTO evaluationDTO = await epContext.ParticipationFormation.Include(p => p.Formation) + .Where(p => p.IdParticipationFormation == idParticipationFormation) + .Select(p => new EvaluationDTO() + { + Id = p.IdParticipationFormation, + Intitule = p.Formation.Intitule, + DateDebut = p.Formation.DateDebut, + EstCertifiee = p.Formation.EstCertifiee, + Saisies = new List() + }).FirstOrDefaultAsync(); + + ChampDTO c1 = new ChampDTO { Id = 35, Section = "Evaluation", Ordre = 0, Texte = "Accueil et organisation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c2 = new ChampDTO { Id = 36, Section = "Evaluation", Ordre = 1, Texte = "Compétences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "Pédagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivité des sujets traités", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilité/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu théorique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c7 = new ChampDTO { Id = 41, Section = "Evaluation", Ordre = 6, Texte = "Contenu pratique", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c8 = new ChampDTO { Id = 42, Section = "Evaluation", Ordre = 7, Texte = "Equilibre pratique/théorie", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c9 = new ChampDTO { Id = 43, Section = "Evaluation", Ordre = 8, Texte = "Support de cours", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + ChampDTO c10 = new ChampDTO { Id = 44, Section = "Evaluation", Ordre = 9, Texte = "Durée", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence }; + + SaisieDTO s1 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c1 }; + SaisieDTO s2 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c2 }; + SaisieDTO s3 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c3 }; + SaisieDTO s4 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c4 }; + SaisieDTO s5 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c5 }; + SaisieDTO s6 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c6 }; + SaisieDTO s7 = new SaisieDTO { Note = 4, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c7 }; + SaisieDTO s8 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c8 }; + SaisieDTO s9 = new SaisieDTO { Note = 3, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c9 }; + SaisieDTO s10 = new SaisieDTO { Note = 5, Texte = "", TypeSaisie = TypeSaisie.Competence, Champ = c10 }; + + evaluationDTO.Saisies.Add(s1); + evaluationDTO.Saisies.Add(s2); + evaluationDTO.Saisies.Add(s3); + evaluationDTO.Saisies.Add(s4); + evaluationDTO.Saisies.Add(s5); + evaluationDTO.Saisies.Add(s6); + evaluationDTO.Saisies.Add(s7); + evaluationDTO.Saisies.Add(s8); + evaluationDTO.Saisies.Add(s9); + evaluationDTO.Saisies.Add(s10); + + evaluationDTO.Id = idParticipationFormationInexistant; + + + // Act + AsyncTestDelegate throwException = () => participationFormationService.EvaluerFormationAsync(idParticipationFormationInexistant, evaluationDTO); + + // Assert + Assert.ThrowsAsync(typeof(ParticipationFormationNotFoundException), throwException); } #endregion - */ - + + } } \ No newline at end of file