From ab5483cd0478f77b7654e77dc0621edc613b4c42 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Tue, 25 Aug 2015 09:40:53 +0800 Subject: [PATCH 1/3] Add test cases for sanitizeForSerialization method in objc client. --- .../Tests/SWGApiClientTest.m | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m b/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m index d19180dc00..547aff2fe1 100644 --- a/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m +++ b/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m @@ -1,7 +1,12 @@ #import #import +#import #import #import +#import +#import +#import +#import @interface SWGApiClientTest : XCTestCase @@ -98,4 +103,74 @@ XCTAssertEqualObjects(basicAuthCredentials, [config getBasicAuthToken]); } +- (void)testSanitizeForDeserialization { + id result; + id data; + + // nil + data = nil; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, data); + + // NSString + data = @"test string"; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, data); + + // NSNumber + data = @1; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, data); + + // SWGQueryParamCollection + data = [[SWGQueryParamCollection alloc] init]; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, data); + + // NSDate + data = [NSDate dateWithISO8601String:@"1997-07-16T19:20:30.45+01:0"]; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, [data ISO8601String]); + + // model + data = [self createPet]; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, [data toDictionary]); + + // NSArray + data = @[@1]; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, data); + + // NSDictionary + data = @{@"test key": @"test value"}; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, data); +} + +- (SWGPet*) createPet { + SWGPet * pet = [[SWGPet alloc] init]; + pet._id = [[NSNumber alloc] initWithLong:[[NSDate date] timeIntervalSince1970]]; + pet.name = @"monkey"; + + SWGCategory * category = [[SWGCategory alloc] init]; + category._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)]; + category.name = @"super-happy"; + pet.category = category; + + SWGTag *tag1 = [[SWGTag alloc] init]; + tag1._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)]; + tag1.name = @"test tag 1"; + SWGTag *tag2 = [[SWGTag alloc] init]; + tag2._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)]; + tag2.name = @"test tag 2"; + pet.tags = (NSArray *)[[NSArray alloc] initWithObjects:tag1, tag2, nil]; + + pet.status = @"available"; + + NSArray * photos = [[NSArray alloc] initWithObjects:@"http://foo.bar.com/3", @"http://foo.bar.com/4", nil]; + pet.photoUrls = photos; + return pet; +} + @end From eb21963fa5bdb0afb1f3281776fc74e0e9fe20d0 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Tue, 25 Aug 2015 10:51:03 +0800 Subject: [PATCH 2/3] Update test case testSanitizeForSerialization in objc client. --- .../Tests/SWGApiClientTest.m | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m b/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m index 547aff2fe1..3e13f618c2 100644 --- a/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m +++ b/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m @@ -103,7 +103,7 @@ XCTAssertEqualObjects(basicAuthCredentials, [config getBasicAuthToken]); } -- (void)testSanitizeForDeserialization { +- (void)testSanitizeForSerialization { id result; id data; @@ -128,14 +128,24 @@ XCTAssertEqualObjects(result, data); // NSDate - data = [NSDate dateWithISO8601String:@"1997-07-16T19:20:30.45+01:0"]; + data = [NSDate dateWithISO8601String:@"1997-07-16T19:20:30.45+01:00"]; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, [data ISO8601String]); + + data = [NSDate dateWithISO8601String:@"1997-07-16"]; result = [self.apiClient sanitizeForSerialization:data]; XCTAssertEqualObjects(result, [data ISO8601String]); // model - data = [self createPet]; + NSDictionary *petDict = @{@"id": @1, @"name": @"monkey", + @"category": @{@"id": @1, @"name": @"test category"}, + @"tags": @[@{@"id": @1, @"name": @"test tag1"}, + @{@"id": @2, @"name": @"test tag2"}], + @"status": @"available", + @"photoUrls": @[@"http://foo.bar.com/3", @"http://foo.bar.com/4"]}; + data = [[SWGPet alloc] initWithDictionary:petDict error:nil]; result = [self.apiClient sanitizeForSerialization:data]; - XCTAssertEqualObjects(result, [data toDictionary]); + XCTAssertEqualObjects(result, petDict); // NSArray data = @[@1]; @@ -148,29 +158,4 @@ XCTAssertEqualObjects(result, data); } -- (SWGPet*) createPet { - SWGPet * pet = [[SWGPet alloc] init]; - pet._id = [[NSNumber alloc] initWithLong:[[NSDate date] timeIntervalSince1970]]; - pet.name = @"monkey"; - - SWGCategory * category = [[SWGCategory alloc] init]; - category._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)]; - category.name = @"super-happy"; - pet.category = category; - - SWGTag *tag1 = [[SWGTag alloc] init]; - tag1._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)]; - tag1.name = @"test tag 1"; - SWGTag *tag2 = [[SWGTag alloc] init]; - tag2._id = [[NSNumber alloc] initWithInteger:arc4random_uniform(100000)]; - tag2.name = @"test tag 2"; - pet.tags = (NSArray *)[[NSArray alloc] initWithObjects:tag1, tag2, nil]; - - pet.status = @"available"; - - NSArray * photos = [[NSArray alloc] initWithObjects:@"http://foo.bar.com/3", @"http://foo.bar.com/4", nil]; - pet.photoUrls = photos; - return pet; -} - @end From 1b2f491b0ea61ec9aca327dcbe5a4d0758569459 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Tue, 25 Aug 2015 11:16:19 +0800 Subject: [PATCH 3/3] Add tese case for sanitizing array of models in objc client. --- .../objc/SwaggerClientTests/Tests/SWGApiClientTest.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m b/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m index 3e13f618c2..e9f1a46af3 100644 --- a/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m +++ b/samples/client/petstore/objc/SwaggerClientTests/Tests/SWGApiClientTest.m @@ -152,6 +152,12 @@ result = [self.apiClient sanitizeForSerialization:data]; XCTAssertEqualObjects(result, data); + // NSArray of models + NSArray *arrayOfPetDict = @[petDict]; + data = [NSArray arrayWithObject:[[SWGPet alloc] initWithDictionary:petDict error:nil]]; + result = [self.apiClient sanitizeForSerialization:data]; + XCTAssertEqualObjects(result, arrayOfPetDict); + // NSDictionary data = @{@"test key": @"test value"}; result = [self.apiClient sanitizeForSerialization:data];