Minor formatting
This commit is contained in:
parent
5c712c13ad
commit
b26df2e6aa
1 changed files with 64 additions and 64 deletions
|
|
@ -42,24 +42,24 @@
|
||||||
- (void)testDefaultHeaders {
|
- (void)testDefaultHeaders {
|
||||||
[self.client setDefaultHeader:@"x-some-key" value:@"SomeValue"];
|
[self.client setDefaultHeader:@"x-some-key" value:@"SomeValue"];
|
||||||
expect([self.client defaultValueForHeader:@"x-some-key"]).to.equal(@"SomeValue");
|
expect([self.client defaultValueForHeader:@"x-some-key"]).to.equal(@"SomeValue");
|
||||||
|
|
||||||
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
|
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
|
||||||
expect([request valueForHTTPHeaderField:@"x-some-key"]).to.equal(@"SomeValue");
|
expect([request valueForHTTPHeaderField:@"x-some-key"]).to.equal(@"SomeValue");
|
||||||
|
|
||||||
expect(^{ [self.client setDefaultHeader:@"x-some-key" value:nil]; }).toNot.raise(nil);
|
expect(^{ [self.client setDefaultHeader:@"x-some-key" value:nil]; }).toNot.raise(nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testReachabilityStatus {
|
- (void)testReachabilityStatus {
|
||||||
[Expecta setAsynchronousTestTimeout:5.0];
|
[Expecta setAsynchronousTestTimeout:5.0];
|
||||||
|
|
||||||
expect(self.client.networkReachabilityStatus).to.equal(@(AFNetworkReachabilityStatusUnknown));
|
expect(self.client.networkReachabilityStatus).to.equal(@(AFNetworkReachabilityStatusUnknown));
|
||||||
|
|
||||||
__block AFNetworkReachabilityStatus reachabilityStatus = self.client.networkReachabilityStatus;
|
__block AFNetworkReachabilityStatus reachabilityStatus = self.client.networkReachabilityStatus;
|
||||||
|
|
||||||
[self.client setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
[self.client setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
||||||
reachabilityStatus = status;
|
reachabilityStatus = status;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
expect(reachabilityStatus).will.equal(@(AFNetworkReachabilityStatusReachableViaWiFi));
|
expect(reachabilityStatus).will.equal(@(AFNetworkReachabilityStatusReachableViaWiFi));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,15 +69,15 @@
|
||||||
|
|
||||||
expect([AFJSONRequestOperation canProcessRequest:request]).to.beTruthy();
|
expect([AFJSONRequestOperation canProcessRequest:request]).to.beTruthy();
|
||||||
|
|
||||||
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
|
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
|
||||||
|
|
||||||
[self.client registerHTTPOperationClass:[AFJSONRequestOperation class]];
|
[self.client registerHTTPOperationClass:[AFJSONRequestOperation class]];
|
||||||
operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
expect([operation class]).to.equal([AFJSONRequestOperation class]);
|
expect([operation class]).to.equal([AFJSONRequestOperation class]);
|
||||||
|
|
||||||
[self.client unregisterHTTPOperationClass:[AFJSONRequestOperation class]];
|
[self.client unregisterHTTPOperationClass:[AFJSONRequestOperation class]];
|
||||||
operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
|
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,11 +87,11 @@
|
||||||
|
|
||||||
expect([AFXMLRequestOperation canProcessRequest:request]).to.beTruthy();
|
expect([AFXMLRequestOperation canProcessRequest:request]).to.beTruthy();
|
||||||
|
|
||||||
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
|
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
|
||||||
|
|
||||||
[self.client registerHTTPOperationClass:[AFXMLRequestOperation class]];
|
[self.client registerHTTPOperationClass:[AFXMLRequestOperation class]];
|
||||||
operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
expect([operation class]).to.equal([AFXMLRequestOperation class]);
|
expect([operation class]).to.equal([AFXMLRequestOperation class]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,38 +101,38 @@
|
||||||
|
|
||||||
expect([AFImageRequestOperation canProcessRequest:request]).to.beTruthy();
|
expect([AFImageRequestOperation canProcessRequest:request]).to.beTruthy();
|
||||||
|
|
||||||
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
|
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
|
||||||
|
|
||||||
[self.client registerHTTPOperationClass:[AFImageRequestOperation class]];
|
[self.client registerHTTPOperationClass:[AFImageRequestOperation class]];
|
||||||
operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
expect([operation class]).to.equal([AFImageRequestOperation class]);
|
expect([operation class]).to.equal([AFImageRequestOperation class]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatEnqueueBatchOfHTTPRequestOperationsFiresCompletionBlockAfterEveryRequestCompleted {
|
- (void)testThatEnqueueBatchOfHTTPRequestOperationsFiresCompletionBlockAfterEveryRequestCompleted {
|
||||||
[Expecta setAsynchronousTestTimeout:5.0];
|
[Expecta setAsynchronousTestTimeout:5.0];
|
||||||
|
|
||||||
__block NSDate *firstCallbackTime = nil;
|
__block NSDate *firstCallbackTime = nil;
|
||||||
__block NSDate *secondCallbackTime = nil;
|
__block NSDate *secondCallbackTime = nil;
|
||||||
__block NSDate *batchCallbackTime = nil;
|
__block NSDate *batchCallbackTime = nil;
|
||||||
|
|
||||||
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
|
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
|
||||||
AFHTTPRequestOperation *firstOperation = [self.client HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
AFHTTPRequestOperation *firstOperation = [self.client HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
firstCallbackTime = [NSDate date];
|
firstCallbackTime = [NSDate date];
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
firstCallbackTime = [NSDate date];
|
firstCallbackTime = [NSDate date];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
AFHTTPRequestOperation *secondOperation = [self.client HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
AFHTTPRequestOperation *secondOperation = [self.client HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
secondCallbackTime = [NSDate date];
|
secondCallbackTime = [NSDate date];
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
secondCallbackTime = [NSDate date];
|
secondCallbackTime = [NSDate date];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[self.client enqueueBatchOfHTTPRequestOperations:@[ firstOperation, secondOperation ] progressBlock:NULL completionBlock:^(NSArray *operations) {
|
[self.client enqueueBatchOfHTTPRequestOperations:@[ firstOperation, secondOperation ] progressBlock:nil completionBlock:^(NSArray *operations) {
|
||||||
batchCallbackTime = [NSDate date];
|
batchCallbackTime = [NSDate date];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
expect(self.client.operationQueue.operationCount).will.equal(0);
|
expect(self.client.operationQueue.operationCount).will.equal(0);
|
||||||
expect(firstCallbackTime).willNot.beNil();
|
expect(firstCallbackTime).willNot.beNil();
|
||||||
expect(secondCallbackTime).willNot.beNil();
|
expect(secondCallbackTime).willNot.beNil();
|
||||||
|
|
@ -143,31 +143,31 @@
|
||||||
|
|
||||||
- (void)testAuthorizationHeaderWithInvalidUsernamePassword {
|
- (void)testAuthorizationHeaderWithInvalidUsernamePassword {
|
||||||
[Expecta setAsynchronousTestTimeout:5.0];
|
[Expecta setAsynchronousTestTimeout:5.0];
|
||||||
|
|
||||||
__block NSHTTPURLResponse *response = nil;
|
__block NSHTTPURLResponse *response = nil;
|
||||||
[self.client getPath:@"/basic-auth/username/password" parameters:nil success:NULL failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
[self.client getPath:@"/basic-auth/username/password" parameters:nil success:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
response = operation.response;
|
response = operation.response;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
expect(response.statusCode).will.equal(401);
|
expect(response.statusCode).will.equal(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testAuthorizationHeaderWithValidUsernamePassword {
|
- (void)testAuthorizationHeaderWithValidUsernamePassword {
|
||||||
[Expecta setAsynchronousTestTimeout:5.0];
|
[Expecta setAsynchronousTestTimeout:5.0];
|
||||||
|
|
||||||
__block NSHTTPURLResponse *response = nil;
|
__block NSHTTPURLResponse *response = nil;
|
||||||
[self.client setAuthorizationHeaderWithUsername:@"username" password:@"password"];
|
[self.client setAuthorizationHeaderWithUsername:@"username" password:@"password"];
|
||||||
[self.client getPath:@"/basic-auth/username/password" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
[self.client getPath:@"/basic-auth/username/password" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
response = operation.response;
|
response = operation.response;
|
||||||
} failure:NULL];
|
} failure:nil];
|
||||||
|
|
||||||
expect(response.statusCode).will.equal(200);
|
expect(response.statusCode).will.equal(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatClientClearsAuthorizationHeader {
|
- (void)testThatClientClearsAuthorizationHeader {
|
||||||
[self.client setAuthorizationHeaderWithUsername:@"username" password:@"password"];
|
[self.client setAuthorizationHeaderWithUsername:@"username" password:@"password"];
|
||||||
[self.client clearAuthorizationHeader];
|
[self.client clearAuthorizationHeader];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
|
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
|
||||||
expect([request valueForHTTPHeaderField:@"Authorization"]).to.beNil();
|
expect([request valueForHTTPHeaderField:@"Authorization"]).to.beNil();
|
||||||
}
|
}
|
||||||
|
|
@ -199,16 +199,16 @@
|
||||||
- (void)testThatCancelAllHTTPOperationsWithMethodPathCancelsOnlyMatchingOperations {
|
- (void)testThatCancelAllHTTPOperationsWithMethodPathCancelsOnlyMatchingOperations {
|
||||||
[self.client registerHTTPOperationClass:[AFJSONRequestOperation class]];
|
[self.client registerHTTPOperationClass:[AFJSONRequestOperation class]];
|
||||||
[self.client registerHTTPOperationClass:[AFImageRequestOperation class]];
|
[self.client registerHTTPOperationClass:[AFImageRequestOperation class]];
|
||||||
|
|
||||||
NSMutableURLRequest *firstRequest = [self.client requestWithMethod:@"GET" path:@"/ip" parameters:nil];
|
NSMutableURLRequest *firstRequest = [self.client requestWithMethod:@"GET" path:@"/ip" parameters:nil];
|
||||||
NSMutableURLRequest *secondRequest = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
|
NSMutableURLRequest *secondRequest = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
|
||||||
NSMutableURLRequest *thirdRequest = [self.client requestWithMethod:@"POST" path:@"/path" parameters:nil];
|
NSMutableURLRequest *thirdRequest = [self.client requestWithMethod:@"POST" path:@"/path" parameters:nil];
|
||||||
|
|
||||||
[self.client enqueueBatchOfHTTPRequestOperationsWithRequests:@[ firstRequest, secondRequest, thirdRequest ] progressBlock:NULL completionBlock:NULL];
|
[self.client enqueueBatchOfHTTPRequestOperationsWithRequests:@[ firstRequest, secondRequest, thirdRequest ] progressBlock:nil completionBlock:nil];
|
||||||
[self.client.operationQueue setSuspended:YES];
|
[self.client.operationQueue setSuspended:YES];
|
||||||
|
|
||||||
[self.client cancelAllHTTPOperationsWithMethod:@"GET" path:@"/path"];
|
[self.client cancelAllHTTPOperationsWithMethod:@"GET" path:@"/path"];
|
||||||
|
|
||||||
NSUInteger numberOfCancelledOperations = [[self.client.operationQueue.operations indexesOfObjectsPassingTest:^BOOL(NSOperation *operation, NSUInteger idx, BOOL *stop) {
|
NSUInteger numberOfCancelledOperations = [[self.client.operationQueue.operations indexesOfObjectsPassingTest:^BOOL(NSOperation *operation, NSUInteger idx, BOOL *stop) {
|
||||||
return [operation isCancelled];
|
return [operation isCancelled];
|
||||||
}] count];
|
}] count];
|
||||||
|
|
@ -221,7 +221,7 @@
|
||||||
|
|
||||||
- (void)testConstructingPOSTRequestWithParametersInFormURLParameterEncoding {
|
- (void)testConstructingPOSTRequestWithParametersInFormURLParameterEncoding {
|
||||||
self.client.parameterEncoding = AFFormURLParameterEncoding;
|
self.client.parameterEncoding = AFFormURLParameterEncoding;
|
||||||
|
|
||||||
NSMutableURLRequest *request = [self.client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
NSMutableURLRequest *request = [self.client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
||||||
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
||||||
expect(requestBody).to.equal(@"key=value");
|
expect(requestBody).to.equal(@"key=value");
|
||||||
|
|
@ -229,7 +229,7 @@
|
||||||
|
|
||||||
- (void)testConstructingPOSTRequestWithParametersInJSONParameterEncoding {
|
- (void)testConstructingPOSTRequestWithParametersInJSONParameterEncoding {
|
||||||
self.client.parameterEncoding = AFJSONParameterEncoding;
|
self.client.parameterEncoding = AFJSONParameterEncoding;
|
||||||
|
|
||||||
NSMutableURLRequest *request = [self.client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
NSMutableURLRequest *request = [self.client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
||||||
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
||||||
expect(requestBody).to.equal(@"{\"key\":\"value\"}");
|
expect(requestBody).to.equal(@"{\"key\":\"value\"}");
|
||||||
|
|
@ -237,7 +237,7 @@
|
||||||
|
|
||||||
- (void)testConstructingPOSTRequestWithParametersInPropertyListParameterEncoding {
|
- (void)testConstructingPOSTRequestWithParametersInPropertyListParameterEncoding {
|
||||||
self.client.parameterEncoding = AFPropertyListParameterEncoding;
|
self.client.parameterEncoding = AFPropertyListParameterEncoding;
|
||||||
|
|
||||||
NSMutableURLRequest *request = [self.client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
NSMutableURLRequest *request = [self.client requestWithMethod:@"POST" path:@"/post" parameters:@{ @"key": @"value" }];
|
||||||
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
NSString *requestBody = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
|
||||||
expect(requestBody).to.equal(@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>key</key>\n <string>value</string>\n</dict>\n</plist>\n");
|
expect(requestBody).to.equal(@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>key</key>\n <string>value</string>\n</dict>\n</plist>\n");
|
||||||
|
|
@ -248,75 +248,75 @@
|
||||||
[self.client postPath:@"/post" parameters:@{ @"key": @"value" } success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
[self.client postPath:@"/post" parameters:@{ @"key": @"value" } success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
blockResponseObject = responseObject;
|
blockResponseObject = responseObject;
|
||||||
} failure:nil];
|
} failure:nil];
|
||||||
|
|
||||||
expect([self.client.operationQueue operationCount]).will.equal(0);
|
expect([self.client.operationQueue operationCount]).will.equal(0);
|
||||||
expect(blockResponseObject).notTo.beNil();
|
expect(blockResponseObject).notTo.beNil();
|
||||||
expect(blockResponseObject).to.beKindOf([NSData class]);
|
expect(blockResponseObject).to.beKindOf([NSData class]);
|
||||||
|
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:blockResponseObject options:0 error:&error];
|
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:blockResponseObject options:0 error:&error];
|
||||||
expect(responseDictionary[@"form"]).to.equal(@{ @"key": @"value" });
|
expect([responseDictionary valueForKey:@"form"]).to.equal(@{ @"key": @"value" });
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatEnqueueBatchOfHTTPRequestOperationsConstructsOperationsWithAppropriateRegisteredHTTPRequestOperationClasses {
|
- (void)testThatEnqueueBatchOfHTTPRequestOperationsConstructsOperationsWithAppropriateRegisteredHTTPRequestOperationClasses {
|
||||||
[self.client registerHTTPOperationClass:[AFJSONRequestOperation class]];
|
[self.client registerHTTPOperationClass:[AFJSONRequestOperation class]];
|
||||||
[self.client registerHTTPOperationClass:[AFImageRequestOperation class]];
|
[self.client registerHTTPOperationClass:[AFImageRequestOperation class]];
|
||||||
|
|
||||||
NSMutableURLRequest *firstRequest = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
|
NSMutableURLRequest *firstRequest = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
|
||||||
[firstRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
|
[firstRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
|
||||||
|
|
||||||
NSMutableURLRequest *secondRequest = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
|
NSMutableURLRequest *secondRequest = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
|
||||||
[secondRequest setValue:@"image/png" forHTTPHeaderField:@"Accept"];
|
[secondRequest setValue:@"image/png" forHTTPHeaderField:@"Accept"];
|
||||||
|
|
||||||
__block NSArray *operations = nil;
|
__block NSArray *operations = nil;
|
||||||
id mockClient = [OCMockObject partialMockForObject:self.client];
|
id mockClient = [OCMockObject partialMockForObject:self.client];
|
||||||
void (^theBlock)(NSInvocation *) = ^(NSInvocation *invocation) {
|
void (^block)(NSInvocation *) = ^(NSInvocation *invocation) {
|
||||||
__unsafe_unretained id argument = nil;
|
__unsafe_unretained id argument = nil;
|
||||||
[invocation getArgument:&argument atIndex:2];
|
[invocation getArgument:&argument atIndex:2];
|
||||||
|
|
||||||
operations = argument;
|
operations = argument;
|
||||||
};
|
};
|
||||||
[[[mockClient stub] andDo:theBlock] enqueueBatchOfHTTPRequestOperations:[OCMArg any] progressBlock:nil completionBlock:nil];
|
[[[mockClient stub] andDo:block] enqueueBatchOfHTTPRequestOperations:[OCMArg any] progressBlock:nil completionBlock:nil];
|
||||||
[mockClient enqueueBatchOfHTTPRequestOperationsWithRequests:@[ firstRequest, secondRequest ] progressBlock:nil completionBlock:nil];
|
[mockClient enqueueBatchOfHTTPRequestOperationsWithRequests:@[ firstRequest, secondRequest ] progressBlock:nil completionBlock:nil];
|
||||||
|
|
||||||
expect(operations).notTo.beNil();
|
expect(operations).notTo.beNil();
|
||||||
expect(operations).to.haveCountOf(2);
|
expect(operations).to.haveCountOf(2);
|
||||||
|
|
||||||
expect([operations[0] class]).to.equal([AFJSONRequestOperation class]);
|
expect([[operations objectAtIndex:0] class]).to.equal([AFJSONRequestOperation class]);
|
||||||
expect([operations[1] class]).to.equal([AFImageRequestOperation class]);
|
expect([[operations objectAtIndex:1] class]).to.equal([AFImageRequestOperation class]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatEnqueueBatchOfHTTPRequestOperationsEnqueuesOperationsInTheCorrectOrder {
|
- (void)testThatEnqueueBatchOfHTTPRequestOperationsEnqueuesOperationsInTheCorrectOrder {
|
||||||
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
|
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
|
||||||
AFHTTPRequestOperation *firstOperation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
AFHTTPRequestOperation *firstOperation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
AFHTTPRequestOperation *secondOperation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
|
AFHTTPRequestOperation *secondOperation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
|
||||||
|
|
||||||
id mockClient = [OCMockObject partialMockForObject:self.client];
|
id mockClient = [OCMockObject partialMockForObject:self.client];
|
||||||
id mockOperationQueue = [OCMockObject mockForClass:[NSOperationQueue class]];
|
id mockOperationQueue = [OCMockObject mockForClass:[NSOperationQueue class]];
|
||||||
[[[mockClient stub] andReturn:mockOperationQueue] operationQueue];
|
[[[mockClient stub] andReturn:mockOperationQueue] operationQueue];
|
||||||
|
|
||||||
__block NSArray *operations = nil;
|
__block NSArray *operations = nil;
|
||||||
[[[mockOperationQueue stub] andDo:^(NSInvocation *invocation) {
|
[[[mockOperationQueue stub] andDo:^(NSInvocation *invocation) {
|
||||||
__unsafe_unretained id argument = nil;
|
__unsafe_unretained id argument = nil;
|
||||||
[invocation getArgument:&argument atIndex:2];
|
[invocation getArgument:&argument atIndex:2];
|
||||||
|
|
||||||
operations = argument;
|
operations = argument;
|
||||||
}] addOperations:OCMOCK_ANY waitUntilFinished:NO];
|
}] addOperations:OCMOCK_ANY waitUntilFinished:NO];
|
||||||
|
|
||||||
__block NSBlockOperation *batchedOperation = nil;
|
__block NSBlockOperation *batchedOperation = nil;
|
||||||
[[[mockOperationQueue stub] andDo:^(NSInvocation *invocation) {
|
[[[mockOperationQueue stub] andDo:^(NSInvocation *invocation) {
|
||||||
__unsafe_unretained id argument = nil;
|
__unsafe_unretained id argument = nil;
|
||||||
[invocation getArgument:&argument atIndex:2];
|
[invocation getArgument:&argument atIndex:2];
|
||||||
|
|
||||||
batchedOperation = argument;
|
batchedOperation = argument;
|
||||||
}] addOperation:OCMOCK_ANY];
|
}] addOperation:OCMOCK_ANY];
|
||||||
[mockClient enqueueBatchOfHTTPRequestOperations:@[ firstOperation, secondOperation ] progressBlock:NULL completionBlock:NULL];
|
[mockClient enqueueBatchOfHTTPRequestOperations:@[ firstOperation, secondOperation ] progressBlock:nil completionBlock:nil];
|
||||||
|
|
||||||
expect(operations).to.haveCountOf(2);
|
expect(operations).to.haveCountOf(2);
|
||||||
|
|
||||||
expect(operations[0]).to.equal(firstOperation);
|
expect([operations objectAtIndex:0]).to.equal(firstOperation);
|
||||||
expect(operations[1]).to.equal(secondOperation);
|
expect([operations objectAtIndex:1]).to.equal(secondOperation);
|
||||||
|
|
||||||
expect(batchedOperation).notTo.beNil();
|
expect(batchedOperation).notTo.beNil();
|
||||||
expect(batchedOperation).to.beKindOf([NSBlockOperation class]);
|
expect(batchedOperation).to.beKindOf([NSBlockOperation class]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue