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;