Skip to content

Instantly share code, notes, and snippets.

@koromiko
Created September 7, 2017 02:15
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 koromiko/baac0ef6a3c7a011de2c543f0c1adc4b to your computer and use it in GitHub Desktop.
Save koromiko/baac0ef6a3c7a011de2c543f0c1adc4b to your computer and use it in GitHub Desktop.
func test_create_todo() {
//Given the name & status
let name = "Todo1"
let finished = false
//When add todo
let todo = sut.insertTodoItem(name: name, finished: finished)
//Assert: return todo item
XCTAssertNotNil( todo )
}
func test_fetch_all_todo() {
//Given a storage with two todo
//When fetch
let results = sut.fetchAll()
//Assert return five todo items
XCTAssertEqual(results.count, 5)
}
func test_remove_todo() {
//Given a item in persistent store
let items = sut.fetchAll()
let item = items[0]
let numberOfItems = items.count
//When remove a item
sut.remove(objectID: item.objectID)
sut.save()
//Assert number of item - 1
XCTAssertEqual(numberOfItemsInPersistentStore(), numberOfItems-1)
}
//Convenient method for getting the number of data in store now
func numberOfItemsInPersistentStore() -> Int {
let request: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "ToDoItem")
let results = try! mockPersistantContainer.viewContext.fetch(request)
return results.count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment