You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: cover the API end to end with Testcontainers integration tests
Boot the real Program.cs through WebApplicationFactory against a SQL Server
started by Testcontainers, so requests exercise the actual middleware pipeline,
DI graph, EF Core SQL Server provider and migrations instead of substitutes.
Respawn truncates the schema between tests while a single container is shared
by the whole suite.
The 48 tests cover JWT issuing and validation (wrong signing key, expired and
tampered tokens), [Authorize] and role policies, per-user data isolation on
transactions, the HTTP error contract, and the database constraints the
InMemory provider cannot enforce: the unique index on category slugs, the
transaction foreign keys, ON DELETE CASCADE and decimal(18,2) round-tripping.
Running them exposed four defects that the service-level unit tests could not
see, fixed here:
- [ApiController] rejects invalid models before the action runs, so every
`if (!ModelState.IsValid)` block was dead code and validation failures came
back as RFC 7807 ProblemDetails while every other error used the
ResultViewModel envelope. Shape them centrally through
InvalidModelStateResponseFactory and drop the unreachable branches.
- Registering a duplicate email returned 500: the controller caught only
DbUpdateException while the service throws InvalidOperationException.
- Updating a category to a slug owned by another category returned 500 when the
unique index rejected it; validate the slug and answer 400.
- Creating or updating a transaction with an unknown CategoryId returned 500 on
the foreign key; check the category up front and answer 400.
Also make Program public so the test host can reference it, and drop the unused
MSTest.TestFramework reference from the API project.
0 commit comments