-
-
Save vanvoorden/31aa5fe38b1c333a36ec9b37998f122f to your computer and use it in GitHub Desktop.
2024-07-30-4.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class ContextTests : XCTestCase { | |
func testDelete() throws { | |
let schema = Schema([Item.self]) | |
let configuration = ModelConfiguration(isStoredInMemoryOnly: true) | |
let container = try ModelContainer( | |
for: schema, | |
configurations: configuration | |
) | |
let modelContext = ModelContext(container) | |
modelContext.insert(Item()) | |
XCTAssert(try modelContext.fetchCount(FetchDescriptor<Item>()) == 1) | |
try modelContext.delete(model: Item.self) | |
XCTAssert(try modelContext.fetchCount(FetchDescriptor<Item>()) == 0) | |
} | |
func testDeleteWithIteration() throws { | |
let schema = Schema([Item.self]) | |
let configuration = ModelConfiguration(isStoredInMemoryOnly: true) | |
let container = try ModelContainer( | |
for: schema, | |
configurations: configuration | |
) | |
let modelContext = ModelContext(container) | |
modelContext.insert(Item()) | |
XCTAssert(try modelContext.fetchCount(FetchDescriptor<Item>()) == 1) | |
try modelContext.delete(model: Item.self) | |
for model in try modelContext.fetch(FetchDescriptor<Item>()) { | |
modelContext.delete(model) | |
} | |
XCTAssert(try modelContext.fetchCount(FetchDescriptor<Item>()) == 0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment