From bb67f315cd402cdcbf970f9ce9e7e2ffa757caf4 Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Thu, 14 Jan 2021 10:34:52 +0100 Subject: [PATCH] MAJ des TU suite aux modifications des exceptions dans le service formation --- .../Services/FormationServiceTests.cs | 796 ++++-------------- 1 file changed, 169 insertions(+), 627 deletions(-) diff --git a/EPAServeur.Tests/Services/FormationServiceTests.cs b/EPAServeur.Tests/Services/FormationServiceTests.cs index fd124db..d60667a 100644 --- a/EPAServeur.Tests/Services/FormationServiceTests.cs +++ b/EPAServeur.Tests/Services/FormationServiceTests.cs @@ -50,49 +50,7 @@ namespace EPAServeur.Tests.Services #endregion - #region Tests GetFormationById et GetFormationByIdAsync - - [Test] - public void GetFormationById_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormation() - { - // Arrange - FormationService formationService = new FormationService(epContext); - - // Act - FormationDTO formationDTO = formationService.GetFormationById(1); - - // Assert - Assert.AreEqual(1, formationDTO.Id); - Assert.AreEqual("Formation1", formationDTO.Intitule); - Assert.AreEqual(1, formationDTO.IdAgence); - Assert.AreEqual(new DateTime(2020, 9, 16, 10, 0, 0), formationDTO.DateDebut); - Assert.AreEqual(new DateTime(2020, 9, 16), formationDTO.DateFin); - Assert.AreEqual(2, formationDTO.Heure); - Assert.AreEqual(1, formationDTO.Jour); - Assert.AreEqual("Organisme1", formationDTO.Organisme); - Assert.False(formationDTO.EstCertifiee); - Assert.AreEqual(new OrigineFormationDTO { Id = 2, Libelle = "Exigence client" }, formationDTO.Origine); - Assert.AreEqual(new StatutFormationDTO { Id = 1, Libelle = "Planifiée" }, formationDTO.Statut); - Assert.AreEqual(new ModeFormationDTO { Id = 4, Libelle = "E-learning" }, formationDTO.Mode); - Assert.AreEqual(new TypeFormationDTO { Id = 3, Libelle = "E-learning" }, formationDTO.Type); - } - - [TestCase(-1)] - [TestCase(0)] - [TestCase(999999)] - [TestCase(null)] - public void GetFormationById_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long? value) - { - // Arrange - FormationService formationService = new FormationService(epContext); - - // Act - TestDelegate throwException = () => formationService.GetFormationById(value); - - // Assert - Assert.Throws(typeof(FormationNotFoundException), throwException); - } - + #region Tests GetFormationByIdAsync [Test] public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormation() { @@ -107,7 +65,7 @@ namespace EPAServeur.Tests.Services Assert.AreEqual("Formation1", formationDTO.Intitule); Assert.AreEqual(1, formationDTO.IdAgence); Assert.AreEqual(new DateTime(2020, 9, 16, 10, 0, 0), formationDTO.DateDebut); - Assert.AreEqual(new DateTime(2020, 9, 16), formationDTO.DateFin); + Assert.AreEqual(new DateTime(2020, 9, 17), formationDTO.DateFin); Assert.AreEqual(2, formationDTO.Heure); Assert.AreEqual(1, formationDTO.Jour); Assert.AreEqual("Organisme1", formationDTO.Organisme); @@ -121,14 +79,13 @@ namespace EPAServeur.Tests.Services [TestCase(-1)] [TestCase(0)] [TestCase(999999)] - [TestCase(null)] - public void GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long? value) + public void GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long idFormation) { // Arrange FormationService formationService = new FormationService(epContext); // Act - AsyncTestDelegate throwException = () => formationService.GetFormationByIdAsync(value); + AsyncTestDelegate throwException = () => formationService.GetFormationByIdAsync(idFormation); // Assert Assert.ThrowsAsync(typeof(FormationNotFoundException), throwException); @@ -136,271 +93,263 @@ namespace EPAServeur.Tests.Services #endregion - #region Tests GetFormations et GetFormationsAsync + #region Tests GetFormationsAsync - [TestCase(true, 1, 5, 1, 1, "formation", null)] - [TestCase(false, 1, 5, 1, 1, "formation1", null)] - [TestCase(null, 2, 10, null, null, null, null)] - [TestCase(null, 1, 10, null, 1, null, null)] - [TestCase(null, 1, 10, 1, null, "for", null)] - public void GetFormations_PasseDesParamsValides_RetourneDesFormations(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri) + [TestCase(1, new int[] { 1, 2, 3 }, true, 1, 5, "formation", null, null, null)] + [TestCase(1, new int[] { 1 }, false, 1, 5, "formation1", null, null, null)] + [TestCase(null, null, null, 2, 10, null, null, null, null)] + [TestCase(null, new int[] { 1 }, null, 1, 10, null, null, null, null)] + [TestCase(1, null, null, 1, 10, "for", null, null, null)] + [TestCase(1, new int[] { }, null, 1, 10, "for", null, null, null)] + 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); + List idStatuts; + + if (arrIdStatuts != null) + idStatuts = arrIdStatuts.Select(x => (int?)x).ToList(); + else + idStatuts = null; // Act - IEnumerable formationDTOs = formationService.GetFormations(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(idAgence, idStatuts, asc, numPage, parPAge, texte, tri, dateDebut, dateFin); // Assert Assert.Less(0, formationDTOs.Count()); } - [TestCase(true, 1, 15, 1, 1, "azerty", null)] - [TestCase(null, -1, -1, -1, -1, "azerty", null)] - [TestCase(null, 0, 0, 0, 0, null, null)] - public void GetFormations_PasseDesParamsInvalides_RetourneZeroFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri) + [TestCase(true, "intitule")] + [TestCase(true, null)] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleCroissant(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = formationService.GetFormations(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.AreEqual(0, formationDTOs.Count()); + Assert.AreEqual("Formation1", formationDTOs.First().Intitule); + Assert.AreEqual("Formation9", formationDTOs.Last().Intitule); + } - [TestCase(true, 1, 5, 1, 1, "formation", null)] - [TestCase(false, 1, 5, 1, 1, "formation1", null)] - [TestCase(null, 2, 10, null, null, null, null)] - [TestCase(null, 1, 10, null, 1, null, null)] - [TestCase(null, 1, 10, 1, null, "for", null)] - public async Task GetFormationsAsync_PasseDesParamsValides_RetourneDesFormations(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri) + [TestCase(false, "intitule")] + [TestCase(false, null)] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParIntituleDecroissant(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = await formationService.GetFormationsAsync(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.Less(0, formationDTOs.Count()); + Assert.AreEqual("Formation9", formationDTOs.First().Intitule); + Assert.AreEqual("Formation1", formationDTOs.Last().Intitule); + } - [TestCase(true, 1, 15, 1, 1, "azerty", null)] - [TestCase(null, -1, -1, -1, -1, "azerty", null)] - [TestCase(null, 0, 0, 0, 0, null, null)] - public async Task GetFormationsAsync_PasseDesParamsInvalides_RetourneZeroFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri) + [TestCase(true, "statut")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutCroissant(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = await formationService.GetFormationsAsync(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.AreEqual(0, formationDTOs.Count()); - } - - #endregion + Assert.AreEqual("Annulée", formationDTOs.First().Statut.Libelle); + Assert.AreEqual("Replanifiée", formationDTOs.Last().Statut.Libelle); - #region Tests GetFormationAnnulees et GetFormationAnnuleesAsync + } - [TestCase(true, 1, 5, 1, "formation", null)] - [TestCase(false, 1, 5, 1, "formation10", null)] - [TestCase(null, 2, 1, null, null, null)] - [TestCase(null, 1, 10, null, null, null)] - [TestCase(null, 1, 10, 1, "for", null)] - public void GetFormationAnnulees_PasseDesParamsValides_RetourneDesFormationsAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase(false, "statut")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParStatutDecroissant(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = formationService.GetFormationAnnulees(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.Less(0, formationDTOs.Count()); + Assert.AreEqual("Replanifiée", formationDTOs.First().Statut.Libelle); + Assert.AreEqual("Annulée", formationDTOs.Last().Statut.Libelle); + } - [TestCase(true, 1, 15, 1, "azerty", null)] - [TestCase(null, -1, -1, -1, "azerty", null)] - [TestCase(null, 0, 0, 0, null, null)] - public void GetFormationAnnulees_PasseDesParamsInvalides_RetourneZeroFormationAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase(true, "origine")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineCroissante(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = formationService.GetFormationAnnulees(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.AreEqual(0, formationDTOs.Count()); + Assert.AreEqual("Demande collaborateur", formationDTOs.First().Origine.Libelle); + Assert.AreEqual("Formation réglementaire", formationDTOs.Last().Origine.Libelle); + } - [TestCase(true, 1, 5, 1, "formation", null)] - [TestCase(false, 1, 5, 1, "formation1", null)] - [TestCase(null, 2, 1, null, null, null)] - [TestCase(null, 1, 10, null, null, null)] - [TestCase(null, 1, 10, 1, "for", null)] - public async Task GetFormationAnnuleesAsync_PasseDesParamsValides_RetourneDesFormationsAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase(false, "origine")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParOrigineDecroissante(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = await formationService.GetFormationAnnuleesAsync(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.Less(0, formationDTOs.Count()); + Assert.AreEqual("Formation réglementaire", formationDTOs.First().Origine.Libelle); + Assert.AreEqual("Demande collaborateur", formationDTOs.Last().Origine.Libelle); + } - [TestCase(true, 1, 15, 1, "azerty", null)] - [TestCase(null, -1, -1, -1, "azerty", null)] - [TestCase(null, 0, 0, 0, null, null)] - public async Task GetFormationAnnuleesAsync_PasseDesParamsInvalides_RetourneZeroFormationAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase(true, "date")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateCroissante(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = await formationService.GetFormationAnnuleesAsync(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.AreEqual(0, formationDTOs.Count()); - } - - #endregion + Assert.AreEqual(new DateTime(2020, 04, 6, 9, 0, 0), formationDTOs.First().DateDebut); + Assert.AreEqual(new DateTime(2020, 11, 18, 10, 0, 0), formationDTOs.Last().DateDebut); - #region Tests GetFormationRealisee et GetFormationRealiseeAsync + } - [TestCase(true, 1, 5, 1, "formation", null)] - [TestCase(false, 1, 5, 1, "formation4", null)] - [TestCase(null, 2, 1, null, null, null)] - [TestCase(null, 1, 10, null, null, null)] - [TestCase(null, 1, 10, 1, "for", null)] - public void GetFormationRealisee_PasseDesParamsValides_RetourneDesFormationsRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase(false, "date")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParDateDecroissante(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = formationService.GetFormationRealisees(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.Less(0, formationDTOs.Count()); + Assert.AreEqual(new DateTime(2020, 11, 18, 10, 0, 0), formationDTOs.First().DateDebut); + Assert.AreEqual(new DateTime(2020, 04, 6, 9, 0, 0), formationDTOs.Last().DateDebut); + } - [TestCase(true, 1, 15, 1, "azerty", null)] - [TestCase(null, -1, -1, -1, "azerty", null)] - [TestCase(null, 0, 0, 0, null, null)] - public void GetFormationRealisee_PasseDesParamsInvalides_RetourneZeroFormationRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase(true, "certification")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationCroissante(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = formationService.GetFormationRealisees(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.AreEqual(0, formationDTOs.Count()); + Assert.AreEqual(false, formationDTOs.First().EstCertifiee); + Assert.AreEqual(true, formationDTOs.Last().EstCertifiee); + } - [TestCase(true, 1, 5, 1, "formation", null)] - [TestCase(false, 1, 5, 1, "formation4", null)] - [TestCase(null, 2, 1, null, null, null)] - [TestCase(null, 1, 10, null, null, null)] - [TestCase(null, 1, 10, 1, "for", null)] - public async Task GetFormationRealiseeAsync_PasseDesParamsValides_RetourneDesFormationsRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase(false, "certification")] + public async Task GetFormationsAsync_PasseEnParamAscEtTri_RetourneDesFormationsOrdonnanceeParCertificationDecroissante(bool? asc, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = await formationService.GetFormationRealiseesAsync(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, asc, null, null, null, tri, null, null); // Assert - Assert.Less(0, formationDTOs.Count()); + Assert.AreEqual(true, formationDTOs.First().EstCertifiee); + Assert.AreEqual(false, formationDTOs.Last().EstCertifiee); + } - [TestCase(true, 1, 15, 1, "azerty", null)] - [TestCase(null, -1, -1, -1, "azerty", null)] - [TestCase(null, 0, 0, 0, null, null)] - public async Task GetFormationRealiseeAsync_PasseDesParamsInvalides_RetourneZeroFormationRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + + [TestCase("2020-10-01")] + public async Task GetFormationsAsync_PasseEnParamUneDateDeDebut_RetourneDesFormationsAvecUneDateDeDebutSuperieur(DateTime dateDebut) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = await formationService.GetFormationRealiseesAsync(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, null); // Assert - Assert.AreEqual(0, formationDTOs.Count()); - } - - #endregion + Assert.Greater(formationDTOs.First().DateDebut, dateDebut); + Assert.GreaterOrEqual(formationDTOs.Last().DateDebut, dateDebut); - #region Tests GetProchainesFormation et GetProchainesFormationAsync + } - [TestCase(true, 1, 5, 1, "formation", null)] - [TestCase(false, 1, 5, 1, "formation1", null)] - [TestCase(null, 2, 1, null, null, null)] - [TestCase(null, 1, 10, null, null, null)] - [TestCase(null, 1, 10, 1, "for", null)] - public void GetProchainesFormation_PasseDesParamsValides_RetourneDesProchainesFormations(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase("2020-10-01")] + public async Task GetFormationsAsync_PasseEnParamUneDateDeFin_RetourneDesFormationsAvecUneDateDeFinInferieur(DateTime dateFin) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = formationService.GetProchainesFormation(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, null, dateFin); // Assert - Assert.Less(0, formationDTOs.Count()); + Assert.Less(formationDTOs.First().DateFin, dateFin); + Assert.LessOrEqual(formationDTOs.Last().DateFin, dateFin); + } - [TestCase(true, 1, 15, 1, "azerty", null)] - [TestCase(null, -1, -1, -1, "azerty", null)] - [TestCase(null, 0, 0, 0, null, null)] - public void GetProchainesFormation_PasseDesParamsInvalides_RetourneZeroProchaineFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase("2020-10-01", "2020-11-01")] + public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutEtUneDateDeFin_RetourneDesFormationsAvecUneDateDeDebutSuperieurUneDateDeFinInferieur(DateTime dateDebut, DateTime dateFin) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = formationService.GetProchainesFormation(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin); // Assert - Assert.AreEqual(0, formationDTOs.Count()); + Assert.Greater(formationDTOs.First().DateDebut, dateDebut); + Assert.Less(formationDTOs.First().DateFin, dateFin); + + Assert.GreaterOrEqual(formationDTOs.Last().DateDebut, dateDebut); + Assert.LessOrEqual(formationDTOs.Last().DateFin, dateFin); + } - [TestCase(true, 1, 5, 1, "formation", null)] - [TestCase(false, 1, 5, 1, "formation1", null)] - [TestCase(null, 2, 1, null, null, null)] - [TestCase(null, 1, 10, null, null, null)] - [TestCase(null, 1, 10, 1, "for", null)] - public async Task GetProchainesFormationAsync_PasseDesParamsValides_RetourneDesProchainesFormations(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase("2020-11-01", "2020-10-01")] + public async Task GetFormationsAsync_PasseEnParamUneDateDeDebutSuperieurEtUneDateDeFinInferieur_RetourneZeroFormation(DateTime dateDebut, DateTime dateFin) { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable formationDTOs = await formationService.GetProchainesFormationAsync(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(null, null, null, null, null, null, null, dateDebut, dateFin); // Assert - Assert.Less(0, formationDTOs.Count()); + Assert.AreEqual(0, formationDTOs.Count()); } - [TestCase(true, 1, 15, 1, "azerty", null)] - [TestCase(null, -1, -1, -1, "azerty", null)] - [TestCase(null, 0, 0, 0, null, null)] - public async Task GetProchainesFormationAsync_PasseDesParamsInvalides_RetourneZeroProchaineFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) + [TestCase(1, new int[] { 1 }, true, 1, 15, "azerty", null, null, null)] + [TestCase(-1, new int[] { -1 }, null, -1, -1, "azerty", null, null, null)] + [TestCase(0, new int[] { 0 }, null, 0, 0, null, null, null, null)] + 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); + List idStatuts; + + if (arrIdStatuts != null) + idStatuts = arrIdStatuts.Select(x => (int?)x).ToList(); + else + idStatuts = null; + // Act - IEnumerable formationDTOs = await formationService.GetProchainesFormationAsync(asc, numPage, parPAge, idAgence, texte, tri); + IEnumerable formationDTOs = await formationService.GetFormationsAsync(idAgence, idStatuts, asc, numPage, parPAge, texte, tri, dateDebut, dateFin); // Assert Assert.AreEqual(0, formationDTOs.Count()); @@ -408,54 +357,76 @@ namespace EPAServeur.Tests.Services #endregion - #region Tests GetModesFormation et GetModesFormationAsync + #region Tests GetFormationsCountAsync - [Test] - public void GetModesFormation_RetourneTousLesModesDeFormation() + [TestCase(1, new int[] { 1, 2, 3 }, 1, 5, "formation", "2020-09-30", "2020-11-30")] + [TestCase(1, new int[] { 1 }, 1, 5, "formation1", 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) { // Arrange FormationService formationService = new FormationService(epContext); + List idStatuts; + + if (arrIdStatuts != null) + idStatuts = arrIdStatuts.Select(x => (int?)x).ToList(); + else + idStatuts = null; // Act - IEnumerable modeFormationDTOs = formationService.GetModesFormation(); + long count = await formationService.GetFormationsCountAsync(idAgence, idStatuts, numPage, parPAge, texte, dateDebut, dateFin); // Assert - Assert.IsNotNull(modeFormationDTOs); - Assert.AreEqual(4, modeFormationDTOs.Count()); // Nombre total de mode de formation dans la classe DataSeeder le 2020-10-31 + Assert.Less(0, count); } - [Test] - public async Task GetModesFormationAsync_RetourneTousLesModesDeFormation() + [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) { // Arrange FormationService formationService = new FormationService(epContext); + List idStatuts; + + if (arrIdStatuts != null) + idStatuts = arrIdStatuts.Select(x => (int?)x).ToList(); + else + idStatuts = null; // Act - IEnumerable modeFormationDTOs = await formationService.GetModesFormationAsync(); + long count = await formationService.GetFormationsCountAsync(idAgence, idStatuts, numPage, parPAge, texte, dateDebut, dateFin); // Assert - Assert.IsNotNull(modeFormationDTOs); - Assert.AreEqual(4, modeFormationDTOs.Count()); // Nombre total de mode de formation dans la classe DataSeeder le 2020-10-31 + Assert.AreEqual(0, count); } #endregion - #region Tests GetOriginesFormation et GetOriginesFormationAsync + + #region Tests GetModesFormationAsync [Test] - public void GetOriginesFormation_RetourneToutesLesOriginesDeFormation() + public async Task GetModesFormationAsync_RetourneTousLesModesDeFormation() { // Arrange FormationService formationService = new FormationService(epContext); // Act - IEnumerable origineFormationDTOs = formationService.GetOriginesFormation(); + IEnumerable modeFormationDTOs = await formationService.GetModesFormationAsync(); // Assert - Assert.IsNotNull(origineFormationDTOs); - Assert.AreEqual(4, origineFormationDTOs.Count()); // Nombre total d'origine de formation dans la classe DataSeeder le 2020-10-31 + Assert.IsNotNull(modeFormationDTOs); + Assert.AreEqual(4, modeFormationDTOs.Count()); // Nombre total de mode de formation dans la classe DataSeeder le 2020-10-31 } + #endregion + + #region Tests GetOriginesFormationAsync + [Test] public async Task GetOriginesAsyncFormation_RetourneToutesLesOriginesDeFormation() { @@ -472,21 +443,7 @@ namespace EPAServeur.Tests.Services #endregion - #region Tests GetStatutsFormation et GetStatutsFormationAsync - - [Test] - public void GetStatutsFormation_RetourneTousLesStatutsDeFormation() - { - // Arrange - FormationService formationService = new FormationService(epContext); - - // Act - IEnumerable statutFormationDTOs = formationService.GetStatutsFormation(); - - // Assert - Assert.IsNotNull(statutFormationDTOs); - Assert.AreEqual(4, statutFormationDTOs.Count()); // Nombre total de statut de formation dans la classe DataSeeder le 2020-10-31 - } + #region Tests GetStatutsFormationAsync [Test] public async Task GetStatutsFormationAsyncFormation_RetourneTousLesStatutsDeFormation() @@ -504,21 +461,7 @@ namespace EPAServeur.Tests.Services #endregion - #region Tests GetTypesFormation et GetTypesFormationAsync - - [Test] - public void GetTypesFormation_RetourneTousLesTypesDeFormation() - { - // Arrange - FormationService formationService = new FormationService(epContext); - - // Act - IEnumerable typeFormationDTOs = formationService.GetTypesFormation(); - - // Assert - Assert.IsNotNull(typeFormationDTOs); - Assert.AreEqual(4, typeFormationDTOs.Count()); // Nombre total de type de formation dans la classe DataSeeder le 2020-10-31 - } + #region Tests GetTypesFormationAsync [Test] public async Task GetTypesFormationAsync_RetourneTousLesTypesDeFormation() @@ -536,60 +479,7 @@ namespace EPAServeur.Tests.Services #endregion - #region Tests AddFormation et AddFormationAsync - - [TestCase(1, 1, 3, 1, 1, "Test ajout formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 1, 1, "Test ajout formation", "Apside", "2020-10-31", "2020-10-31")] - [TestCase(1, 1, 3, 1, 1, "Test ajout formation", "Apside", "2020-11-02", "2020-11-02")] - public void AddFormation_AjouteUneFormationValide_FormationAjouteeAvecSucces(int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) - { - // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) - .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - - FormationDTO formation = new FormationDTO - { - Intitule = intitule, - IdAgence = idAgence, - DateDebut = dateDebut, - DateFin = dateFin, - Heure = 2, - Jour = 1, - Mode = modeExterne, - Type = typeELearning, - Organisme = organisme, - Origine = origineFormationCollaborateur, - Statut = statutPlanifie, - EstCertifiee = false - }; - - FormationService formationService = new FormationService(epContext); - - // Act - FormationDTO formationAjoute = formationService.AddFormation(formation); - - // Assert - Assert.IsNotNull(formationAjoute); - Assert.AreEqual(12, formationAjoute.Id); - Assert.AreEqual(formation.Intitule, formationAjoute.Intitule); - Assert.AreEqual(formation.IdAgence, formationAjoute.IdAgence); - Assert.AreEqual(formation.DateDebut, formationAjoute.DateDebut); - Assert.AreEqual(formation.DateFin, formationAjoute.DateFin); - Assert.AreEqual(formation.Heure, formationAjoute.Heure); - Assert.AreEqual(formation.Jour, formationAjoute.Jour); - Assert.AreEqual(formation.Mode, formationAjoute.Mode); - Assert.AreEqual(formation.Type, formationAjoute.Type); - Assert.AreEqual(formation.Organisme, formationAjoute.Organisme); - Assert.AreEqual(formation.Origine, formationAjoute.Origine); - Assert.AreEqual(formation.Statut, formationAjoute.Statut); - Assert.AreEqual(formation.EstCertifiee, formationAjoute.EstCertifiee); - } + #region Tests AddFormationAsync [TestCase(1, 1, 3, 1, 1, "Test ajout formation", "Apside", "2020-10-31", "2020-11-02")] [TestCase(1, 1, 3, 1, 1, "Test ajout formation", "Apside", "2020-10-31", "2020-10-31")] @@ -644,22 +534,6 @@ namespace EPAServeur.Tests.Services Assert.AreEqual(formation.EstCertifiee, formationAjoute.EstCertifiee); } - [Test] - public void AddFormation_AjouteUneFormationNull_LeveUneFormationInvalidException() - { - - // Arrange - FormationDTO formation = null; - - FormationService formationService = new FormationService(epContext); - - // Act - TestDelegate throwException = () => formationService.AddFormation(formation); - - // Assert - Assert.Throws(typeof(FormationInvalidException), throwException); - } - [Test] public void AddFormationAsync_AjouteUneFormationNull_LeveUneFormationInvalidException() { @@ -676,57 +550,6 @@ namespace EPAServeur.Tests.Services Assert.ThrowsAsync(typeof(FormationInvalidException), throwException); } - [TestCase(1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-10-30")] - [TestCase(0, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 0, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 0, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 0, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 1, 0, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 1, 1, "", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 1, 1, "Test Formation", "", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 1, null, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 1, 1, null, "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 1, 1, "Test Formation", null, "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 3, 1, 1, "Test Formation", "Apside", null, "2020-11-02")] - [TestCase(1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", null)] - public void AddFormation_AjouteUneFormationAvecDesProprietesInvalides_LeveUneFormationInvalidException(int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) - { - - // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.IdOrigineFormation == idOrigine) - .Select(mode => new OrigineFormationDTO { Id = mode.IdOrigineFormation, Libelle = mode.Libelle }).FirstOrDefault(); - - FormationDTO formation = new FormationDTO - { - Intitule = intitule, - IdAgence = idAgence, - DateDebut = dateDebut, - DateFin = dateFin, - Heure = 2, - Jour = 1, - Mode = modeExterne, - Type = typeELearning, - Organisme = organisme, - Origine = origineFormationCollaborateur, - Statut = statutPlanifie, - EstCertifiee = false - }; - - FormationService formationService = new FormationService(epContext); - - // Act - TestDelegate throwException = () => formationService.AddFormation(formation); - - // Assert - Assert.Throws(typeof(FormationInvalidException), throwException); - } - [TestCase(1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-10-30")] [TestCase(0, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] [TestCase(1, 0, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] @@ -776,52 +599,6 @@ namespace EPAServeur.Tests.Services Assert.ThrowsAsync(typeof(FormationInvalidException), throwException); } - [TestCase(0, 1, 3, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(1, 0, 3, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(1, 1, 0, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(1, 1, 3, 0, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(null, 1, 3, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(1, null, 3, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(1, 1, null, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(1, 1, 3, null, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(1, 1, 3, 1, "Externez", "Planifiée", "E-learning", "Demande collaborateur")] - [TestCase(1, 1, 3, 1, "Externe", "Planifiées", "E-learning", "Demande collaborateur")] - [TestCase(1, 1, 3, 1, "Externe", "Planifiée", "E-learnings", "Demande collaborateur")] - [TestCase(1, 1, 3, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateurs")] - public void AddFormation_AjouteUneFormationAvecDesObjetsEnfantsInvalides_LeveUneFormationInvalidException(int? idMode, int? idStatut, int? idType, int? idOrigine, string libelleMode, string libelleStatut, string libelleType, string libelleOrigine) - { - - // Arrange - ModeFormationDTO modeExterne = new ModeFormationDTO { Id = idMode, Libelle = libelleMode }; - StatutFormationDTO statutPlanifie = new StatutFormationDTO { Id = idStatut, Libelle = libelleStatut }; - TypeFormationDTO typeELearning = new TypeFormationDTO { Id = idType, Libelle = libelleType }; - OrigineFormationDTO origineFormationCollaborateur = new OrigineFormationDTO { Id = idOrigine, Libelle = libelleOrigine }; - - FormationDTO formation = new FormationDTO - { - Intitule = "Test Formation", - IdAgence = 1, - DateDebut = new DateTime(2020, 10, 31), - DateFin = new DateTime(2020, 11, 02), - Heure = 2, - Jour = 1, - Mode = modeExterne, - Type = typeELearning, - Organisme = "Apside", - Origine = origineFormationCollaborateur, - Statut = statutPlanifie, - EstCertifiee = false - }; - - FormationService formationService = new FormationService(epContext); - - // Act - TestDelegate throwException = () => formationService.AddFormation(formation); - - // Assert - Assert.Throws(typeof(FormationInvalidException), throwException); - } - [TestCase(0, 1, 3, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] [TestCase(1, 0, 3, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] [TestCase(1, 1, 0, 1, "Externe", "Planifiée", "E-learning", "Demande collaborateur")] @@ -870,61 +647,10 @@ namespace EPAServeur.Tests.Services #endregion - #region Tests UpdateFormation et UpdateFormationAsync - - [TestCase(1, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - public void UpdateFormation_ModifieUneFormationValide_FormationModifieeAvecSucces(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) - { - // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - 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); - - FormationDTO formation = formationService.GetFormationById(idFormation); - - formation.Intitule = intitule; - formation.IdAgence = idAgence; - formation.DateDebut = dateDebut; - formation.DateFin = dateFin; - formation.Heure = 2; - formation.Jour = 1; - formation.Mode = modeExterne; - formation.Type = typeELearning; - formation.Organisme = organisme; - formation.Origine = origineFormationCollaborateur; - formation.Statut = statutPlanifie; - formation.EstCertifiee = false; - - - // Act - FormationDTO formationModifie = formationService.UpdateFormation(idFormation, formation); - - // Assert - Assert.IsNotNull(formationModifie); - Assert.AreEqual(idFormation, formationModifie.Id); - Assert.AreEqual(formation.Intitule, formationModifie.Intitule); - Assert.AreEqual(formation.IdAgence, formationModifie.IdAgence); - Assert.AreEqual(formation.DateDebut, formationModifie.DateDebut); - Assert.AreEqual(formation.DateFin, formationModifie.DateFin); - Assert.AreEqual(formation.Heure, formationModifie.Heure); - Assert.AreEqual(formation.Jour, formationModifie.Jour); - Assert.AreEqual(formation.Mode, formationModifie.Mode); - Assert.AreEqual(formation.Type, formationModifie.Type); - Assert.AreEqual(formation.Organisme, formationModifie.Organisme); - Assert.AreEqual(formation.Origine, formationModifie.Origine); - Assert.AreEqual(formation.Statut, formationModifie.Statut); - Assert.AreEqual(formation.EstCertifiee, formationModifie.EstCertifiee); - } + #region Tests UpdateFormationAsync [TestCase(1, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - public async Task UpdateFormationAsync_ModifieUneFormationValide_FormationModifieeAvecSucces(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) + public async Task UpdateFormationAsync_ModifieUneFormationValide_FormationModifieeAvecSucces(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) { // Arrange ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) @@ -987,57 +713,7 @@ namespace EPAServeur.Tests.Services [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", null, "2020-10-31", "2020-11-02")] [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", null, "2020-11-02")] [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", null)] - public void UpdateFormation_ModifieUneFormationAvecDesProprietesInvalides_LeveUneFormationInvalidException(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) - { - - // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - 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); - - FormationDTO formation = formationService.GetFormationById(idFormation); - - formation.Intitule = intitule; - formation.IdAgence = idAgence; - formation.DateDebut = dateDebut; - formation.DateFin = dateFin; - formation.Heure = 2; - formation.Jour = 1; - formation.Mode = modeExterne; - formation.Type = typeELearning; - formation.Organisme = organisme; - formation.Origine = origineFormationCollaborateur; - formation.Statut = statutPlanifie; - formation.EstCertifiee = false; - - // Act - TestDelegate throwException = () => formationService.UpdateFormation(idFormation, formation); - - // Assert - Assert.Throws(typeof(FormationInvalidException), throwException); - } - - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-10-30")] - [TestCase(1, 0, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 0, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 0, 1, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 0, 1, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 0, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, null, "Test Formation", "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, null, "Apside", "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", null, "2020-10-31", "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", null, "2020-11-02")] - [TestCase(1, 1, 1, 3, 1, 1, "Test Formation", "Apside", "2020-10-31", null)] - public async Task UpdateFormationAsync_ModifieUneFormationAvecDesProprietesInvalides_LeveUneFormationInvalidException(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) + public async Task UpdateFormationAsync_ModifieUneFormationAvecDesProprietesInvalides_LeveUneFormationInvalidException(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) { // Arrange @@ -1075,45 +751,7 @@ namespace EPAServeur.Tests.Services } [TestCase(2, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - [TestCase(null, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - public void UpdateFormation_ModifieUneFormationAvecUnIdIncorrecte_LeveUneFormationIncompatibleIdException(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) - { - // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - 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); - - FormationDTO formation = formationService.GetFormationById(1); - - formation.Id = idFormation; - formation.Intitule = intitule; - formation.IdAgence = idAgence; - formation.DateDebut = dateDebut; - formation.DateFin = dateFin; - formation.Heure = 2; - formation.Jour = 1; - formation.Mode = modeExterne; - formation.Type = typeELearning; - formation.Organisme = organisme; - formation.Origine = origineFormationCollaborateur; - formation.Statut = statutPlanifie; - formation.EstCertifiee = false; - - // Act - TestDelegate throwException = () => formationService.UpdateFormation(1, formation); - - // Assert - Assert.Throws(typeof(FormationIncompatibleIdException), throwException); - } - - [TestCase(2, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] + [TestCase(0, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] [TestCase(null, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] public async Task UpdateFormationAsync_ModifieUneFormationAvecUnIdIncorrecte_LeveUneFormationIncompatibleIdException(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) { @@ -1153,46 +791,7 @@ namespace EPAServeur.Tests.Services } [TestCase(0, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - public void UpdateFormation_ModifieUneFormationAvecUnIdInexistant_RetourneUnObjetNull(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) - { - // Arrange - ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) - .Select(mode => new ModeFormationDTO { Id = mode.IdModeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.IdStatutFormation == idStatut) - .Select(mode => new StatutFormationDTO { Id = mode.IdStatutFormation, Libelle = mode.Libelle }).FirstOrDefault(); - TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.IdTypeFormation == idType) - .Select(mode => new TypeFormationDTO { Id = mode.IdTypeFormation, Libelle = mode.Libelle }).FirstOrDefault(); - 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); - - FormationDTO formation = new FormationDTO - { - Id = idFormation, - Intitule = intitule, - IdAgence = idAgence, - DateDebut = dateDebut, - DateFin = dateFin, - Heure = 2, - Jour = 1, - Mode = modeExterne, - Type = typeELearning, - Organisme = organisme, - Origine = origineFormationCollaborateur, - Statut = statutPlanifie, - EstCertifiee = false - }; - - // Act - FormationDTO formationModifie = formationService.UpdateFormation(idFormation, formation); - - // Assert - Assert.IsNull(formationModifie); - } - - [TestCase(0, 2, 2, 1, 1, 2, "Test modification formation", "Apside", "2020-10-31", "2020-11-04")] - public async Task UpdateFormationAsync_ModifieUneFormationAvecUnIdInexistant_RetourneUnObjetNull(long? idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) + public void UpdateFormationAsync_ModifieUneFormationAvecUnIdInexistant_RetourneUnObjetNull(long idFormation, int? idMode, int? idStatut, int? idType, int? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) { // Arrange ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.IdModeFormation == idMode) @@ -1224,10 +823,10 @@ namespace EPAServeur.Tests.Services }; // Act - FormationDTO formationModifie = await formationService.UpdateFormationAsync(idFormation, formation); + AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(idFormation, formation); // Assert - Assert.IsNull(formationModifie); + Assert.ThrowsAsync(typeof(FormationNotFoundException), throwException); } @@ -1237,24 +836,7 @@ namespace EPAServeur.Tests.Services [TestCase(1)] [TestCase(2)] - public void DeleteFormationById_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long? idFormation) - { - // Arrange - FormationService formationService = new FormationService(epContext); - bool existFormation = true; - - // Act - FormationDTO formationSupprime = formationService.DeleteFormationById(idFormation); - - existFormation = epContext.Formation.Any(formation => formation.IdFormation == formationSupprime.Id.Value); - - // Assert - Assert.IsFalse(existFormation); - } - - [TestCase(1)] - [TestCase(2)] - public async Task DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long? idFormation) + public async Task DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long idFormation) { // Arrange FormationService formationService = new FormationService(epContext); @@ -1271,21 +853,7 @@ namespace EPAServeur.Tests.Services [TestCase(0)] [TestCase(-1)] - public void DeleteFormationById_SupprimeUneFormationAvecUnIdInvalide_LeveUneFormationNotFoundException(long? idFormation) - { - // Arrange - FormationService formationService = new FormationService(epContext); - - // Act - TestDelegate throwException = () => formationService.DeleteFormationById(idFormation); - - // Assert - Assert.Throws(typeof(FormationNotFoundException), throwException); - } - - [TestCase(0)] - [TestCase(-1)] - public void DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdInvalide_LeveUneFormationNotFoundException(long? idFormation) + public void DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdInvalide_LeveUneFormationNotFoundException(long idFormation) { // Arrange FormationService formationService = new FormationService(epContext); @@ -1297,32 +865,6 @@ namespace EPAServeur.Tests.Services Assert.ThrowsAsync(typeof(FormationNotFoundException), throwException); } - [Test] - public void DeleteFormationById_SupprimeUneFormationAvecUnIdNull_LeveUneFormationIncompatibleIdException() - { - // Arrange - FormationService formationService = new FormationService(epContext); - - // Act - TestDelegate throwException = () => formationService.DeleteFormationById(null); - - // Assert - Assert.Throws(typeof(FormationIncompatibleIdException), throwException); - } - - [Test] - public void DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdNull_LeveUneFormationIncompatibleIdException() - { - // Arrange - FormationService formationService = new FormationService(epContext); - - // Act - AsyncTestDelegate throwException = () => formationService.DeleteFormationByIdAsync(null); - - // Assert - Assert.ThrowsAsync(typeof(FormationIncompatibleIdException), throwException); - } - #endregion } } \ No newline at end of file