ActiveResourceKit  v1.2 (498.0)
 All Classes Files Functions Variables Typedefs Enumerator Properties Macros Pages
KeyValueCodingTests.m
Go to the documentation of this file.
1 // ActiveResourceKitTests KeyValueCodingTests.m
2 //
3 // Copyright © 2012, Roy Ratcliffe, Pioneering Software, United Kingdom
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the “Software”), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED “AS IS,” WITHOUT WARRANTY OF ANY KIND, EITHER
16 // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO
18 // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
19 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22 //
23 //------------------------------------------------------------------------------
24 
25 #import "KeyValueCodingTests.h"
26 
28 
29 @implementation KeyValueCodingTests
30 
31 @synthesize resource;
32 
33 - (void)setUp
34 {
35  ARService *service = [[ARService alloc] initWithSite:[NSURL URLWithString:@"http://localhost"] elementName:@"resource"];
36  [self setResource:[[ARResource alloc] initWithService:service]];
37  [[self resource] setValue:[NSNumber numberWithInt:0] forKey:@"zero"];
38 }
39 
40 - (void)tearDown
41 {
42  [self setResource:nil];
43 }
44 
46 {
47  STAssertEqualObjects([NSNumber numberWithInt:0], [[self resource] valueForKey:@"zero"], nil);
48 }
49 
51 {
52  [[self resource] setValue:@"" forKey:@"key"];
53  STAssertEqualObjects(@"", [[self resource] valueForKey:@"key"], nil);
54 
55  [[self resource] setNilValueForKey:@"key"];
56  STAssertEqualObjects([NSNull null], [[self resource] valueForKey:@"key"], nil);
57 }
58 
60 {
61  [[self resource] setValue:@"123" forKey:@"TheKey"];
62  STAssertEqualObjects(@"123", [[[self resource] attributes] objectForKey:@"the_key"], nil);
63 }
64 
66 {
67  [[self resource] setValue:@"abc" forKey:@"KeyA"];
68  [[self resource] setValue:@"def" forKey:@"KeyB"];
69  NSDictionary *valuesForKeys = [[self resource] dictionaryWithValuesForKeys:[NSArray arrayWithObjects:@"KeyA", @"KeyB", nil]];
70  NSDictionary *shouldBeValuesForKeys = [NSDictionary dictionaryWithObjectsAndKeys:@"abc", @"KeyA", @"def", @"KeyB", nil];
71  STAssertEqualObjects(shouldBeValuesForKeys, valuesForKeys, nil);
72 }
73 
75 {
76  NSDictionary *valuesForKeys = [NSDictionary dictionaryWithObjectsAndKeys:@"abc", @"KeyABC", @"xyz", @"KeyXYZ", [NSNull null], @"Null", nil];
77  [[self resource] setValuesForKeysWithDictionary:valuesForKeys];
78  NSDictionary *attributes = [[self resource] attributes];
79  STAssertEqualObjects([attributes objectForKey:@"key_abc"], @"abc", nil);
80  STAssertEqualObjects([attributes objectForKey:@"key_xyz"], @"xyz", nil);
81  STAssertEqualObjects([attributes objectForKey:@"null"], [NSNull null], nil);
82 }
83 
84 @end