forked from parse-community/Parse-SDK-iOS-OSX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectEstimatedDataTests.m
100 lines (84 loc) · 3.87 KB
/
ObjectEstimatedDataTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "PFFieldOperation.h"
#import "PFObjectEstimatedData.h"
#import "PFOperationSet.h"
#import "PFTestCase.h"
@interface ObjectEstimatedDataTests : PFTestCase
@end
@implementation ObjectEstimatedDataTests
- (void)testConstructors {
PFObjectEstimatedData *data = [[PFObjectEstimatedData alloc] init];
XCTAssertNotNil(data);
XCTAssertNotNil([data allKeys]);
XCTAssertEqualObjects([data allKeys], @[]);
data = [[PFObjectEstimatedData alloc] initWithServerData:nil operationSetQueue:nil];
XCTAssertNotNil(data);
XCTAssertNotNil([data allKeys]);
XCTAssertEqualObjects([data allKeys], @[]);
data = [[PFObjectEstimatedData alloc] initWithServerData:@{ @"a" : @"b" } operationSetQueue:nil];
XCTAssertNotNil(data);
XCTAssertNotNil([data allKeys]);
XCTAssertEqualObjects([data allKeys], @[ @"a" ]);
XCTAssertEqualObjects(data[@"a"], @"b");
data = [PFObjectEstimatedData estimatedDataFromServerData:@{ @"a" : @"b" } operationSetQueue:nil];
XCTAssertNotNil(data);
XCTAssertNotNil([data allKeys]);
XCTAssertEqualObjects([data allKeys], @[ @"a" ]);
XCTAssertEqualObjects(data[@"a"], @"b");
PFOperationSet *operationSet = [[PFOperationSet alloc] init];
operationSet[@"c"] = [PFSetOperation setWithValue:@"d"];
data = [PFObjectEstimatedData estimatedDataFromServerData:@{ @"a" : @"b" }
operationSetQueue:@[ operationSet ]];
XCTAssertNotNil(data);
XCTAssertNotNil([data allKeys]);
XCTAssertEqualObjects([data allKeys], (@[ @"a", @"c" ]));
XCTAssertEqualObjects(data[@"a"], @"b");
XCTAssertEqualObjects(data[@"c"], @"d");
}
- (void)testObjectForKey {
PFObjectEstimatedData *data = [PFObjectEstimatedData estimatedDataFromServerData:@{ @"a" : @"b" }
operationSetQueue:nil];
XCTAssertEqualObjects([data objectForKey:@"a"], @"b");
XCTAssertEqualObjects(data[@"a"], @"b");
}
- (void)testEnumeration {
PFOperationSet *operationSet = [[PFOperationSet alloc] init];
operationSet[@"c"] = [PFSetOperation setWithValue:@"d"];
PFObjectEstimatedData *data = [PFObjectEstimatedData estimatedDataFromServerData:@{ @"a" : @"b" }
operationSetQueue:@[ operationSet ]];
__block NSUInteger counter = 0;
[data enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
if (counter == 0) {
XCTAssertEqualObjects(key, @"a");
XCTAssertEqualObjects(obj, @"b");
} else if (counter == 1) {
XCTAssertEqualObjects(key, @"c");
XCTAssertEqualObjects(obj, @"d");
} else {
XCTFail();
}
counter++;
}];
}
- (void)testAllKeys {
PFObjectEstimatedData *data = [PFObjectEstimatedData estimatedDataFromServerData:@{ @"a" : @"b" }
operationSetQueue:nil];
XCTAssertEqualObjects([data allKeys], @[ @"a" ]);
}
- (void)testDictionaryRepresentation {
PFOperationSet *operationSet = [[PFOperationSet alloc] init];
operationSet[@"c"] = [PFSetOperation setWithValue:@"d"];
PFObjectEstimatedData *data = [PFObjectEstimatedData estimatedDataFromServerData:@{ @"a" : @"b" }
operationSetQueue:@[ operationSet ]];
NSDictionary *dictionary = data.dictionaryRepresentation;
XCTAssertEqualObjects(dictionary, (@{ @"a" : @"b", @"c" : @"d" }));
XCTAssertNotEqual(dictionary, data.dictionaryRepresentation);
}
@end