mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-01-12 17:32:18 +08:00
Writing more assertions to verify import is occurring properly
This commit is contained in:
@@ -19,7 +19,9 @@ extern NSString * const kMagicalRecordImportRelationshipTypeKey;
|
||||
@interface NSManagedObject (NSManagedObject_DataImport)
|
||||
|
||||
- (void) MR_setValuesForKeysWithJSONDictionary:(NSDictionary *)jsonData;
|
||||
|
||||
+ (id) MR_importFromDictionary:(NSDictionary *)data;
|
||||
+ (id) MR_importFromDictionary:(NSDictionary *)data inContext:(NSManagedObjectContext *)context;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -215,9 +215,17 @@ NSString * const kMagicalRecordImportRelationshipTypeKey = @"type";
|
||||
return [self MR_importFromDictionary:data inContext:[NSManagedObjectContext defaultContext]];
|
||||
}
|
||||
|
||||
+ (id) MR_updateFromDictionary:(NSDictionary *)data inContext:(NSManagedObjectContext *)context
|
||||
{
|
||||
//find object
|
||||
//create if not exists
|
||||
//apply dictionary updates
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (id) MR_updateFromDictionary:(NSDictionary *)data
|
||||
{
|
||||
return [self MR_importFromDictionary:data inContext:[NSManagedObjectContext defaultContext]];
|
||||
return [self MR_updateFromDictionary:data inContext:[NSManagedObjectContext defaultContext]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
NSManagedObjectContext *context = [NSManagedObjectContext defaultContext];
|
||||
|
||||
MappedEntity *testMappedEntity = [MappedEntity createInContext:context];
|
||||
testMappedEntity.mappedEntityIDValue = 42;
|
||||
testMappedEntity.testMappedEntityIDValue = 42;
|
||||
testMappedEntity.sampleAttribute = @"This attribute created as part of the test case setup";
|
||||
|
||||
[context save];
|
||||
}
|
||||
|
||||
- (void) setUpClass
|
||||
- (void) setUp
|
||||
{
|
||||
[NSManagedObjectModel setDefaultManagedObjectModel:[NSManagedObjectModel managedObjectModelNamed:@"TestModel.momd"]];
|
||||
[MagicalRecordHelpers setupCoreDataStackWithInMemoryStore];
|
||||
@@ -41,7 +41,7 @@
|
||||
self.testEntity = [SingleEntityRelatedToMappedEntityUsingDefaults MR_importFromDictionary:singleEntity];
|
||||
}
|
||||
|
||||
- (void) tearDownClass
|
||||
- (void) tearDown
|
||||
{
|
||||
[MagicalRecordHelpers cleanUp];
|
||||
}
|
||||
@@ -50,7 +50,10 @@
|
||||
{
|
||||
id testRelatedEntity = testEntity.mappedEntity;
|
||||
|
||||
assertThat([MappedEntity numberOfEntities], is(equalToInteger(1)));
|
||||
|
||||
assertThat(testRelatedEntity, is(notNilValue()));
|
||||
assertThat([testRelatedEntity sampleAttribute], containsString(@"sample json file"));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
[context save];
|
||||
}
|
||||
|
||||
- (void) setUpClass
|
||||
- (void) setUp
|
||||
{
|
||||
[NSManagedObjectModel setDefaultManagedObjectModel:[NSManagedObjectModel managedObjectModelNamed:@"TestModel.momd"]];
|
||||
[MagicalRecordHelpers setupCoreDataStackWithInMemoryStore];
|
||||
@@ -42,7 +42,7 @@
|
||||
self.testEntity = [SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey MR_importFromDictionary:singleEntity];
|
||||
}
|
||||
|
||||
- (void) tearDownClass
|
||||
- (void) tearDown
|
||||
{
|
||||
[MagicalRecordHelpers cleanUp];
|
||||
}
|
||||
@@ -56,6 +56,7 @@
|
||||
NSRelationshipDescription *testRelationship = [[mappedEntity propertiesByName] valueForKey:@"mappedEntity"];
|
||||
assertThat([[testRelationship userInfo] valueForKey:kMagicalRecordImportRelationshipMapKey], is(equalTo(@"someRandomAttributeName")));
|
||||
|
||||
assertThat([MappedEntity numberOfEntities], is(equalToInteger(1)));
|
||||
assertThat(testRelatedEntity, is(notNilValue()));
|
||||
assertThat([testRelatedEntity sampleAttribute], is(containsString(@"sample json file")));
|
||||
}
|
||||
@@ -69,7 +70,7 @@
|
||||
NSRelationshipDescription *testRelationship = [[mappedEntity propertiesByName] valueForKey:@"mappedEntity"];
|
||||
assertThat([[testRelationship userInfo] valueForKey:kMagicalRecordImportRelationshipPrimaryKey], is(equalTo(@"testMappedEntityID")));
|
||||
|
||||
|
||||
assertThat([MappedEntity numberOfEntities], is(equalToInteger(1)));
|
||||
assertThat([testRelatedEntity testMappedEntityID], is(equalToInteger(42)));
|
||||
assertThat([testRelatedEntity sampleAttribute], containsString(@"sample json file"));
|
||||
}
|
||||
|
||||
@@ -83,20 +83,19 @@
|
||||
assertThat(testEntity.mappedStringAttribute, is(equalTo(@"Mapped value")));
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#if TARGET_OS_IPHONE && __IPHONE_5_0 >= 50000
|
||||
|
||||
- (void) testImportUIColorAttributeToEntity
|
||||
{
|
||||
// UIColor *actualColor = testEntity.colorTestAttribute;
|
||||
//
|
||||
// CGFloat red, blue, green, alpha;
|
||||
// [actualColor getRed:&red green:&green blue:&blue alpha:&alpha];
|
||||
//
|
||||
//
|
||||
// assertThatFloat(alpha, is(equalToFloat(1.)));
|
||||
// assertThatFloat(red, is(equalToFloat(64./255.)));
|
||||
// assertThatFloat(green, is(equalToFloat(128./255.)));
|
||||
// assertThatFloat(blue, is(equalToFloat(225./255.)));
|
||||
UIColor *actualColor = testEntity.colorTestAttribute;
|
||||
|
||||
CGFloat red, blue, green, alpha;
|
||||
[actualColor getRed:&red green:&green blue:&blue alpha:&alpha];
|
||||
|
||||
assertThatFloat(alpha, is(equalToFloat(1.)));
|
||||
assertThatFloat(red, is(equalToFloat(64./255.)));
|
||||
assertThatFloat(green, is(equalToFloat(128./255.)));
|
||||
assertThatFloat(blue, is(equalToFloat(225./255.)));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -37,11 +37,6 @@
|
||||
[NSManagedObjectModel setDefaultManagedObjectModel:[NSManagedObjectModel managedObjectModelNamed:@"TestModel.momd"]];
|
||||
[MagicalRecordHelpers setupCoreDataStackWithInMemoryStore];
|
||||
|
||||
// NSURL *storeUrl = [NSPersistentStore MR_urlForStoreName:@"ImportSingleEntityTestStore.sqlite"];
|
||||
// [[NSFileManager defaultManager] removeItemAtURL:storeUrl error:nil];
|
||||
//
|
||||
// [MagicalRecordHelpers setupCoreDataStackWithStoreNamed:@"ImportSingleEntityTestStore.sqlite"];
|
||||
|
||||
[self setupTestData];
|
||||
|
||||
id singleEntity = [self dataFromJSONFixture];
|
||||
@@ -62,6 +57,7 @@
|
||||
|
||||
assertThat(testRelatedEntity, is(notNilValue()));
|
||||
assertThat([testRelatedEntity sampleBaseAttribute], containsString(@"BASE"));
|
||||
assertThatBool([testRelatedEntity respondsToSelector:@selector(sampleConcreteAttribute)], is(equalToBool(NO)));
|
||||
}
|
||||
|
||||
- (void) testImportAnEntityRelatedToAbstractEntityViaToManyRelationship
|
||||
@@ -73,6 +69,7 @@
|
||||
|
||||
assertThat(testRelatedEntity, is(notNilValue()));
|
||||
assertThat([testRelatedEntity sampleBaseAttribute], containsString(@"BASE"));
|
||||
assertThatBool([testRelatedEntity respondsToSelector:@selector(sampleConcreteAttribute)], is(equalToBool(NO)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user