Merge branch 'formation' into develop

develop
jboinembalome 4 years ago
commit 8a4365547d
  1. 10
      EPAServeur.Tests/Controllers/FormationApiTests.cs
  2. 56
      EPAServeur.Tests/Services/FormationServiceTests.cs
  3. 8
      EPAServeur/Controllers/FormationsApi.cs
  4. 2
      EPAServeur/IServices/IFormationService.cs
  5. 9
      EPAServeur/Services/FormationService.cs

@ -175,7 +175,7 @@ namespace EPAServeur.Tests.Controllers
List<int?> idStatuts = new List<int?> { 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<OkObjectResult>(okResult.Result);
@ -187,10 +187,10 @@ namespace EPAServeur.Tests.Controllers
// Arrange
FormationsApiController formationsApiController = new FormationsApiController(formationService, new NullLogger<FormationsApiController>(), mockEnvironment.Object);
List<int?> idStatuts = new List<int?> { 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<long>(okResult.Value);
@ -589,13 +589,13 @@ namespace EPAServeur.Tests.Controllers
// Arrange
FormationsApiController formationsApiController = new FormationsApiController(formationService, new NullLogger<FormationsApiController>(), 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);
}

@ -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<FormationDetailsDTO> 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<FormationDetailsDTO> 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)
{
@ -439,13 +469,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 +487,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 +508,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);

@ -330,11 +330,7 @@ namespace IO.Swagger.Controllers
/// <remarks>Récupérer le nombre total de formations.</remarks>
/// <param name="idAgence">id de l&#x27;agence à laquelle sont rattachées les données à récupérer</param>
/// <param name="idStatuts">liste des ids des statuts des formations à récupérer</param>
/// <param name="asc">Indique si les données sont récupérées dans l&#x27;ordre croissant ou non</param>
/// <param name="numPage">Numéro de la page du tableau à afficher</param>
/// <param name="parPAge">Nombre d’élément maximum à afficher dans le tableau</param>
/// <param name="texte">Texte permettant de filtrer les données</param>
/// <param name="tri">Colonne du tableau sur lequel le tri devra être effectué</param>
/// <param name="dateDebut">Date à partir de laquelle les données son récupérées</param>
/// <param name="dateFin">Date jusqu&#x27;à laquelle les données sont récupérées</param>
/// <response code="200">OK</response>
@ -350,7 +346,7 @@ namespace IO.Swagger.Controllers
[SwaggerResponse(statusCode: 401, type: typeof(ErreurDTO), description: "L&#x27;utilisateur souhaitant accéder à la ressource n&#x27;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<IActionResult> GetFormationsCount([FromQuery] long? idAgence, [FromQuery] List<int?> 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<IActionResult> GetFormationsCount([FromQuery] long? idAgence, [FromQuery] List<int?> 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)
{

@ -12,7 +12,7 @@ namespace EPAServeur.IServices
{
Task<FormationDTO> GetFormationByIdAsync(long idFormation);
Task<IEnumerable<FormationDetailsDTO>> GetFormationsAsync(long? idAgence, List<int?> idStatuts, bool? asc, int? numPage, int? parPage, string texte, string tri, DateTime? dateDebut, DateTime? dateFin);
Task<long> GetFormationsCountAsync(long? idAgence, List<int?> idStatuts, int? numPage, int? parPage, string texte, DateTime? dateDebut, DateTime? dateFin);
Task<long> GetFormationsCountAsync(long? idAgence, List<int?> idStatuts, string texte, DateTime? dateDebut, DateTime? dateFin);
Task<IEnumerable<ModeFormationDTO>> GetModesFormationAsync();
Task<IEnumerable<OrigineFormationDTO>> GetOriginesFormationAsync();
Task<IEnumerable<StatutFormationDTO>> GetStatutsFormationAsync();

@ -144,7 +144,7 @@ namespace EPAServeur.Services
/// <param name="idAgence">id de l&#x27;agence à laquelle sont rattachées les données à récupérer</param>
/// <param name="texte">Texte permettant d&#x27;identifier l&#x27;objet rechercher</param>
/// <returns></returns>
public async Task<long> GetFormationsCountAsync(long? idAgence, List<int?> idStatuts, int? numPage, int? parPage, string texte, DateTime? dateDebut, DateTime? dateFin)
public async Task<long> GetFormationsCountAsync(long? idAgence, List<int?> idStatuts, string texte, DateTime? dateDebut, DateTime? dateFin)
{
IQueryable<Formation> 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;
@ -420,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);

Loading…
Cancel
Save