Created
January 29, 2014 02:20
-
-
Save westonplatter/8680667 to your computer and use it in GitHub Desktop.
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
| - (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