You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Digitalisation_EPA_Serveur/EPAServeur.Tests/Controllers/ParticipationFormationApiTe...

438 lines
30 KiB

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<IWebHostEnvironment> mockEnvironment;
private EpContext epContext;
#endregion
#region Setup
[SetUp]
public void Setup()
{
// Cr<EFBFBD>ation d'une collection de services pour l'injection de d<EFBFBD>pendance
var services = new ServiceCollection();
// Utilisation d'une base de donn<EFBFBD>es en m<EFBFBD>moire
var optionBuider = new DbContextOptionsBuilder<EpContext>()
.UseInMemoryDatabase("server_ep_test")
.Options;
services.AddDbContext<EpContext>(b => b.UseInMemoryDatabase("server_ep_test"));
epContext = new EpContext(optionBuider);
epContext.Database.EnsureDeleted();
epContext.Database.EnsureCreated();
epContext.SaveChanges();
// Ajout du jeu de donn<EFBFBD>es pour les tests
DataSeeder.AddFormations(epContext);
DataSeeder.AddChamps(epContext);
// D<EFBFBD>tache les entit<EFBFBD>s du context car la base de donn<EFBFBD>es InMemory cr<EFBFBD><EFBFBD> des conflits
// entre les cl<EFBFBD>s primaires lors d'un Update ou d'un Insert
foreach (var entity in epContext.ChangeTracker.Entries())
{
entity.State = EntityState.Detached;
}
services.AddScoped<ICollaborateurApi, CollaborateurApi>();
services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IParticipationFormationService, ParticipationFormationService>();
// R<EFBFBD>cup<EFBFBD>re le service qui sera utils<EFBFBD> pour tester le contr<EFBFBD>leur
var serviceProvider = services.BuildServiceProvider();
participationFormationService = serviceProvider.GetService<IParticipationFormationService>();
// Simule l'interface IWebHostEnvironment avec Moq
mockEnvironment = new Mock<IWebHostEnvironment>();
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<ParticipationsFormationsApiController>(), mockEnvironment.Object);
long idParticipationFormation = 99999;
// Act
var notFoundResult = ParticipationsFormationsApiController.GetEvaluationCollaborateur(idParticipationFormation);
// Assert
Assert.IsInstanceOf<NotFoundObjectResult>(notFoundResult.Result);
}
[Test]
public void GetEvaluationCollaborateur_PasseEnParamUnIdConnu_RetourneUnObjetOkResult()
{
// Arrange
ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger<ParticipationsFormationsApiController>(), mockEnvironment.Object);
long idParticipationFormation = 5;
// Act
var okResult = ParticipationsFormationsApiController.GetEvaluationCollaborateur(idParticipationFormation);
// Assert
Assert.IsInstanceOf<OkObjectResult>(okResult.Result);
}
[Test]
public void GetEvaluationCollaborateur_PasseEnParamUnIdConnu_RetourneLaBonneEvaluation()
{
// Arrange
ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger<ParticipationsFormationsApiController>(), mockEnvironment.Object);
long idParticipationFormation = 5;
// Act
var okResult = ParticipationsFormationsApiController.GetEvaluationCollaborateur(idParticipationFormation).Result as OkObjectResult;
// Assert
Assert.IsInstanceOf<EvaluationDTO>(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<ParticipationsFormationsApiController>(), mockEnvironment.Object);
Guid idCollaborateur = Guid.Parse("842650db-a548-4472-a3af-4c5fff3c1ab8");
// Act
var okResult = ParticipationsFormationsApiController.GetParticipationsByCollaborateur(idCollaborateur);
// Assert
Assert.IsInstanceOf<OkObjectResult>(okResult.Result);
}
[Test]
public void GetParticipationByCollaborateur_PasseDesParamsPresentsDansLaBDD_RetourneLesParticipationsDUnCollaborateur()
{
// Arrange
ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger<ParticipationsFormationsApiController>(), 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<IEnumerable<ParticipationFormationDTO>>(okResult.Value);
Assert.AreEqual(nbFormation, (okResult.Value as IEnumerable<ParticipationFormationDTO>).Count());
Assert.AreEqual(idFirstParticipationFormation, (okResult.Value as IEnumerable<ParticipationFormationDTO>).First().Id);
}
#endregion
#region Tests EvaluerFormation
[Test]
public async Task EvaluerFormation_EvaluerUneFormationAvecDesObjetsEnfantsInvalides_RetourneUnObjetObjectResultDansCatchParticipationFormationInvalidException()
{
// Arrange
long idParticipationFormation = 5;
ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger<ParticipationsFormationsApiController>(), 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<SaisieDTO>()
}).FirstOrDefaultAsync();
// Act
var objectResult = ParticipationsFormationsApiController.EvaluerFormation(evaluationDTO, idParticipationFormation);
// Assert
Assert.IsInstanceOf<ObjectResult>(objectResult.Result);
}
[Test]
public async Task EvaluerFormation_EvaluerUneFormationAvecDesObjetsEnfantsInvalides_RetourneUnObjetObjectResultDansCatchParticipationFormationIncompatibleIdException()
{
// Arrange
long idParticipationFormation = 5;
ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger<ParticipationsFormationsApiController>(), 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<SaisieDTO>()
}).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<EFBFBD>tences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "P<EFBFBD>dagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivit<EFBFBD> des sujets trait<EFBFBD>s", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilit<EFBFBD>/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu th<EFBFBD>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<EFBFBD>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<EFBFBD>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>(objectResult.Result);
}
[Test]
public async Task EvaluerFormation_EvaluerUneFormationInexistante_RetourneUnObjetObjectResultDansCatchParticipationFormationNotFoundExceptionn()
{
// Arrange
long idParticipationFormation = 5;
long idParticipationFormationInexistant = 999;
ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger<ParticipationsFormationsApiController>(), 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<SaisieDTO>()
}).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<EFBFBD>tences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "P<EFBFBD>dagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivit<EFBFBD> des sujets trait<EFBFBD>s", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilit<EFBFBD>/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu th<EFBFBD>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<EFBFBD>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<EFBFBD>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>(objectResult.Result);
}
[Test]
public async Task EvaluerFormation_EvaluerUneFormationValide_RetourneUnObjetOkObjectResult()
{
// Arrange
long idParticipationFormation = 5;
ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger<ParticipationsFormationsApiController>(), 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<SaisieDTO>()
}).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<EFBFBD>tences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "P<EFBFBD>dagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivit<EFBFBD> des sujets trait<EFBFBD>s", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilit<EFBFBD>/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu th<EFBFBD>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<EFBFBD>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<EFBFBD>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>(okObjectResult.Result);
}
[Test]
public async Task EvaluerFormation_EvaluerUneFormationValide_RetourneLEvaluationEvaluee()
{
// Arrange
long idParticipationFormation = 5;
ParticipationsFormationsApiController ParticipationsFormationsApiController = new ParticipationsFormationsApiController(participationFormationService, new NullLogger<ParticipationsFormationsApiController>(), 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<SaisieDTO>()
}).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<EFBFBD>tences animateur", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c3 = new ChampDTO { Id = 37, Section = "Evaluation", Ordre = 2, Texte = "P<EFBFBD>dagogie/Animation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c4 = new ChampDTO { Id = 38, Section = "Evaluation", Ordre = 3, Texte = "Exhaustivit<EFBFBD> des sujets trait<EFBFBD>s", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c5 = new ChampDTO { Id = 39, Section = "Evaluation", Ordre = 4, Texte = "Utilit<EFBFBD>/Apport de la formation", TypeChamp = TypeChamps.Evaluation, TypeSaisie = TypeSaisie.Competence };
ChampDTO c6 = new ChampDTO { Id = 40, Section = "Evaluation", Ordre = 5, Texte = "Contenu th<EFBFBD>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<EFBFBD>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<EFBFBD>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<EvaluationDTO>(okObjectResult.Value);
Assert.AreEqual(idParticipationFormation, (okObjectResult.Value as EvaluationDTO).Id);
}
#endregion
}
}