Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint โ€” The Self-Verifying Suite

โญโญ intermediateโณ 25 min read๐Ÿ“ Lesson 137 of 265

Compose it: a fake double, a service behind an interface, and a test suite that actually catches broken implementations.

The gate (mini-build)

Three pieces, one file:

  1. IInventory โ€” int GetStock(string sku), void Reserve(string sku, int qty).
  2. FakeInventory : IInventory โ€” the fake: Dictionary<string,int> Stock (missing sku = 0), List<string> Reservations, plus two fault hooks: LyingStock (when true, GetStock returns the real value + 1000) and BrokenReserve (when true, Reserve records nothing).
  3. OrderService(IInventory) โ€” PlaceOrder(sku, qty) โ†’ "ok" | "outofstock"; reserves only on success.
  4. CheckAll(FakeInventory inv) โ€” a small suite (โ‰ฅ 3 tests) that verifies: the ok path reserves, the out-of-stock path does not reserve, and qty exactly equal to stock still succeeds. Returns the list of failure messages โ€” empty means every test passed. The suite must genuinely test the injected inventory: handed a lying or broken fake, it must report failures, not happy-face an empty list.