From 5e3870ec6ea7aad78eb598e8836f5764339ae264 Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Thu, 4 Feb 2021 08:58:30 +0100 Subject: [PATCH] Ajout du service Collaborateur --- .../Controllers/FormationApiTests.cs | 12 +-- .../Services/FormationServiceTests.cs | 80 ++++++++++--------- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/EPAServeur.Tests/Controllers/FormationApiTests.cs b/EPAServeur.Tests/Controllers/FormationApiTests.cs index eb056ae..fb8ae37 100644 --- a/EPAServeur.Tests/Controllers/FormationApiTests.cs +++ b/EPAServeur.Tests/Controllers/FormationApiTests.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(); + services.AddScoped(); services.AddScoped(); // 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>(okResult.Value); - Assert.AreEqual(nbFormation, (okResult.Value as IEnumerable).Count()); - Assert.AreEqual(idFirstFormation, (okResult.Value as IEnumerable).First().Id); - Assert.AreEqual(idLastFormation, (okResult.Value as IEnumerable).Last().Id); + Assert.IsInstanceOf>(okResult.Value); + Assert.AreEqual(nbFormation, (okResult.Value as IEnumerable).Count()); + Assert.AreEqual(idFirstFormation, (okResult.Value as IEnumerable).First().Id); + Assert.AreEqual(idLastFormation, (okResult.Value as IEnumerable).Last().Id); } #endregion diff --git a/EPAServeur.Tests/Services/FormationServiceTests.cs b/EPAServeur.Tests/Services/FormationServiceTests.cs index 9881639..eea69fd 100644 --- a/EPAServeur.Tests/Services/FormationServiceTests.cs +++ b/EPAServeur.Tests/Services/FormationServiceTests.cs @@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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);