Skip to content

Instantly share code, notes, and snippets.

@westonplatter
Created January 29, 2014 02:20
Show Gist options
  • Select an option

  • Save westonplatter/8680667 to your computer and use it in GitHub Desktop.

Select an option

Save westonplatter/8680667 to your computer and use it in GitHub Desktop.
- (void)testExample
{
NSString *jsonString = @"{\"user\":{\" .... ";
NSError *error = nil;
NSDictionary *jsonDictionary = [NSJSONSerialization
JSONObjectWithData: [jsonString dataUsingEncoding:NSUTF8StringEncoding]
options: NSJSONReadingMutableContainers
error: &error
];
Director *director = [[Director alloc] initWithMOC:self.moc];
BOOL result = [director loadJSON:jsonDictionary];
XCTAssertTrue(result, @"loadJSON should return true");
// 1 User should be created
NSFetchRequest *fetchRequest1 = [[NSFetchRequest alloc] init];
NSEntityDescription *userEntity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:self.moc];
[fetchRequest1 setEntity:userEntity];
NSArray *fetchedUsers = [self.moc executeFetchRequest:fetchRequest1 error:&error];
XCTAssertTrue([fetchedUsers count] == 1, @"director should create user");
XCTAssertFalse(error, @"fetch should generate no errors");
// 2 Todos should be created
NSObject *user = [fetchedUsers firstObject];
NSArray *userTodos = [user valueForKey:@"todos"];
XCTAssertTrue([userTodos count] == 2, @"director should create 2 tods for user");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment