Ajout du service Collaborateur

develop
jboinembalome 4 years ago
parent 6747f231fe
commit 5e3870ec6e
  1. 12
      EPAServeur.Tests/Controllers/FormationApiTests.cs
  2. 80
      EPAServeur.Tests/Services/FormationServiceTests.cs

@ -18,6 +18,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using EPAServeur.IServices;
using Moq;
using IO.Swagger.ApiCollaborateur;
namespace EPAServeur.Tests.Controllers
{
@ -62,7 +63,8 @@ namespace EPAServeur.Tests.Controllers
entity.State = EntityState.Detached;
}
services.AddScoped<ICollaborateurApi, CollaborateurApi>();
services.AddScoped<ICollaborateurService, CollaborateurService>();
services.AddScoped<IFormationService, FormationService>();
// Récupère le service qui sera utilsé pour tester le contrôleur
@ -155,10 +157,10 @@ namespace EPAServeur.Tests.Controllers
var okResult = formationsApiController.GetFormations(1, idStatuts, true, 1, 5, "formation", null, null, null).Result as OkObjectResult;
// Assert
Assert.IsInstanceOf<IEnumerable<FormationDTO>>(okResult.Value);
Assert.AreEqual(nbFormation, (okResult.Value as IEnumerable<FormationDTO>).Count());
Assert.AreEqual(idFirstFormation, (okResult.Value as IEnumerable<FormationDTO>).First().Id);
Assert.AreEqual(idLastFormation, (okResult.Value as IEnumerable<FormationDTO>).Last().Id);
Assert.IsInstanceOf<IEnumerable<FormationDetailsDTO>>(okResult.Value);
Assert.AreEqual(nbFormation, (okResult.Value as IEnumerable<FormationDetailsDTO>).Count());
Assert.AreEqual(idFirstFormation, (okResult.Value as IEnumerable<FormationDetailsDTO>).First().Id);
Assert.AreEqual(idLastFormation, (okResult.Value as IEnumerable<FormationDetailsDTO>).Last().Id);
}
#endregion

@ -1,7 +1,9 @@
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 Microsoft.EntityFrameworkCore;
using NUnit.Framework;
@ -18,7 +20,8 @@ namespace EPAServeur.Tests.Services
#region Variables
private EpContext epContext;
private ICollaborateurApi collaborateurApi;
private ICollaborateurService collaborateurService;
#endregion
#region Setup
@ -32,7 +35,8 @@ namespace EPAServeur.Tests.Services
.Options;
epContext = new EpContext(optionBuider);
collaborateurApi = new CollaborateurApi();
collaborateurService = new CollaborateurService(collaborateurApi, epContext);
epContext.Database.EnsureDeleted();
epContext.Database.EnsureCreated();
epContext.SaveChanges();
@ -55,7 +59,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormation()
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
FormationDTO formationDTO = await formationService.GetFormationByIdAsync(1);
@ -82,7 +86,7 @@ namespace EPAServeur.Tests.Services
public void GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long idFormation)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
AsyncTestDelegate throwException = () => formationService.GetFormationByIdAsync(idFormation);
@ -104,7 +108,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseDesParamsValides_RetourneDesFormations(long? idAgence, int[] arrIdStatuts, bool? asc, int? numPage, int? parPAge, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
List<int?> idStatuts;
if (arrIdStatuts != null)
@ -124,7 +128,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaPremierePageDesFormations(int? numPage, int? parPAge)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, numPage, parPAge, null, null, null, null);
@ -140,7 +144,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamNumPageEtParPage_RetourneLaDeuxiemePageDesFormations(int? numPage, int? parPAge)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
int? nbFormationDeuxiemePage;
switch (parPAge)
@ -171,7 +175,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleCroissant(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -187,7 +191,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleDecroissant(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -202,7 +206,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutCroissant(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -217,7 +221,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutDecroissant(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -232,7 +236,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineCroissante(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -247,7 +251,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineDecroissante(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -262,7 +266,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateCroissante(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -277,7 +281,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateDecroissante(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -292,7 +296,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationCroissante(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -307,7 +311,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationDecroissante(bool? asc, string tri)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null);
@ -323,7 +327,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamUneDateDeDebut_RetourneDesFormationsAvecUneDateDeDebutSuperieur(DateTime dateDebut)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, null);
@ -338,7 +342,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamUneDateDeFin_RetourneDesFormationsAvecUneDateDeFinInferieur(DateTime dateFin)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, null, dateFin);
@ -353,7 +357,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutEtUneDateDeFin_RetourneDesFormationsAvecUneDateDeDebutSuperieurUneDateDeFinInferieur(DateTime dateDebut, DateTime dateFin)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin);
@ -371,7 +375,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutSuperieurEtUneDateDeFinInferieur_RetourneZeroFormation(DateTime dateDebut, DateTime dateFin)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<FormationDetailsDTO> formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin);
@ -386,7 +390,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsAsync_PasseDesParamsInvalides_RetourneZeroFormation(long? idAgence, int[] arrIdStatuts, bool? asc, int? numPage, int? parPAge, string texte, string tri, DateTime? dateDebut, DateTime? dateFin)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
List<int?> idStatuts;
if (arrIdStatuts != null)
@ -415,7 +419,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDeFormations(long? idAgence, int[] arrIdStatuts, int? numPage, int? parPAge, string texte, DateTime? dateDebut, DateTime? dateFin)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
List<int?> idStatuts;
if (arrIdStatuts != null)
@ -436,7 +440,7 @@ namespace EPAServeur.Tests.Services
public async Task GetFormationsCountAsync_PasseDesParamsInvalides_RetourneZero(long? idAgence, int[] arrIdStatuts, int? numPage, int? parPAge, string texte, DateTime? dateDebut, DateTime? dateFin)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
List<int?> idStatuts;
if (arrIdStatuts != null)
@ -460,7 +464,7 @@ namespace EPAServeur.Tests.Services
public async Task GetModesFormationAsync_RetourneTousLesModesDeFormation()
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<ModeFormationDTO> modeFormationDTOs = await formationService.GetModesFormationAsync();
@ -478,7 +482,7 @@ namespace EPAServeur.Tests.Services
public async Task GetOriginesAsyncFormation_RetourneToutesLesOriginesDeFormation()
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<OrigineFormationDTO> origineFormationDTOs = await formationService.GetOriginesFormationAsync();
@ -496,7 +500,7 @@ namespace EPAServeur.Tests.Services
public async Task GetStatutsFormationAsyncFormation_RetourneTousLesStatutsDeFormation()
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<StatutFormationDTO> statutFormationDTOs = await formationService.GetStatutsFormationAsync();
@ -514,7 +518,7 @@ namespace EPAServeur.Tests.Services
public async Task GetTypesFormationAsync_RetourneTousLesTypesDeFormation()
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
IEnumerable<TypeFormationDTO> typeFormationDTOs = await formationService.GetTypesFormationAsync();
@ -559,7 +563,7 @@ namespace EPAServeur.Tests.Services
EstCertifiee = false
};
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
FormationDTO formationAjoute = await formationService.AddFormationAsync(formation);
@ -588,7 +592,7 @@ namespace EPAServeur.Tests.Services
// Arrange
FormationDTO formation = null;
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation);
@ -637,7 +641,7 @@ namespace EPAServeur.Tests.Services
EstCertifiee = false
};
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation);
@ -683,7 +687,7 @@ namespace EPAServeur.Tests.Services
EstCertifiee = false
};
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation);
@ -709,7 +713,7 @@ namespace EPAServeur.Tests.Services
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);
FormationService formationService = new FormationService(epContext, collaborateurService);
FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation);
@ -773,7 +777,7 @@ namespace EPAServeur.Tests.Services
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);
FormationService formationService = new FormationService(epContext, collaborateurService);
FormationDTO formation = await formationService.GetFormationByIdAsync(idFormation);
@ -812,7 +816,7 @@ namespace EPAServeur.Tests.Services
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);
FormationService formationService = new FormationService(epContext, collaborateurService);
FormationDTO formation = await formationService.GetFormationByIdAsync(1);
@ -850,7 +854,7 @@ namespace EPAServeur.Tests.Services
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);
FormationService formationService = new FormationService(epContext, collaborateurService);
FormationDTO formation = new FormationDTO
{
@ -886,7 +890,7 @@ namespace EPAServeur.Tests.Services
public async Task DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long idFormation)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
bool existFormation = true;
// Act
@ -903,7 +907,7 @@ namespace EPAServeur.Tests.Services
public void DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdInvalide_LeveUneFormationNotFoundException(long idFormation)
{
// Arrange
FormationService formationService = new FormationService(epContext);
FormationService formationService = new FormationService(epContext, collaborateurService);
// Act
AsyncTestDelegate throwException = () => formationService.DeleteFormationByIdAsync(idFormation);

Loading…
Cancel
Save