Skip to content

Instantly share code, notes, and snippets.

@antonio081014
Created February 23, 2022 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonio081014/0e80b3e5412db4ce8087468b401009d7 to your computer and use it in GitHub Desktop.
Save antonio081014/0e80b3e5412db4ce8087468b401009d7 to your computer and use it in GitHub Desktop.
func test_imageEntity_properties() throws {
// Assert non nil value, and unwrap it.
let entity = try XCTUnwrap(
CoreDataStore.model?.entitiesByName["Name of Entity"]
)
entity.verify(attribute: "id", hasType: .UUIDAttributeType, isOptional: false)
entity.verify(attribute: "description", hasType: .stringAttributeType, isOptional: true)
entity.verify(attribute: "url", hasType: .URIAttributeType, isOptional: false)
}
extension NSEntityDescription {
func verify(attribute name: String, hasType type: NSAttributeType, isOptional: Bool, file: StaticString = #filePath, line: UInt = #line) {
guard let attribute = attributesByName[name] else {
XCTFail("Missing expected attribute \(name)", file: file, line: line)
return
}
guard let property = propertiesByName[name] else {
XCTFail("Missing expected property \(name)", file: file, line: line)
return
}
XCTAssertEqual(attribute.attributeType, type, "attributeType", file: file, line: line)
XCTAssertEqual(property.isOptional, isOptional, "isOptional", file: file, line: line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment