Problem
The existing unit tests call controller methods directly through Moq mocks and cannot detect routing failures, middleware issues, or HTTP-level serialization problems. There is no test coverage for the actual ASP.NET Core request pipeline.
Proposed Solution
Add an HTTP-layer integration test class using WebApplicationFactory<Program> that exercises the real middleware pipeline, route resolution, status codes, and RFC 7807 Problem Details response bodies — without requiring a running server.
Suggested Approach
- Add
Microsoft.AspNetCore.Mvc.Testing to the test project.
- Expose
Program to the test project by adding public partial class Program {} at the bottom of Program.cs.
- Create
test/.../Integration/PlayerWebApplicationTests.cs using WebApplicationFactory<Program> with an in-memory SQLite database substituted for the real one (via ConfigureTestServices).
- Add
Utilities/TestAuthHandler.cs to bypass [Authorize] on GET /players/{id:Guid}.
- Use
[Trait("Category", "Integration")] on all tests in this class.
- Follow the controller naming convention:
{HttpMethod}_{Resource}_{Condition}_Returns{Outcome}.
Endpoints to cover
GET /players
- Returns
200 OK with all seeded players
GET /players/{id:Guid}
- Returns
200 OK with a valid player body when the ID exists
- Returns
404 Not Found (RFC 7807) when not found
GET /players/squadNumber/{squadNumber:int}
- Returns
200 OK with a valid player body when the squad number exists
- Returns
404 Not Found (RFC 7807) when not found
POST /players
- Returns
201 Created with valid payload
- Returns
400 Bad Request (RFC 7807) when validation fails
- Note: the
409 Conflict branch in the controller is unreachable via the HTTP pipeline. The BeUniqueSquadNumber rule in the "Create" validation rule set catches duplicate squad numbers first and returns 400. The 409 path is covered by the unit test Post_Players_Existing_Returns409Conflict, where validation is mocked to pass.
PUT /players/squadNumber/{squadNumber:int}
- Returns
204 No Content on successful update
- Returns
404 Not Found (RFC 7807) when player does not exist
- Returns
400 Bad Request (RFC 7807) when validation fails
- Returns
400 Bad Request (RFC 7807) when squad number in route does not match body
DELETE /players/squadNumber/{squadNumber:int}
- Returns
204 No Content on successful deletion
- Returns
404 Not Found (RFC 7807) when player does not exist
GET /health
Acceptance Criteria
References
Problem
The existing unit tests call controller methods directly through Moq mocks and cannot detect routing failures, middleware issues, or HTTP-level serialization problems. There is no test coverage for the actual ASP.NET Core request pipeline.
Proposed Solution
Add an HTTP-layer integration test class using
WebApplicationFactory<Program>that exercises the real middleware pipeline, route resolution, status codes, and RFC 7807 Problem Details response bodies — without requiring a running server.Suggested Approach
Microsoft.AspNetCore.Mvc.Testingto the test project.Programto the test project by addingpublic partial class Program {}at the bottom ofProgram.cs.test/.../Integration/PlayerWebApplicationTests.csusingWebApplicationFactory<Program>with an in-memory SQLite database substituted for the real one (viaConfigureTestServices).Utilities/TestAuthHandler.csto bypass[Authorize]onGET /players/{id:Guid}.[Trait("Category", "Integration")]on all tests in this class.{HttpMethod}_{Resource}_{Condition}_Returns{Outcome}.Endpoints to cover
GET
/players200 OKwith all seeded playersGET
/players/{id:Guid}200 OKwith a valid player body when the ID exists404 Not Found(RFC 7807) when not foundGET
/players/squadNumber/{squadNumber:int}200 OKwith a valid player body when the squad number exists404 Not Found(RFC 7807) when not foundPOST
/players201 Createdwith valid payload400 Bad Request(RFC 7807) when validation fails409 Conflictbranch in the controller is unreachable via the HTTP pipeline. TheBeUniqueSquadNumberrule in the"Create"validation rule set catches duplicate squad numbers first and returns400. The409path is covered by the unit testPost_Players_Existing_Returns409Conflict, where validation is mocked to pass.PUT
/players/squadNumber/{squadNumber:int}204 No Contenton successful update404 Not Found(RFC 7807) when player does not exist400 Bad Request(RFC 7807) when validation fails400 Bad Request(RFC 7807) when squad number in route does not match bodyDELETE
/players/squadNumber/{squadNumber:int}204 No Contenton successful deletion404 Not Found(RFC 7807) when player does not existGET
/health200 OKAcceptance Criteria
Microsoft.AspNetCore.Mvc.Testingadded to the test projectpublic partial class Program {}added toProgram.csUtilities/TestAuthHandler.csadded to bypass[Authorize]in teststest/.../Integration/PlayerWebApplicationTests.csexiststype,title,status)[Trait("Category", "Integration")]applied to all tests in the classCHANGELOG.mdupdatedReferences
Repository<T>andPlayerRepository#461 (establishes theIntegration/subfolder and pattern)Testcontainersfor Integration Testing with Database Containers #353 (Testcontainers — promotes these tests to real containers)