Exercise 2: A Real, No-Networking Test Inserting a Task Directly — Possible Solution =========================================================================================== import Testing import SwiftData @Test func insertingATaskMakesItFetchable() throws { let config = ModelConfiguration(isStoredInMemoryOnly: true) let container = try ModelContainer(for: Task.self, configurations: config) let context = ModelContext(container) let newTask = Task(title: "Read a chapter", priority: 2) context.insert(newTask) let fetchedTasks = try context.fetch(FetchDescriptor()) #expect(fetchedTasks.count == 1) #expect(fetchedTasks.first?.title == "Read a chapter") } HOW IT WORKS: This test follows the capstone's own established real in-memory testing pattern exactly - a fresh ModelConfiguration(isStoredInMemoryOnly: true) and a real ModelContainer built from it, giving the test a genuine, working SwiftData stack that exists only for the duration of this one test and never touches real disk storage at all. Unlike the capstone's own syncingInsertsTasksFromTheFakeClient() test, this version skips TaskListViewModel and networking entirely - it calls context.insert(newTask) directly, inserting one real Task value straight into the in-memory context, with no APIClientProtocol, FakeAPIClient, or async sync step involved anywhere. This correctly isolates the test to checking SwiftData's own real persistence behavior specifically (does an inserted Task become fetchable afterward), completely independent of the separate networking layer the capstone's own other test already covers. context.fetch(FetchDescriptor()) then performs a real, genuine fetch against the in-memory store, and the two #expect calls confirm both that exactly one task exists and that it carries the exact real title that was inserted - correctly verifying SwiftData's own basic insert-then-fetch round trip in isolation. ANSWER: A @Test function building a fresh in-memory ModelContainer, inserting one Task directly via context.insert(newTask) with no networking involved, and confirming context.fetch(FetchDescriptor()) returns exactly that one task correctly isolates and verifies SwiftData's own real persistence behavior on its own, separately from the capstone's own network-sync test. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly uses the real in-memory ModelConfiguration pattern to test SwiftData's own insert-then-fetch behavior in isolation, without pulling in the separate networking/DI machinery the chapter's own other test exercises.