A useful testing portfolio
Choose tests by the failure they can reveal.
The idea
Unit tests isolate booking rules. Integration tests verify SQL, migrations, and dependency wiring. HTTP tests verify routes, authorization, and response contracts. A fake repository cannot prove PostgreSQL constraints work, and a large browser suite is a slow place to discover a small rule error.
Follow the flow
Make it concrete
This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.
[Theory]
[InlineData(0)]
[InlineData(-1)]
public void RejectsInvalidSeatCount(int seats)
{
Assert.Throws<ArgumentOutOfRangeException>(
() => Booking.Create("tenant-a", seats));
}Decisions that matter
- Use deterministic inputs and explicit time providers where time affects behavior.
- Test externally visible behavior rather than private implementation details.
- A small set of real boundary tests protects the assumptions fakes cannot model.
Your turn
Create a test plan for a tenant-scoped booking lookup with a PostgreSQL adapter.
Reveal a worked answer
Unit-test rule and error mapping. Integration-test the tenant predicate and missing row with PostgreSQL. HTTP-test anonymous access, a caller from another tenant, a valid caller, malformed IDs, and the successful response contract.