11using exercise . wwwapi . DTOs . Posts ;
2- using Microsoft . AspNetCore . Http ;
32using Microsoft . AspNetCore . Mvc . Testing ;
4- using System ;
5- using System . Collections . Generic ;
6- using System . Linq ;
73using System . Net ;
84using System . Text ;
95using System . Text . Json ;
106using System . Text . Json . Nodes ;
11- using System . Threading . Tasks ;
127
138namespace exercise . tests . IntegrationTests
149{
10+ /// <summary>
11+ /// Integration tests covering the lifecycle of posts via the public API endpoints.
12+ /// </summary>
1513 [ TestFixture ]
1614 public class PostTests
1715 {
@@ -33,6 +31,9 @@ public void TearDown()
3331 _factory . Dispose ( ) ;
3432 }
3533
34+ /// <summary>
35+ /// Ensures GET /posts returns a successful response and the expected payload structure.
36+ /// </summary>
3637 [ Test ]
3738 public async Task GetAllPosts ( )
3839 {
@@ -82,6 +83,9 @@ public async Task GetAllPosts()
8283 }
8384 }
8485
86+ /// <summary>
87+ /// Confirms creating a post with valid data yields an HTTP 201 Created status.
88+ /// </summary>
8589 [ Test ]
8690 public async Task SuccessfulCreatePostStatus ( )
8791 {
@@ -111,6 +115,9 @@ public async Task SuccessfulCreatePostStatus()
111115 Assert . That ( response . StatusCode , Is . EqualTo ( HttpStatusCode . Created ) ) ;
112116 }
113117
118+ /// <summary>
119+ /// Validates the create post response body mirrors the request payload and contracts.
120+ /// </summary>
114121 [ Test ]
115122 public async Task SuccessfulCreatePostMessage ( )
116123 {
@@ -161,6 +168,12 @@ public async Task SuccessfulCreatePostMessage()
161168 Assert . That ( data [ "createdAt" ] , Is . Not . Null ) ;
162169 }
163170
171+ /// <summary>
172+ /// Checks that invalid create post requests surface the correct HTTP status codes.
173+ /// </summary>
174+ /// <param name="userid">The author identifier to include in the payload.</param>
175+ /// <param name="content">The post body content being validated.</param>
176+ /// <param name="expected">The status code the API should return.</param>
164177 [ TestCase ( 9999999 , "somecontent" , HttpStatusCode . NotFound ) ]
165178 [ TestCase ( 5 , "" , HttpStatusCode . BadRequest ) ]
166179 [ TestCase ( 5 , " " , HttpStatusCode . BadRequest ) ]
@@ -191,6 +204,12 @@ public async Task FailedlCreatePostStatus(int userid, string content, HttpStatus
191204 Assert . That ( response . StatusCode , Is . EqualTo ( expected ) ) ;
192205 }
193206
207+ /// <summary>
208+ /// Ensures the validation error message matches expectations for rejected create post attempts.
209+ /// </summary>
210+ /// <param name="userid">The author identifier placed in the request.</param>
211+ /// <param name="content">The invalid content variation under test.</param>
212+ /// <param name="expectedmessage">The message the API should return.</param>
194213 [ TestCase ( 9999999 , "somecontent" , "Invalid userID" ) ]
195214 [ TestCase ( 5 , "" , "Content cannot be empty" ) ]
196215 [ TestCase ( 5 , " " , "Content cannot be empty" ) ]
@@ -224,6 +243,9 @@ public async Task FailedCreatePostMessage(int userid, string content, string exp
224243 Assert . That ( message [ "data" ] , Is . Null ) ;
225244 Assert . That ( message [ "timestamp" ] , Is . Not . Null ) ;
226245 }
246+ /// <summary>
247+ /// Validates that deleting an existing post succeeds and a second deletion reports not found.
248+ /// </summary>
227249 [ Test ]
228250 public async Task DeletePostById_SuccessAndNotFound ( )
229251 {
@@ -262,6 +284,12 @@ public async Task DeletePostById_SuccessAndNotFound()
262284
263285
264286
287+ /// <summary>
288+ /// Exercises the PATCH /posts/{id} endpoint across happy path and error scenarios.
289+ /// </summary>
290+ /// <param name="postId">The identifier of the post to update.</param>
291+ /// <param name="newContent">The updated content supplied.</param>
292+ /// <param name="expected">The anticipated HTTP status code.</param>
265293 [ TestCase ( 5 , "Updated content" , HttpStatusCode . OK ) ]
266294 [ TestCase ( 9999999 , "Updated content" , HttpStatusCode . NotFound ) ]
267295 [ TestCase ( 5 , "" , HttpStatusCode . BadRequest ) ]
0 commit comments