@@ -31,6 +31,31 @@ final class CRUDRepositoryTests: CoreDataXCTestCase {
3131 try verify ( transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
3232 }
3333
34+ func testCreateFailure( ) async throws {
35+ let historyTimeStamp = Date ( )
36+ let transactionAuthor : String = #function
37+ let movie = Movie ( id: UUID ( ) , title: " Create Success " , releaseDate: Date ( ) , boxOffice: 100 )
38+ var existingMovie = try await repositoryContext ( ) . perform ( schedule: . immediate) {
39+ let object = try ManagedMovie ( context: self . repositoryContext ( ) )
40+ try movie. updating ( managed: object)
41+ try self . repositoryContext ( ) . save ( )
42+ return try Movie ( managed: object)
43+ }
44+ var tempResultMovie = existingMovie
45+ XCTAssertNotNil ( tempResultMovie. url)
46+ tempResultMovie. url = nil
47+ XCTAssertNoDifference ( tempResultMovie, movie)
48+
49+ try await verify ( existingMovie)
50+
51+ let result : Result < Movie , CoreDataError > = try await repository ( )
52+ . create ( movie, transactionAuthor: transactionAuthor)
53+ guard case . failure = result else {
54+ XCTFail ( " Expecting a failed result " )
55+ return
56+ }
57+ }
58+
3459 func testReadSuccess( ) async throws {
3560 let movie = Movie ( id: UUID ( ) , title: " Read Success " , releaseDate: Date ( ) , boxOffice: 100 )
3661 let createdMovie : Movie = try await repositoryContext ( ) . perform ( schedule: . immediate) {
0 commit comments