Skip to content

Lay out the test tiers: unit, database and API - #38

Merged
elgorro merged 1 commit into
mainfrom
chore/test-layout
Aug 12, 2026
Merged

Lay out the test tiers: unit, database and API#38
elgorro merged 1 commit into
mainfrom
chore/test-layout

Conversation

@elgorro

@elgorro elgorro commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Puts the three test tiers from #37 in place, with a working example in each. No feature coverage
yet — that is #34 and the tiers it now has somewhere to live in.

Layout

Project Tier
tests/Ssabba.TestSupport PostgresFixture — a Testcontainers postgres:18-alpine, migrated once per collection, plus ResetAsync and the Category=Integration trait constants
tests/Ssabba.Infrastructure.Tests SsabbaDbContext and the migrations against the real provider
tests/Ssabba.Web.Tests the real host through WebApplicationFactory<Program> against the same container

Each test assembly declares its own PostgresDatabase collection: xUnit requires the collection
definition to live in the assembly that uses it.

No mocking library is added. The only substitute in the suite is TestAuthHandler, a hand-written
stand-in for the Keycloak handshake; requests opt into a signed-in identity with
factory.CreateClientAs("ada").

Running it

dotnet test Ssabba.slnx                                    # everything (needs Docker)
dotnet test Ssabba.slnx --filter "Category!=Integration"   # no container runtime required

CI runs the two tiers as separate steps so a failure names the tier.

A defect the API tier found

UseStatusCodePagesWithReExecute re-executes with the original request method, so an unauthorized
POST /api/matches was re-run against the Blazor /not-found page and came back as 400 "The
request has an incorrect Content-type."
instead of 401 — any API client would have seen the wrong
status. The re-execution is now scoped to non-/api paths. Written up in #39; #40 covers the structural follow-up.

Program.cs also gained public partial class Program; so the factory can name the host.

Verification

  • dotnet build Ssabba.slnx -c Release — clean, warnings-as-errors
  • dotnet test Ssabba.slnx -c Release — 22 domain, 2 infrastructure, 3 API, all green
  • dotnet format Ssabba.slnx --verify-no-changes — clean

Part of #37.

🤖 Generated with Claude Code

https://claude.ai/code/session_01F9TP5WEbVsmAWQS4uAds3Q

The suite was one domain project against the whole codebase, with nowhere to put a test
that needs a database or the host. Three tiers now, as agreed in #37:

- `Ssabba.TestSupport` holds `PostgresFixture`, a Testcontainers Postgres migrated once per
  collection, plus the `Category=Integration` trait so `dotnet test --filter
  "Category!=Integration"` still works without a container runtime.
- `Ssabba.Infrastructure.Tests` proves the migrations apply cleanly and leave no pending
  model changes.
- `Ssabba.Web.Tests` boots the real host through `WebApplicationFactory<Program>` against
  the same container, with `TestAuthHandler` standing in for the Keycloak handshake — the
  only substitute in the suite. No mocking library.

Booting the host turned up a real defect: `UseStatusCodePagesWithReExecute` re-executes with
the original method, so an unauthorized API POST came back as the Blazor page's 400 instead
of 401. The UI keeps the re-execution; `/api` no longer does.

CI runs the two tiers as separate steps so a failure names the tier.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9TP5WEbVsmAWQS4uAds3Q
@elgorro elgorro added area: web Blazor host and API endpoints (Ssabba.Web) area: data EF Core, DbContext and migrations (Ssabba.Infrastructure) area: ci GitHub Actions workflows type: chore Maintenance, refactors, tooling labels Aug 12, 2026
@elgorro
elgorro merged commit 33cb5c2 into main Aug 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci GitHub Actions workflows area: data EF Core, DbContext and migrations (Ssabba.Infrastructure) area: web Blazor host and API endpoints (Ssabba.Web) type: chore Maintenance, refactors, tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant