From 65afda1ab616142e6dcae81548fc2c909df7269b Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Tue, 16 Feb 2021 09:31:07 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Suppression=20du=20Skip=20And=20Take=20pour?= =?UTF-8?q?=20la=20m=C3=A9thode=20Count?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/FormationApiTests.cs | 10 +++---- .../Services/FormationServiceTests.cs | 26 +++++++++---------- EPAServeur/Controllers/FormationsApi.cs | 8 ++---- EPAServeur/IServices/IFormationService.cs | 2 +- EPAServeur/Services/FormationService.cs | 4 +-- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/EPAServeur.Tests/Controllers/FormationApiTests.cs b/EPAServeur.Tests/Controllers/FormationApiTests.cs index fb8ae37..aff0d95 100644 --- a/EPAServeur.Tests/Controllers/FormationApiTests.cs +++ b/EPAServeur.Tests/Controllers/FormationApiTests.cs @@ -175,7 +175,7 @@ namespace EPAServeur.Tests.Controllers List idStatuts = new List { 1, 2, 3 }; // Act - var okResult = formationsApiController.GetFormationsCount(1, idStatuts, 1, 5, "formation", null, null); + var okResult = formationsApiController.GetFormationsCount(1, idStatuts, "formation", null, null); // Assert Assert.IsInstanceOf(okResult.Result); @@ -187,10 +187,10 @@ namespace EPAServeur.Tests.Controllers // Arrange FormationsApiController formationsApiController = new FormationsApiController(formationService, new NullLogger(), mockEnvironment.Object); List idStatuts = new List { 1, 2, 3 }; - int nbFormation = 5; + int nbFormation = 8; // Act - var okResult = formationsApiController.GetFormationsCount(1, idStatuts, 1, 5, "formation", null, null).Result as OkObjectResult; + var okResult = formationsApiController.GetFormationsCount(1, idStatuts, "formation", null, null).Result as OkObjectResult; // Assert Assert.IsInstanceOf(okResult.Value); @@ -589,13 +589,13 @@ namespace EPAServeur.Tests.Controllers // Arrange FormationsApiController formationsApiController = new FormationsApiController(formationService, new NullLogger(), mockEnvironment.Object); int idFormation = 1; - long nbFormationAvantSuppression = await formationService.GetFormationsCountAsync(null, null, null, null, null, null, null); + long nbFormationAvantSuppression = await formationService.GetFormationsCountAsync(null, null, null, null, null); // Act var noContentResult = formationsApiController.DeleteFormation(idFormation).Result as NoContentResult; // Assert - long nbFormationApresSuppression = await formationService.GetFormationsCountAsync(null, null, null, null, null, null, null); + long nbFormationApresSuppression = await formationService.GetFormationsCountAsync(null, null, null, null, null); Assert.AreEqual(nbFormationAvantSuppression -1, nbFormationApresSuppression); } diff --git a/EPAServeur.Tests/Services/FormationServiceTests.cs b/EPAServeur.Tests/Services/FormationServiceTests.cs index 9dccbe2..cefa3b6 100644 --- a/EPAServeur.Tests/Services/FormationServiceTests.cs +++ b/EPAServeur.Tests/Services/FormationServiceTests.cs @@ -439,13 +439,13 @@ namespace EPAServeur.Tests.Services #region Tests GetFormationsCountAsync - [TestCase(1, new int[] { 1, 2, 3 }, 1, 5, "formation", "2020-09-30", "2020-11-30")] - [TestCase(1, new int[] { 1 }, 1, 5, "Formation Mainframe Complčte", null, null)] - [TestCase(null, null, 2, 10, null, null, null)] - [TestCase(null, new int[] { 1 }, 1, 10, null, null, null)] - [TestCase(1, null, 1, 10, "for", null, null)] - [TestCase(1, new int[] { }, 1, 10, "for", null, null)] - public async Task GetFormationsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDeFormations(long? idAgence, int[] arrIdStatuts, int? numPage, int? parPAge, string texte, DateTime? dateDebut, DateTime? dateFin) + [TestCase(1, new int[] { 1, 2, 3 }, "formation", "2020-09-30", "2020-11-30")] + [TestCase(1, new int[] { 1 }, "Formation Mainframe Complčte", null, null)] + [TestCase(null, null, null, null, null)] + [TestCase(null, new int[] { 1 }, null, null, null)] + [TestCase(1, null, "for", null, null)] + [TestCase(1, new int[] { }, "for", null, null)] + public async Task GetFormationsCountAsync_PasseDesParamsValides_RetourneLeNombreTotalDeFormations(long? idAgence, int[] arrIdStatuts, string texte, DateTime? dateDebut, DateTime? dateFin) { // Arrange FormationService formationService = new FormationService(epContext, collaborateurService); @@ -457,16 +457,16 @@ namespace EPAServeur.Tests.Services idStatuts = null; // Act - long count = await formationService.GetFormationsCountAsync(idAgence, idStatuts, numPage, parPAge, texte, dateDebut, dateFin); + long count = await formationService.GetFormationsCountAsync(idAgence, idStatuts, texte, dateDebut, dateFin); // Assert Assert.Less(0, count); } - [TestCase(1, new int[] { 1 }, 1, 15, "azerty", null, null)] - [TestCase(-1, new int[] { -1 }, -1, -1, "azerty", null, null)] - [TestCase(0, new int[] { 0 }, 0, 0, null, null, null)] - public async Task GetFormationsCountAsync_PasseDesParamsInvalides_RetourneZero(long? idAgence, int[] arrIdStatuts, int? numPage, int? parPAge, string texte, DateTime? dateDebut, DateTime? dateFin) + [TestCase(1, new int[] { 1 }, "azerty", null, null)] + [TestCase(-1, new int[] { -1 }, "azerty", null, null)] + [TestCase(0, new int[] { 0 }, null, null, null)] + public async Task GetFormationsCountAsync_PasseDesParamsInvalides_RetourneZero(long? idAgence, int[] arrIdStatuts, string texte, DateTime? dateDebut, DateTime? dateFin) { // Arrange FormationService formationService = new FormationService(epContext, collaborateurService); @@ -478,7 +478,7 @@ namespace EPAServeur.Tests.Services idStatuts = null; // Act - long count = await formationService.GetFormationsCountAsync(idAgence, idStatuts, numPage, parPAge, texte, dateDebut, dateFin); + long count = await formationService.GetFormationsCountAsync(idAgence, idStatuts, texte, dateDebut, dateFin); // Assert Assert.AreEqual(0, count); diff --git a/EPAServeur/Controllers/FormationsApi.cs b/EPAServeur/Controllers/FormationsApi.cs index 5ec93ff..d2c750a 100644 --- a/EPAServeur/Controllers/FormationsApi.cs +++ b/EPAServeur/Controllers/FormationsApi.cs @@ -330,11 +330,7 @@ namespace IO.Swagger.Controllers /// RĂ©cupĂ©rer le nombre total de formations. /// id de l'agence Ă  laquelle sont rattachĂ©es les donnĂ©es Ă  rĂ©cupĂ©rer /// liste des ids des statuts des formations Ă  rĂ©cupĂ©rer - /// Indique si les donnĂ©es sont rĂ©cupĂ©rĂ©es dans l'ordre croissant ou non - /// NumĂ©ro de la page du tableau Ă  afficher - /// Nombre d’élĂ©ment maximum Ă  afficher dans le tableau /// Texte permettant de filtrer les donnĂ©es - /// Colonne du tableau sur lequel le tri devra ĂŞtre effectuĂ© /// Date Ă  partir de laquelle les donnĂ©es son rĂ©cupĂ©rĂ©es /// Date jusqu'Ă  laquelle les donnĂ©es sont rĂ©cupĂ©rĂ©es /// OK @@ -350,7 +346,7 @@ namespace IO.Swagger.Controllers [SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L'utilisateur souhaitant accĂ©der Ă  la ressource n'est pas authentifiĂ©")] [SwaggerResponse(statusCode: 403, type: typeof(ErreurDTO), description: "L’utilisateur souhaitant accĂ©der Ă  la ressource n’a pas les droits d’accès suffisants")] [SwaggerResponse(statusCode: 500, type: typeof(ErreurDTO), description: "Une erreur est survenue sur le serveur")] - public virtual async Task GetFormationsCount([FromQuery] long? idAgence, [FromQuery] List idStatuts, [FromQuery] int? numPage, [FromQuery][Range(5, 100)][DefaultValue(15)] int? parPAge, [FromQuery] string texte, [FromQuery] DateTime? dateDebut, [FromQuery] DateTime? dateFin) + public virtual async Task GetFormationsCount([FromQuery] long? idAgence, [FromQuery] List idStatuts, [FromQuery] string texte, [FromQuery] DateTime? dateDebut, [FromQuery] DateTime? dateFin) { if (env.IsDevelopment()) logger.LogInformation("RĂ©cupĂ©ration du nombre total de formations."); @@ -359,7 +355,7 @@ namespace IO.Swagger.Controllers try { - count = await formationService.GetFormationsCountAsync(idAgence, idStatuts, numPage, parPAge, texte, dateDebut, dateFin); + count = await formationService.GetFormationsCountAsync(idAgence, idStatuts, texte, dateDebut, dateFin); } catch (Exception e) { diff --git a/EPAServeur/IServices/IFormationService.cs b/EPAServeur/IServices/IFormationService.cs index 099e065..419947f 100644 --- a/EPAServeur/IServices/IFormationService.cs +++ b/EPAServeur/IServices/IFormationService.cs @@ -12,7 +12,7 @@ namespace EPAServeur.IServices { Task GetFormationByIdAsync(long idFormation); Task> GetFormationsAsync(long? idAgence, List idStatuts, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin); - Task GetFormationsCountAsync(long? idAgence, List idStatuts, int? numPage, int? parPage, string texte, DateTime? dateDebut, DateTime? dateFin); + Task GetFormationsCountAsync(long? idAgence, List idStatuts, string texte, DateTime? dateDebut, DateTime? dateFin); Task> GetModesFormationAsync(); Task> GetOriginesFormationAsync(); Task> GetStatutsFormationAsync(); diff --git a/EPAServeur/Services/FormationService.cs b/EPAServeur/Services/FormationService.cs index 2cd314d..147d9bb 100644 --- a/EPAServeur/Services/FormationService.cs +++ b/EPAServeur/Services/FormationService.cs @@ -144,7 +144,7 @@ namespace EPAServeur.Services /// id de l'agence Ă  laquelle sont rattachĂ©es les donnĂ©es Ă  rĂ©cupĂ©rer /// Texte permettant d'identifier l'objet rechercher /// - public async Task GetFormationsCountAsync(long? idAgence, List idStatuts, int? numPage, int? parPage, string texte, DateTime? dateDebut, DateTime? dateFin) + public async Task GetFormationsCountAsync(long? idAgence, List idStatuts, string texte, DateTime? dateDebut, DateTime? dateFin) { IQueryable query; long count; @@ -165,8 +165,6 @@ namespace EPAServeur.Services query = DateFilter(query, dateDebut, dateFin); - query = SkipAndTake(query, parPage, numPage); - count = await query.CountAsync(); return count; From 5e3c971282dda00dabbac9abccaf581e488e963e Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Fri, 19 Feb 2021 13:47:49 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Ajout=20du=20tri=20pour=20le=20nombre=20de?= =?UTF-8?q?=20participant=20=C3=A0=20une=20formation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EPAServeur/Services/FormationService.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/EPAServeur/Services/FormationService.cs b/EPAServeur/Services/FormationService.cs index 147d9bb..e712c18 100644 --- a/EPAServeur/Services/FormationService.cs +++ b/EPAServeur/Services/FormationService.cs @@ -418,6 +418,11 @@ namespace EPAServeur.Services return query.OrderBy(p => p.EstCertifiee); else return query.OrderByDescending(p => p.EstCertifiee); + case "participants": + if (asc.Value) + return query.OrderBy(p => p.ParticipationsFormation.Count); + else + return query.OrderByDescending(p => p.ParticipationsFormation.Count); default: if (asc.Value) return query.OrderBy(p => p.Intitule); From 647ac6537f3fc2fbcc50839d8c83404378b249a8 Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Fri, 19 Feb 2021 13:49:27 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Ajout=20des=20tests=20unitaires=20pour=20le?= =?UTF-8?q?=20tri=20du=20nombre=20de=20participant=20=C3=A0=20une=20format?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/FormationServiceTests.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/EPAServeur.Tests/Services/FormationServiceTests.cs b/EPAServeur.Tests/Services/FormationServiceTests.cs index cefa3b6..e2954c5 100644 --- a/EPAServeur.Tests/Services/FormationServiceTests.cs +++ b/EPAServeur.Tests/Services/FormationServiceTests.cs @@ -261,6 +261,36 @@ namespace EPAServeur.Tests.Services } + [TestCase(true, "participants")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParNombreDeParticipantsCroissant(bool? asc, string tri) + { + // Arrange + FormationService formationService = new FormationService(epContext, collaborateurService); + + // Act + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); + + // Assert + Assert.AreEqual(0, formationDTOs.First().NbParticipations); + Assert.AreEqual(3, formationDTOs.Last().NbParticipations); + + } + + [TestCase(false, "participants")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParNombreDeParticipantsDecroissant(bool? asc, string tri) + { + // Arrange + FormationService formationService = new FormationService(epContext, collaborateurService); + + // Act + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); + + // Assert + Assert.AreEqual(3, formationDTOs.First().NbParticipations); + Assert.AreEqual(0, formationDTOs.Last().NbParticipations); + + } + [TestCase(true, "origine")] public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineCroissante(bool? asc, string tri) {