diff --git a/Sources/BowlingApi/Controllers/PartieController.cs b/Sources/BowlingApi/Controllers/PartieController.cs
index cd67275..f8fbe59 100644
--- a/Sources/BowlingApi/Controllers/PartieController.cs
+++ b/Sources/BowlingApi/Controllers/PartieController.cs
@@ -29,9 +29,20 @@ namespace BowlingApi.Controllers
-
+ ///
+ /// Get all partie
+ /// GET: api/parti
+ ///
+ /// la liste des parti
+ /// Retourne la liste des joueurs
+ /// Si la liste est vide
+ /// Si une erreur est survenue
// GET: api/Partie
[HttpGet]
+ [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
+ [ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
+ [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
+ [ProducesResponseType(typeof(JoueurDTO), StatusCodes.Status200OK)]
public async Task Get()
{
try
@@ -78,9 +89,18 @@ namespace BowlingApi.Controllers
}
}
-
- // POST: api/Partie
+ ///
+ /// Creeation
+ /// POST: api/parti
+ ///
+ ///
+ /// Retourne la parti créé
+ /// Si la parti est null
+ /// Si une erreur est survenue
[HttpPost]
+ [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
+ [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
+ [ProducesResponseType(typeof(JoueurDTO), StatusCodes.Status201Created)]
public async Task> Post([FromBody] PartieDTO parti)
{
@@ -103,9 +123,23 @@ namespace BowlingApi.Controllers
}
- // PUT: api/Partie/5
+ ///
+ /// Modification partie
+ /// PUT: api/parti/5
+ ///
+ ///
+ ///
+ /// Retourne la modification
+ /// Si le partie est null
+ /// Si le partie n'existe pas
+ /// Si une erreur est survenue
[HttpPut("{id}")]
- public async Task> Put(string name, [FromBody] PartieDTO partie)
+ [ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
+ [ProducesResponseType(typeof(string), StatusCodes.Status404NotFound)]
+ [ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
+ [ProducesResponseType(typeof(PartieDTO), StatusCodes.Status200OK)]
+
+ public async Task> Put(long id, [FromBody] PartieDTO partie)
{
try
{
diff --git a/Sources/GraphQL Project/GraphQL Project.csproj b/Sources/GraphQL Project/GraphQL Project.csproj
index acdda21..eaa97d7 100644
--- a/Sources/GraphQL Project/GraphQL Project.csproj
+++ b/Sources/GraphQL Project/GraphQL Project.csproj
@@ -7,6 +7,7 @@
GraphQL_Project
+
diff --git a/Sources/GraphQL Project/Properties/launchSettings.json b/Sources/GraphQL Project/Properties/launchSettings.json
index fedf6f9..8730302 100644
--- a/Sources/GraphQL Project/Properties/launchSettings.json
+++ b/Sources/GraphQL Project/Properties/launchSettings.json
@@ -18,8 +18,6 @@
},
"GraphQL": {
"commandName": "Project",
- "dotnetRunMessages": true,
- "launchBrowser": false,
"applicationUrl": "https://localhost:5002",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
diff --git a/Sources/Tests/BowlingAPITest/TestPartiControlleur.cs b/Sources/Tests/BowlingAPITest/TestPartiControlleur.cs
new file mode 100644
index 0000000..ff24615
--- /dev/null
+++ b/Sources/Tests/BowlingAPITest/TestPartiControlleur.cs
@@ -0,0 +1,192 @@
+using DTOs;
+using FluentAssertions;
+
+namespace BowlingAPITest
+{
+ public class TestPartiControlleur
+ {
+ [Fact]
+ public async void Get_ShouldReturnOkResult()
+ {
+ // Arrange
+ var partie1 = new PartieDTO { Score = 1 };
+ var partie2 = new PartieDTO { Score = 2 };
+ var parti = GetTestItems();
+ var mockService = new Mock();
+ mockService.Setup(service => service.GetAll()).ReturnsAsync(parti);
+ var controller = new PartieController(mockService.Object);
+
+ // Act
+ 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(parti);
+
+ }
+ [Fact]
+ public async void Get_ShouldReturnAllItems()
+ {
+ // Arrange
+ var testItems = GetTestItems();
+ var mockService = new Mock();
+ mockService.Setup(service => service.GetAll()).ReturnsAsync(testItems);
+ var controller = new PartieController(mockService.Object);
+
+ // Act
+ var result = await controller.Get();
+
+ // Assert
+ var okResult = result as OkObjectResult;
+ var items = Assert.IsType>(okResult.Value);
+ Assert.Equal(2, items.Count);
+ }
+
+ private IEnumerable GetTestItems()
+ {
+
+ var testItems = new List();
+ testItems.Add(new PartieDTO { Score = 1 });
+ testItems.Add(new PartieDTO { Score = 2 });
+ return testItems;
+ }
+ //[Fact]
+ //public async Task Get_With_Invalid_id_Should_Return_BadRequest()
+ //{
+ // // Arrange
+ // var PartieController = new PartieController(null);
+
+ // // Act
+ // var result = await PartieController.Get(0);
+
+ // // Assert
+ // result.Should().BeOfType();
+ // var badRequestResult = result as BadRequestObjectResult;
+ // badRequestResult.Value.Should().Be("Le id de la partie est obligatoire");
+ //}
+
+ [Fact]
+ public async Task Get_With_Valid_id_Should_Return_Ok_With_partie()
+ {
+ // Arrange
+ var parti = new PartieDTO { Id = 1, Score = 1 };
+ var partiservicemock = new Mock();
+ partiservicemock.Setup(x => x.GetDataWithId(1)).ReturnsAsync(parti);
+ var particontrolleur = new PartieController(partiservicemock.Object);
+
+ // Act
+ var result = await particontrolleur.Get(1);
+
+ // Assert
+ result.Should().BeOfType();
+ var okResult = result as OkObjectResult;
+ okResult.Value.Should().BeEquivalentTo(parti);
+ }
+
+ //post
+
+
+
+ [Fact]
+ public async Task Put_With_Valid_parti_Should_Return_Ok_With_parti()
+ {
+ // Arrange
+ var parti = new PartieDTO { Id = 1, Score = 1 };
+ var partiServiceMock = new Mock();
+ partiServiceMock.Setup(x => x.Update(parti)).ReturnsAsync(true);
+ var partiControlleur = new PartieController(partiServiceMock.Object);
+
+ // Act
+ var result = await partiControlleur.Put(parti.Id, parti);
+
+ // Assert
+ result.Should().BeOfType>();
+ var actionResult = result as ActionResult;
+ actionResult.Result.Should().BeOfType();
+ }
+
+ //test Get_ShouldReturnNotFound
+ [Fact]
+ public async Task Get_ShouldReturnNotFound()
+ {
+ // Arrange
+ var mockService = new Mock();
+ mockService.Setup(service => service.GetAll()).ReturnsAsync((List)null);
+ var controller = new PartieController(mockService.Object);
+
+ // Act
+ var result = await controller.Get();
+
+ // Assert
+ result.Should().BeOfType();
+ }
+
+ //[Fact]
+ //public async Task Get_White_id_ShouldReturnNotFound()
+ //{
+ // // Arrange
+
+ // var partie1 = new PartieDTO { Score = 1 };
+ // var mockService = new Mock();
+ // mockService.Setup(service => service.GetDataWithId(2)).ReturnsAsync(partie1);
+ // var controller = new PartieController(mockService.Object);
+
+ // // Act
+ // var result = await controller.Get(2);
+
+ // // Assert
+ // result.Should().BeOfType();
+ //}
+ [Fact]
+ public async Task Get_ShouldReturnInternalServerError()
+ {
+ // Arrange
+ var mockService = new Mock();
+ mockService.Setup(service => service.GetAll()).ThrowsAsync(new Exception());
+ var controller = new PartieController(mockService.Object);
+
+ // Act
+ var result = await controller.Get() as ObjectResult;
+
+ // Assert
+ result.Should().BeOfType();
+ result.StatusCode.Should().Be(500);
+ }
+ //TEST POST
+ //[Fact]
+ //public async Task Post_With_Invalid_parti_Should_Return_BadRequest()
+ //{
+ // // Arrange
+ // var PartieController = new PartieController(null);
+
+ // // Act
+ // var result = await PartieController.Post(null);
+
+ // // Assert
+ // result.Should().BeOfType>();
+ // var actionResult = result as ActionResult;
+ // actionResult.Result.Should().BeOfType();
+ // var badRequestResult = actionResult.Result as BadRequestObjectResult;
+ // badRequestResult.Value.Should().Be("La partie est obligatoire");
+ //}
+
+
+ [Fact]
+ void test()
+ {
+ Assert.Equal(1, 1);
+
+ }
+
+
+
+
+
+
+ }
+
+
+}