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 ParticipationFormationServiceTests { #region Variables private EpContext epContext; private ICollaborateurApi collaborateurApi; private ICollaborateurService collaborateurService; private ITransformDTO transformDTO; #endregion #region Setup [SetUp] public void Setup() { // Utilisation d'une base de données en mémoire var optionBuider = new DbContextOptionsBuilder() .UseInMemoryDatabase("server_ep_test") .Options; epContext = new EpContext(optionBuider); collaborateurApi = new CollaborateurApi(); transformDTO = new TransformDTO(); collaborateurService = new CollaborateurService(collaborateurApi, epContext, transformDTO); epContext.Database.EnsureDeleted(); epContext.Database.EnsureCreated(); epContext.SaveChanges(); // Ajout du jeu de données pour les tests DataSeeder.AddFormations(epContext); 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; } } #endregion #region Tests GetEvaluationCollaborateurAsync [Test] public async Task GetEvaluationCollaborateurAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneEvaluation() { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); 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.EstCertifiee); Assert.AreEqual("Apprendre C# et le développement de logiciels avec WPF", evaluationDTO.Intitule); } [TestCase(-1)] [TestCase(0)] [TestCase(999999)] public void GetEvaluationCollaborateurAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneParticipationFormationNotFoundException(long idParticipationFormation) { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act AsyncTestDelegate throwException = () => participationFormationService.GetEvaluationCollaborateurAsync(idParticipationFormation); // Assert Assert.ThrowsAsync(typeof(ParticipationFormationNotFoundException), throwException); } #endregion #region Tests GetParticipationsByCollaborateurAsync [TestCase("842650db-a548-4472-a3af-4c5fff3c1ab8")] [TestCase("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491")] public async Task GetParticipationByCollaborateurAsync_PasseDesParamsValides_RetourneDesParticipationsFormations(Guid idCollaborateur) { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); // Assert Assert.Less(0, participationFormationDTOs.Count()); } [TestCase("e7820f92-eab1-42f5-ae96-5c16e71ff1e6")] [TestCase("b5254c6c-7caa-435f-a4bb-e0cf92559832")] public async Task GetParticipationByCollaborateurAsync_PasseDesParamsInvalides_RetourneZeroParticipation(Guid idCollaborateur) { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); // Act IEnumerable participationFormationDTOs = await participationFormationService.GetParticipationsByCollaborateurAsync(idCollaborateur); // Assert Assert.AreEqual(0, participationFormationDTOs.Count()); } #endregion #region Tests EvaluerFormationAsync [Test] public async Task EvaluerFormationAsync_EvaluerUneFormationValide_EvaluationRealiseeAvecSucces() { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); 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 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(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(null)] [TestCase("")] [TestCase(" ")] public async Task EvaluerFormationAsync_EvaluerUneFormationSansIntitule_LeveUneParticipationFormationInvalidException(string intitule) { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); 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 = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); // Assert Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); } [Test] public async Task EvaluerFormationAsync_EvaluerUneFormationSansEstCertifiee_LeveUneParticipationFormationInvalidException() { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); 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 = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); // Assert Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); } [Test] public async Task EvaluerFormationAsync_EvaluerUneFormationSansDateDebut_LeveUneParticipationFormationInvalidException() { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); 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, transformDTO); 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, transformDTO); 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 = () => participationFormationService.EvaluerFormationAsync(idParticipationFormation, evaluationDTO); // Assert Assert.ThrowsAsync(typeof(ParticipationFormationInvalidException), throwException); } [Test] public async Task EvaluerFormationAsync_EvaluerUneFormationAvecDesSaisiesSansNotesEtUnTypeDeSaisieCompetence_LeveUneParticipationFormationInvalidException() { // Arrange ParticipationFormationService participationFormationService = new ParticipationFormationService(epContext, collaborateurService, transformDTO); 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, transformDTO); 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, transformDTO); 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, transformDTO); 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, transformDTO); 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, transformDTO); 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 } }