Skip to content

Commit 59ca8bd

Browse files
committed
Merge pull request #821 from geekerzp/develop_2.0_objc_test
[Objc] Update test case
2 parents e1393d1 + 58feda7 commit 59ca8bd

File tree

1 file changed

+29
-1
lines changed
  • samples/client/petstore/objc/PetstoreClient/PetstoreClientTests

1 file changed

+29
-1
lines changed

samples/client/petstore/objc/PetstoreClient/PetstoreClientTests/PetApiTest.m

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ - (void)testCreateAndGetPet {
3737
}
3838
if(output){
3939
XCTAssertNotNil([output _id], @"token was nil");
40+
41+
// test category of pet is correct
42+
XCTAssertEqualObjects(output.category._id, pet.category._id);
43+
XCTAssertEqualObjects(output.category.name, pet.category.name);
44+
45+
// test tags of pet is correct
46+
XCTAssertTrue([output.tags isKindOfClass:[NSArray class]]);
47+
[pet.tags enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
48+
SWGTag *foundTag = [[SWGTag alloc] init];
49+
for (SWGTag *tag in output.tags) {
50+
if ([tag _id] == [obj _id]) {
51+
foundTag = tag;
52+
}
53+
}
54+
XCTAssertNotNil(foundTag);
55+
XCTAssertEqualObjects([foundTag _id], [obj _id]);
56+
XCTAssertEqualObjects([foundTag name], [obj name]);
57+
}];
4058
}
4159
[expectation fulfill];
4260
}];
@@ -231,10 +249,20 @@ - (SWGPet*) createPet {
231249
SWGPet * pet = [[SWGPet alloc] init];
232250
pet._id = [[NSNumber alloc] initWithLong:[[NSDate date] timeIntervalSince1970]];
233251
pet.name = @"monkey";
252+
234253
SWGCategory * category = [[SWGCategory alloc] init];
254+
category._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)];
235255
category.name = @"super-happy";
236-
237256
pet.category = category;
257+
258+
SWGTag *tag1 = [[SWGTag alloc] init];
259+
tag1._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)];
260+
tag1.name = @"test tag 1";
261+
SWGTag *tag2 = [[SWGTag alloc] init];
262+
tag2._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)];
263+
tag2.name = @"test tag 2";
264+
pet.tags = (NSArray<SWGTag> *)[[NSArray alloc] initWithObjects:tag1, tag2, nil];
265+
238266
pet.status = @"available";
239267

240268
NSArray * photos = [[NSArray alloc] initWithObjects:@"http://foo.bar.com/3", @"http://foo.bar.com/4", nil];

0 commit comments

Comments
 (0)