From 1d5d73721c00ba28b67c05de1d9ff5159b976df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20P=C3=A9rez=20Ngounou?= Date: Wed, 1 Feb 2023 11:38:45 +0100 Subject: [PATCH] Downgrate --- Sources/BowlingApi/BowlingApi.csproj | 10 ++-- .../BowlingAPITest/BowlingAPITest.csproj | 18 +++---- .../BowlingAPITest/TestJoueurController.cs | 54 +++++++++---------- Sources/Tests/BowlingAPITest/Usings.cs | 2 +- 4 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Sources/BowlingApi/BowlingApi.csproj b/Sources/BowlingApi/BowlingApi.csproj index 3ae707a..2b76c0b 100644 --- a/Sources/BowlingApi/BowlingApi.csproj +++ b/Sources/BowlingApi/BowlingApi.csproj @@ -1,7 +1,7 @@ - net7.0 + net6.0 enable enable 11 @@ -12,13 +12,13 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/Sources/Tests/BowlingAPITest/BowlingAPITest.csproj b/Sources/Tests/BowlingAPITest/BowlingAPITest.csproj index 0a87957..75fce4f 100644 --- a/Sources/Tests/BowlingAPITest/BowlingAPITest.csproj +++ b/Sources/Tests/BowlingAPITest/BowlingAPITest.csproj @@ -1,7 +1,7 @@ - net7.0 + net6.0 enable enable @@ -11,9 +11,9 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -25,14 +25,14 @@ - - + + - - ..\..\..\..\..\.nuget\packages\fluentassertions\6.9.0\lib\net6.0\FluentAssertions.dll - + + ..\..\..\..\..\.nuget\packages\fluentassertions\6.9.0\lib\net6.0\FluentAssertions.dll + diff --git a/Sources/Tests/BowlingAPITest/TestJoueurController.cs b/Sources/Tests/BowlingAPITest/TestJoueurController.cs index abb09a3..d0583de 100644 --- a/Sources/Tests/BowlingAPITest/TestJoueurController.cs +++ b/Sources/Tests/BowlingAPITest/TestJoueurController.cs @@ -3,10 +3,10 @@ using FluentAssertions; namespace BowlingAPITest; -public class TestController +public class TestController { [Fact] - public async void Get_ShouldReturnOkResult() + public async void Get_ShouldReturnOkResult() { // Arrange var joueur1 = new JoueurDTO { Pseudo = "John Doe" }; @@ -15,31 +15,30 @@ public class TestController var mockService = new Mock(); mockService.Setup(service => service.GetAll()).ReturnsAsync(joueurs); var controller = new JoueurController(mockService.Object); - + // Act - var result= await controller.Get() as OkObjectResult; + var result = await controller.Get() as OkObjectResult; var value = result.Value as List; - + // Assert result.Should().NotBeNull(); value.Should().NotBeNull(); result.StatusCode.Should().Be(200); value.Should().BeEquivalentTo(joueurs); - } - + [Fact] - public async void Get_ShouldReturnAllItems() + public async void Get_ShouldReturnAllItems() { // Arrange var testItems = GetTestItems(); var mockService = new Mock(); mockService.Setup(service => service.GetAll()).ReturnsAsync(testItems); var controller = new JoueurController(mockService.Object); - + // Act var result = await controller.Get(); - + // Assert var okResult = result as OkObjectResult; var items = Assert.IsType>(okResult.Value); @@ -48,13 +47,12 @@ public class TestController private IEnumerable GetTestItems() { - var testItems = new List(); testItems.Add(new JoueurDTO { Pseudo = "Item1" }); testItems.Add(new JoueurDTO { Pseudo = "Item2" }); return testItems; } - + [Fact] public async Task Get_With_Invalid_Name_Should_Return_BadRequest() { @@ -69,7 +67,7 @@ public class TestController var badRequestResult = result as BadRequestObjectResult; badRequestResult.Value.Should().Be("Le nom du joueur est obligatoire"); } - + [Fact] public async Task Get_With_Valid_Name_Should_Return_Ok_With_Joueur() { @@ -87,7 +85,7 @@ public class TestController var okResult = result as OkObjectResult; okResult.Value.Should().BeEquivalentTo(joueur); } - + [Fact] public async Task Post_With_Invalid_Joueur_Should_Return_BadRequest() { @@ -104,7 +102,7 @@ public class TestController var badRequestResult = actionResult.Result as BadRequestObjectResult; badRequestResult.Value.Should().Be("Le joueur est obligatoire"); } - + [Fact] public async Task Post_With_Valid_Joueur_Should_Return_Created_With_Joueur() { @@ -124,7 +122,7 @@ public class TestController var createdResult = actionResult.Result as CreatedAtActionResult; createdResult.Value.Should().BeEquivalentTo(joueur); } - + [Fact] public async Task Put_With_Invalid_Joueur_Should_Return_BadRequest() { @@ -141,7 +139,7 @@ public class TestController var badRequestResult = actionResult.Result as BadRequestObjectResult; badRequestResult.Value.Should().Be("Le joueur est obligatoire"); } - + [Fact] public async Task Put_With_Valid_Joueur_Should_Return_Ok_With_Joueur() { @@ -159,7 +157,7 @@ public class TestController var actionResult = result as ActionResult; actionResult.Result.Should().BeOfType(); } - + //test Get_ShouldReturnNotFound [Fact] public async Task Get_ShouldReturnNotFound() @@ -168,31 +166,31 @@ public class TestController var mockService = new Mock(); mockService.Setup(service => service.GetAll()).ReturnsAsync((List)null); var controller = new JoueurController(mockService.Object); - + // Act var result = await controller.Get(); - + // Assert result.Should().BeOfType(); } - + [Fact] public async Task Get_White_Name_ShouldReturnNotFound() { // Arrange - + var joueur2 = new JoueurDTO { Pseudo = "Jane Smith" }; var mockService = new Mock(); mockService.Setup(service => service.GetDataWithName("Jane Smith")).ReturnsAsync(joueur2); var controller = new JoueurController(mockService.Object); - + // Act var result = await controller.Get("John Doe"); - + // Assert result.Should().BeOfType(); } - + //test Get_ShouldReturn InternalServerError [Fact] public async Task Get_ShouldReturnInternalServerError() @@ -201,14 +199,12 @@ public class TestController var mockService = new Mock(); mockService.Setup(service => service.GetAll()).ThrowsAsync(new Exception()); var controller = new JoueurController(mockService.Object); - + // Act var result = await controller.Get() as ObjectResult; - + // Assert result.Should().BeOfType(); result.StatusCode.Should().Be(500); } - - } \ No newline at end of file diff --git a/Sources/Tests/BowlingAPITest/Usings.cs b/Sources/Tests/BowlingAPITest/Usings.cs index 49abb01..ecc90e8 100644 --- a/Sources/Tests/BowlingAPITest/Usings.cs +++ b/Sources/Tests/BowlingAPITest/Usings.cs @@ -3,4 +3,4 @@ global using BowlingApi.Controllers; global using BowlingEF.Entities; global using BowlingService.Interfaces; global using Microsoft.AspNetCore.Mvc; -global using Moq; +global using Moq; \ No newline at end of file