From 5c90fd599a2fcba8846d0b24df343e7bcf501017 Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 21:28:23 +0200 Subject: [PATCH] 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); }