using EPAServeur.Context; using EPAServeur.Exceptions; using EPAServeur.Models.Formation; using EPAServeur.Services; using IO.Swagger.DTO; using Microsoft.EntityFrameworkCore; using NUnit.Framework; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace EPAServeur.Tests { public class FormationServiceTests { #region Variables private EpContext epContext; #endregion #region Setup [SetUp] public void Setup() { // Utilisation d'une base de données en mémoire var optionBuider = new DbContextOptionsBuilder() .UseInMemoryDatabase("server_ep_test") .Options; epContext = new EpContext(optionBuider); epContext.Database.EnsureDeleted(); epContext.Database.EnsureCreated(); epContext.SaveChanges(); // Ajout du jeu de données pour les tests DataSeeder.AddFormations(epContext); // Détache les entités du context car la base de données InMemory créé des conflits // entre les clés primaires lors d'un Update ou d'un Insert foreach (var entity in epContext.ChangeTracker.Entries()) { entity.State = EntityState.Detached; } } #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.EstCertifie); 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); } [Test] public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictif_RetourneUneFormation() { // Arrange FormationService formationService = new FormationService(epContext); // Act FormationDTO formationDTO = await formationService.GetFormationByIdAsync(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.EstCertifie); 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 GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictif_LeveUneFormationNotFoundException(long? value) { // Arrange FormationService formationService = new FormationService(epContext); // Act AsyncTestDelegate throwException = () => formationService.GetFormationByIdAsync(value); // Assert Assert.ThrowsAsync(typeof(FormationNotFoundException), throwException); } #endregion #region Tests GetFormations et 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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = formationService.GetFormations(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); // 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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = formationService.GetFormations(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); // Assert Assert.AreEqual(0, formationDTOs.Count()); } [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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); // 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 async Task GetFormationsAsync_PasseDesParamsInvalides_RetourneZeroFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, int? statutFormation, string texte, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = await formationService.GetFormationsAsync(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); // Assert Assert.AreEqual(0, formationDTOs.Count()); } #endregion #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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = formationService.GetFormationAnnulees(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.Less(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 void GetFormationAnnulees_PasseDesParamsInvalides_RetourneZeroFormationAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = formationService.GetFormationAnnulees(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.AreEqual(0, formationDTOs.Count()); } [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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = await formationService.GetFormationAnnuleesAsync(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.Less(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 GetFormationAnnuleesAsync_PasseDesParamsInvalides_RetourneZeroFormationAnnulees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = await formationService.GetFormationAnnuleesAsync(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.AreEqual(0, formationDTOs.Count()); } #endregion #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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = formationService.GetFormationRealisees(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.Less(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 void GetFormationRealisee_PasseDesParamsInvalides_RetourneZeroFormationRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = formationService.GetFormationRealisees(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.AreEqual(0, formationDTOs.Count()); } [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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = await formationService.GetFormationRealiseesAsync(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.Less(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 GetFormationRealiseeAsync_PasseDesParamsInvalides_RetourneZeroFormationRealisees(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = await formationService.GetFormationRealiseesAsync(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.AreEqual(0, formationDTOs.Count()); } #endregion #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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = formationService.GetProchainesFormation(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.Less(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 void GetProchainesFormation_PasseDesParamsInvalides_RetourneZeroProchaineFormation(bool? asc, int? numPage, int? parPAge, long? idAgence, string texte, string tri) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = formationService.GetProchainesFormation(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.AreEqual(0, formationDTOs.Count()); } [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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = await formationService.GetProchainesFormationAsync(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.Less(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) { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable formationDTOs = await formationService.GetProchainesFormationAsync(asc, numPage, parPAge, idAgence, texte, tri); // Assert Assert.AreEqual(0, formationDTOs.Count()); } #endregion #region Tests GetModesFormation et GetModesFormationAsync [Test] public void GetModesFormation_RetourneTousLesModesDeFormation() { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable modeFormationDTOs = formationService.GetModesFormation(); // Assert Assert.IsNotNull(modeFormationDTOs); Assert.AreEqual(4, modeFormationDTOs.Count()); // Nombre total de mode de formation dans la classe DataSeeder le 2020-10-31 } [Test] public async Task GetModesFormationAsync_RetourneTousLesModesDeFormation() { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable modeFormationDTOs = await formationService.GetModesFormationAsync(); // Assert 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 GetOriginesFormation et GetOriginesFormationAsync [Test] public void GetOriginesFormation_RetourneToutesLesOriginesDeFormation() { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable origineFormationDTOs = formationService.GetOriginesFormation(); // Assert Assert.IsNotNull(origineFormationDTOs); Assert.AreEqual(4, origineFormationDTOs.Count()); // Nombre total d'origine de formation dans la classe DataSeeder le 2020-10-31 } [Test] public async Task GetOriginesAsyncFormation_RetourneToutesLesOriginesDeFormation() { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable origineFormationDTOs = await formationService.GetOriginesFormationAsync(); // Assert Assert.IsNotNull(origineFormationDTOs); Assert.AreEqual(4, origineFormationDTOs.Count()); // Nombre total d'origine de formation dans la classe DataSeeder le 2020-10-31 } #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 } [Test] public async Task GetStatutsFormationAsyncFormation_RetourneTousLesStatutsDeFormation() { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable statutFormationDTOs = await formationService.GetStatutsFormationAsync(); // Assert Assert.IsNotNull(statutFormationDTOs); Assert.AreEqual(4, statutFormationDTOs.Count()); // Nombre total de statut de formation dans la classe DataSeeder le 2020-10-31 } #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 } [Test] public async Task GetTypesFormationAsync_RetourneTousLesTypesDeFormation() { // Arrange FormationService formationService = new FormationService(epContext); // Act IEnumerable typeFormationDTOs = await formationService.GetTypesFormationAsync(); // Assert Assert.IsNotNull(typeFormationDTOs); Assert.AreEqual(4, typeFormationDTOs.Count()); // Nombre total de type de formation dans la classe DataSeeder le 2020-10-31 } #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.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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, EstCertifie = 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.EstCertifie, formationAjoute.EstCertifie); } [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 async Task AddFormationAsync_AjouteUneFormationValide_FormationAjouteeAvecSucces(int? idMode, int? idStatut, int? idType, long? idOrigine, long? idAgence, string intitule, string organisme, DateTime? dateDebut, DateTime? dateFin) { // Arrange ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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, EstCertifie = false }; FormationService formationService = new FormationService(epContext); // Act FormationDTO formationAjoute = await formationService.AddFormationAsync(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.EstCertifie, formationAjoute.EstCertifie); } [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() { // Arrange FormationDTO formation = null; FormationService formationService = new FormationService(epContext); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); // Assert 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.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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, EstCertifie = 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")] [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")] public void AddFormationAsync_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.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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, EstCertifie = false }; FormationService formationService = new FormationService(epContext); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); // Assert 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, EstCertifie = 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")] [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 AddFormationAsync_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, EstCertifie = false }; FormationService formationService = new FormationService(epContext); // Act AsyncTestDelegate throwException = () => formationService.AddFormationAsync(formation); // Assert Assert.ThrowsAsync(typeof(FormationInvalidException), throwException); } #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.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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.EstCertifie = 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.EstCertifie, formationModifie.EstCertifie); } [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) { // Arrange ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); FormationService formationService = new FormationService(epContext); FormationDTO formation = await formationService.GetFormationByIdAsync(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.EstCertifie = false; // Act FormationDTO formationModifie = await formationService.UpdateFormationAsync(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.EstCertifie, formationModifie.EstCertifie); } [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 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.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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.EstCertifie = 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) { // Arrange ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); FormationService formationService = new FormationService(epContext); FormationDTO formation = await formationService.GetFormationByIdAsync(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.EstCertifie = false; // Act AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(idFormation, formation); // Assert Assert.ThrowsAsync(typeof(FormationInvalidException), throwException); } [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.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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.EstCertifie = 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(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) { // Arrange ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); FormationService formationService = new FormationService(epContext); FormationDTO formation = await formationService.GetFormationByIdAsync(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.EstCertifie = false; // Act AsyncTestDelegate throwException = () => formationService.UpdateFormationAsync(1, formation); // Assert Assert.ThrowsAsync(typeof(FormationIncompatibleIdException), throwException); } [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.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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, EstCertifie = 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) { // Arrange ModeFormationDTO modeExterne = epContext.ModeFormation.Where(mode => mode.Id == idMode) .Select(mode => new ModeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); StatutFormationDTO statutPlanifie = epContext.StatutFormation.Where(mode => mode.Id == idStatut) .Select(mode => new StatutFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); TypeFormationDTO typeELearning = epContext.TypeFormation.Where(mode => mode.Id == idType) .Select(mode => new TypeFormationDTO { Id = mode.Id, Libelle = mode.Libelle }).FirstOrDefault(); OrigineFormationDTO origineFormationCollaborateur = epContext.OrigineFormation.Where(mode => mode.Id == idOrigine) .Select(mode => new OrigineFormationDTO { Id = mode.Id, 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, EstCertifie = false }; // Act FormationDTO formationModifie = await formationService.UpdateFormationAsync(idFormation, formation); // Assert Assert.IsNull(formationModifie); } #endregion #region Tests DeleteFormationById et DeleteFormationByIdAsync [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.Id == formationSupprime.Id.Value); // Assert Assert.IsFalse(existFormation); } [TestCase(1)] [TestCase(2)] public async Task DeleteFormationByIdAsync_SupprimeUneFormationAvecUnIdValide_FormationSupprimeAvecSucces(long? idFormation) { // Arrange FormationService formationService = new FormationService(epContext); bool existFormation = true; // Act FormationDTO formationSupprime = await formationService.DeleteFormationByIdAsync(idFormation); existFormation = await epContext.Formation.AnyAsync(formation => formation.Id == formationSupprime.Id.Value); // Assert Assert.IsFalse(existFormation); } [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) { // Arrange FormationService formationService = new FormationService(epContext); // Act AsyncTestDelegate throwException = () => formationService.DeleteFormationByIdAsync(idFormation); // Assert 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 } }