From bcdd8faa838490908eadb2ca0e409ba41c0e518b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yana=C3=ABl=20GRETTE?= Date: Thu, 24 Dec 2020 10:07:05 +0100 Subject: [PATCH] Ajout des tests unitaires sur le GetNotById de NoteService --- EPAServeur.Tests/Services/NoteServiceTests.cs | 57 +++++++++++++++++++ EPAServeur/Context/DataSeeder.cs | 14 ++--- 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/EPAServeur.Tests/Services/NoteServiceTests.cs b/EPAServeur.Tests/Services/NoteServiceTests.cs index 762f0a1..9aa7ea3 100644 --- a/EPAServeur.Tests/Services/NoteServiceTests.cs +++ b/EPAServeur.Tests/Services/NoteServiceTests.cs @@ -309,6 +309,63 @@ namespace EPAServeur.Tests.Services #endregion #region Tests GetNoteById + [TestCase(1)] + [TestCase(2)] + [TestCase(4)] + [TestCase(5)] + [TestCase(6)] + [TestCase(9)] + public async Task GetNote_NoteNotNull(long id) + { + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + DetailsNoteDTO detailsNoteDTO = await noteService.GetNoteByIdAsync(id); + + Assert.NotNull(detailsNoteDTO); + Assert.NotNull(detailsNoteDTO.Titre); + Assert.NotNull(detailsNoteDTO.Texte); + Assert.NotNull(detailsNoteDTO.IdAuteur); + Assert.NotNull(detailsNoteDTO.Collaborateur); + Assert.NotNull(detailsNoteDTO.DateCreation); + Assert.NotNull(detailsNoteDTO.DateMiseAjour); + Assert.AreEqual(id, detailsNoteDTO.Id); + + } + + + [TestCase(-999)] + [TestCase(-1)] + [TestCase(0)] + [TestCase(11)] + [TestCase(20)] + [TestCase(30)] + [TestCase(100)] + public void GetNote_NoteNotFoundException(long id) + { + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); + Assert.ThrowsAsync(typeof(NoteNotFoundException), exception); + } + + [TestCase(3)] + [TestCase(7)] + public void GetNote_ReferentNotFoundException(long id) + { + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); + Assert.ThrowsAsync(typeof(ReferentNotFoundException), exception); + } + + [TestCase(8)] + [TestCase(10)] + public void GetNote_CollaborateurNotFoundException(long id) + { + INoteService noteService = new NoteService(collaborateurApi, collaborateurService, context); + AsyncTestDelegate exception = () => noteService.GetNoteByIdAsync(id); + Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception); + } + + + #endregion diff --git a/EPAServeur/Context/DataSeeder.cs b/EPAServeur/Context/DataSeeder.cs index e91a242..cda13b0 100644 --- a/EPAServeur/Context/DataSeeder.cs +++ b/EPAServeur/Context/DataSeeder.cs @@ -829,7 +829,7 @@ namespace EPAServeur.Context Titre = "Titre1", Texte = "Texte1", IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"), - IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"), + IdCollaborateur = new Guid("fc1d7593-83c3-44de-b3f5-53dbe53c0830"), DateCreation = DateTime.Now, DateMiseAJour = DateTime.Now @@ -842,7 +842,7 @@ namespace EPAServeur.Context Titre = "Titre2", Texte = "Texte2", IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"), - IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"), + IdCollaborateur = new Guid("fc1d7593-83c3-44de-b3f5-53dbe53c0830"), DateCreation = DateTime.Now, DateMiseAJour = DateTime.Now @@ -854,8 +854,8 @@ namespace EPAServeur.Context IdNote = 3, Titre = "Titre3", Texte = "Texte3", - IdAuteur = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"), - IdCollaborateur = new Guid("779bf1cf-4d38-48fb-8550-3d583384523b"), + IdAuteur = new Guid("073a4fb0-45c3-11eb-b378-0242ac130002"), + IdCollaborateur = new Guid("fc1d7593-83c3-44de-b3f5-53dbe53c0830"), DateCreation = DateTime.Now, DateMiseAJour = DateTime.Now @@ -906,7 +906,7 @@ namespace EPAServeur.Context IdNote = 7, Titre = "Titre7", Texte = "Texte7", - IdAuteur = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"), + IdAuteur = new Guid("073a4fb0-45c3-11eb-b378-0242ac130002"), IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"), DateCreation = DateTime.Now, DateMiseAJour = DateTime.Now @@ -920,7 +920,7 @@ namespace EPAServeur.Context Titre = "Titre8", Texte = "Texte8", IdAuteur = new Guid("571463f3-b286-4a21-9eab-0707dc506dec"), - IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"), + IdCollaborateur = new Guid("227e0e1a-45c3-11eb-b378-0242ac130002"), DateCreation = DateTime.Now, DateMiseAJour = DateTime.Now @@ -946,7 +946,7 @@ namespace EPAServeur.Context Titre = "Titre10", Texte = "Texte10", IdAuteur = new Guid("6aa62dcb-f7c9-4c0c-af40-e934a4d6a7eb"), - IdCollaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"), + IdCollaborateur = new Guid("694ffef2-45c3-11eb-b378-0242ac130002"), DateCreation = DateTime.Now, DateMiseAJour = DateTime.Now