From 4f3de6b3ab9cacda5aaaf0227d7e7f413a18572b Mon Sep 17 00:00:00 2001 From: masapountz Date: Fri, 15 Mar 2024 22:44:24 +0100 Subject: [PATCH] Ajout des TU Create pour ParagraphController --- API_SQLuedo/TestAPI/ParagraphsUnitTest.cs | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/API_SQLuedo/TestAPI/ParagraphsUnitTest.cs b/API_SQLuedo/TestAPI/ParagraphsUnitTest.cs index 73e22d1..f1a121e 100644 --- a/API_SQLuedo/TestAPI/ParagraphsUnitTest.cs +++ b/API_SQLuedo/TestAPI/ParagraphsUnitTest.cs @@ -201,7 +201,44 @@ namespace TestAPI } + [Fact] + public void CreateParagraphSuccess() + { + paragraphService.Setup(x => x.CreateParagraph("Le nouveau titre","Le nouveau content","Les infos","La requête requêtante","Commentaires",2)) + .Returns(new ParagraphDTO("Le nouveau titre", "Le nouveau content", "Les infos", "La requête requêtante", "Commentaires", 2)); + var ParagraphsController = new ParagraphsController(paragraphService.Object, new NullLogger()); + + var paragraphsResult = ParagraphsController.CreateParagraph(new ParagraphDTO("Le nouveau titre", "Le nouveau content", "Les infos", "La requête requêtante", "Commentaires", 2)); + if (paragraphsResult is CreatedResult createdObjectResult) + { + ParagraphDTO valeur = createdObjectResult.Value as ParagraphDTO; + + Assert.NotNull(valeur); + Assert.Equal("Le nouveau titre", valeur.Title); + Assert.Equal("Le nouveau content", valeur.Content); + Assert.Equal("Les infos", valeur.Info); + Assert.Equal("La requête requêtante", valeur.Query); + Assert.Equal("Commentaires", valeur.Comment); + Assert.Equal(2, valeur.LessonId); + } + + } + + [Fact] + public void CreateParagraphFail() + { + paragraphService.Setup(x => x.CreateParagraph("Le nouveau titre", "Le nouveau content", "Les infos", "La requête requêtante", "Commentaires", 2)) + .Returns(new ParagraphDTO("Le nouveau titre", "Le nouveau content", "Les infos", "La requête requêtante", "Commentaires", 2)); + var ParagraphsController = new ParagraphsController(paragraphService.Object, new NullLogger()); + var paragraphsResult = ParagraphsController.CreateParagraph(new ParagraphDTO(null, "Le nouveau content", "Les infos", "La requête requêtante", "Commentaires", 2)); + + if (paragraphsResult is BadRequestResult BDObjectResult) + { + + Assert.Equal(400, BDObjectResult.StatusCode); + } + }