Capstone implementation and tests
Capstone implementation and tests
Implement one end-to-end reservation slice and prove its invariants through positive, negative, concurrency and failure tests.
Follow the capstone solution in order: read SQL migrations; inspect Store.Reserve and DrainOne; run the independent Core and HTTP acceptance harness only after approving the SDK and dependencies. The Store owns one in-memory SQLite connection protected by a process-local lock; this intentionally serializes transactions for a small teaching fixture. The conditional UPDATE protects the nonnegative invariant and the database CHECK is a second guard. The transaction contains the decrement, reservation and outbox insert. An injected exception immediately before commit, after the stock decrement and both inserts, tests rollback of all three writes. The injection flag is used only in the core test harness, never exposed through an endpoint. The separate SQL check can demonstrate SQLite constraints but cannot establish C# provider or HTTP behavior. Duplicate reservations compare stored quantity and return replay or conflict before decrement. A pending outbox row becomes fulfilled inside a transaction with a unique fulfillment record; this is a local effect, not proof of exactly-once delivery to an external system. A finite hosted worker is optional; the acceptance harness uses explicit drain calls for deterministic results. API endpoints validate the DTO, enforce a role policy and compare the requested tenant to the authenticated tenant. The fake authentication scheme exists only in the in-process Checks project; the local browser host uses a deny-all scheme and exposes read-only public catalog. Never expose synthetic credentials or a test authentication handler on a real network. No production identity provider is implemented. The HTML catalog has a language attribute, heading and table headers; keyboard and screen-reader testing are still required. Use the fixed catalog cache only for immutable product details. Telemetry counts outcomes without tenant IDs or request keys; logs are not an audit store. The solution includes versioned SQL migration files and a dependency graph, but no real migration of durable production data. Expected results are reasoned and not executed in .NET.
Baseline: .NET 10 / C# 14. All C# results below are reasoned, not executed. The capstone examples are synthetic; the separate solution is staged and unexecuted.
Compare allowed and denied resource access
Authorization requires both role and tenant equality.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;static bool Allowed(string role,string principalTenant,string resourceTenant) => (role is "clerk" or "manager") && principalTenant==resourceTenant;Console.WriteLine(Allowed("clerk","alpha","alpha"));Console.WriteLine(Allowed("clerk","alpha","beta"));Console.WriteLine(Allowed("reader","alpha","alpha"));Expected result (not executed):
TrueFalseFalseThis pure rule makes the boundary visible; the HTTP harness also exercises authentication and authorization middleware.
Model rollback of a reservation
A temporary next state becomes visible only after a successful transaction.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;int stock=5, reservations=0, events=0;void Apply(int qty,bool fail) { if (qty<=0 || qty>stock) return; int next=stock-qty; if (fail) return; stock=next; reservations++; events++;}Apply(2,true); Console.WriteLine($"{stock}/{reservations}/{events}");Apply(2,false); Console.WriteLine($"{stock}/{reservations}/{events}");Expected result (not executed):
5/0/03/1/1This is a state-transition model, not a database transaction. The solution uses SQLite and an explicit rollback test.
Test conservation across contention outcomes
Enumerate two competing sequential orders as a model for serial transaction execution.
Inspect the archived Fixture.csproj and use only an approved .NET 10 SDK. Build and run in an isolated lab with finite time and resource limits.
using System;foreach (int[] order in new[]{new[]{4,3},new[]{3,4}}) { int stock=5, accepted=0; foreach(int q in order) if(q<=stock){stock-=q;accepted+=q;} Console.WriteLine($"{stock}+{accepted}=5");}Expected result (not executed):
1+4=52+3=5The winning request is not predetermined. The actual concurrency harness must assert conservation and one successful reservation, not thread ordering.
Apply the concept
Extend the acceptance matrix with a worker interruption just before its transaction commits. Describe the test setup, actions, assertions and cleanup.
Use the manual practice and knowledge check. Do not deploy or publish these fixtures.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Capstone implementation and tests — knowledge check
Apply the lesson concepts to the following scenarios.
What does a 403 response represent here?
Why is the outbox insert in the reservation transaction?
What should a concurrency test assert?
Where may synthetic test authentication be installed?
What does an independent SQLite check prove?