From 0fead2b2b94ef05dfffa81895b2dfb456cb9ac05 Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 21:16:39 +0200 Subject: [PATCH 1/3] Adds testEnqueueBatchOfHTTPRequestOperationsWithRequests. --- Tests/AFHTTPClientTests.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 7f4a4a9..5fb8334 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -86,6 +86,32 @@ expect([operation class]).to.equal([AFImageRequestOperation class]); } +- (void)testEnqueueBatchOfHTTPRequestOperationsWithRequests { + [Expecta setAsynchronousTestTimeout:5.0]; + + __block NSDate *firstCallbackTime = nil; + __block NSDate *batchCallbackTime = nil; + + NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil]; + AFHTTPRequestOperation *firstOperation = [self.client HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { + firstCallbackTime = [NSDate date]; + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { + firstCallbackTime = [NSDate date]; + }]; + + AFHTTPRequestOperation *secondOperation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; + + [self.client enqueueBatchOfHTTPRequestOperations:@[ firstOperation, secondOperation ] progressBlock:NULL completionBlock:^(NSArray *operations) { + batchCallbackTime = [NSDate date]; + }]; + + expect(self.client.operationQueue.operationCount).to.equal(@3); + expect(firstCallbackTime).willNot.beNil(); + expect(batchCallbackTime).willNot.beNil(); + + expect(batchCallbackTime).beGreaterThan(firstCallbackTime); +} + - (void)testThatTheDefaultStringEncodingIsUTF8 { expect(self.client.stringEncoding).to.equal(NSUTF8StringEncoding); } From 5c90fd599a2fcba8846d0b24df343e7bcf501017 Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 21:28:23 +0200 Subject: [PATCH 2/3] Adds testEnqueueBatchOfHTTPRequestOperations. --- Tests/AFHTTPClientTests.m | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 5fb8334..663cd80 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -86,7 +86,7 @@ expect([operation class]).to.equal([AFImageRequestOperation class]); } -- (void)testEnqueueBatchOfHTTPRequestOperationsWithRequests { +- (void)testEnqueueBatchOfHTTPRequestOperations { [Expecta setAsynchronousTestTimeout:5.0]; __block NSDate *firstCallbackTime = nil; @@ -112,6 +112,36 @@ expect(batchCallbackTime).beGreaterThan(firstCallbackTime); } +- (void)testEnqueueBatchOfHTTPRequestOperationsWithRequests { + [Expecta setAsynchronousTestTimeout:5.0]; + + [self.client registerHTTPOperationClass:[AFJSONRequestOperation class]]; + [self.client registerHTTPOperationClass:[AFImageRequestOperation class]]; + + __block NSArray *batchOperations = nil; + + NSMutableURLRequest *firstRequest = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil]; + [firstRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + + NSMutableURLRequest *secondeRequest = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil]; + [secondeRequest setValue:@"image/png" forHTTPHeaderField:@"Accept"]; + + [self.client enqueueBatchOfHTTPRequestOperationsWithRequests:@[ firstRequest, secondeRequest ] progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) { + + } completionBlock:^(NSArray *operations) { + batchOperations = operations; + }]; + + expect(self.client.operationQueue.operationCount).to.equal(@3); + expect(batchOperations).willNot.beNil(); + + expect(self.client.operationQueue.operationCount).to.equal(@0); + expect(batchOperations.count).to.equal(@2); + + expect([[batchOperations objectAtIndex:0] class]).to.equal([AFJSONRequestOperation class]); + expect([[batchOperations objectAtIndex:1] class]).to.equal([AFImageRequestOperation class]); +} + - (void)testThatTheDefaultStringEncodingIsUTF8 { expect(self.client.stringEncoding).to.equal(NSUTF8StringEncoding); } From 178bf2d58f4863b6f48e6082ba2b8ecfce85eb3d Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 21:33:34 +0200 Subject: [PATCH 3/3] Adds testReachabilityStatus. --- Tests/AFHTTPClientTests.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 663cd80..0ba0032 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -43,6 +43,20 @@ expect([request valueForHTTPHeaderField:@"x-some-key"]).to.equal(@"SomeValue"); } +- (void)testReachabilityStatus { + [Expecta setAsynchronousTestTimeout:5.0]; + + expect(self.client.networkReachabilityStatus).to.equal(@(AFNetworkReachabilityStatusUnknown)); + + __block AFNetworkReachabilityStatus reachabilityStatus = self.client.networkReachabilityStatus; + + [self.client setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { + reachabilityStatus = status; + }]; + + expect(reachabilityStatus).will.equal(@(AFNetworkReachabilityStatusReachableViaWiFi)); +} + - (void)testJSONRequestOperationContruction { NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];