From 728a55630f56b787d51b9436eb295d0373eb985d Mon Sep 17 00:00:00 2001 From: Tobias Sundstrand Date: Tue, 20 Nov 2012 07:21:40 +0100 Subject: [PATCH] Added test for nested property --- .../KeyValueObjectMappingTests.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/KeyValueObjectMappingTests/KeyValueObjectMappingTests.m b/KeyValueObjectMappingTests/KeyValueObjectMappingTests.m index 0f5d1de..6a54512 100644 --- a/KeyValueObjectMappingTests/KeyValueObjectMappingTests.m +++ b/KeyValueObjectMappingTests/KeyValueObjectMappingTests.m @@ -252,4 +252,16 @@ -(void) testCustomMap { STAssertEquals(2, (int)[user.tweets count], @"Should have two tweet"); } +- (void)testNestedProperties{ + NSDictionary *source = @{@"idStr" : @"12345" , @"tweet" : @{@"text" : @"Some text"}}; + DCParserConfiguration *configuration = [DCParserConfiguration configuration]; + + DCObjectMapping *nestedMapping = [DCObjectMapping mapKeyPath:@"tweet.text" toAttribute:@"text" onClass:[Tweet class]]; + [configuration addObjectMapping:nestedMapping]; + + DCKeyValueObjectMapping *parser = [DCKeyValueObjectMapping mapperForClass:[Tweet class] andConfiguration:configuration]; + Tweet *tweet = [parser parseDictionary:source]; + STAssertEqualObjects(tweet.idStr, @"12345", @"wrong id string"); + STAssertEqualObjects(tweet.text, @"Some text", @"wrong text string"); +} @end