Skip to content

Commit

Permalink
Added unit tests to test for the bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian King committed Nov 4, 2014
1 parent 009d906 commit 0a11dc4
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Tests/Tests/AFHTTPSessionManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,51 @@ - (void)testThatRedirectBlockIsCalledWhen302IsEncountered {
expect(success).will.beTruthy();
}

- (void)testDownloadFileCompletionSpecifiesURLInCompletionWithManagerDidFinishBlock {
__block BOOL managerDownloadFinishedBlockExecuted = NO;
__block BOOL completionBlockExecuted = NO;
__block NSURL *downloadFilePath = nil;
[self.manager setDownloadTaskDidFinishDownloadingBlock:^NSURL *(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location) {
managerDownloadFinishedBlockExecuted = YES;
NSURL *dirURL = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
return [dirURL URLByAppendingPathComponent:@"t1.file"];
}];

NSURLSessionDownloadTask *downloadTask = [self.manager downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
progress:nil
destination:nil
completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
downloadFilePath = filePath;
completionBlockExecuted = YES;
}];
[downloadTask resume];
expect(completionBlockExecuted).will.equal(YES);
expect(managerDownloadFinishedBlockExecuted).will.equal(YES);
expect(downloadFilePath).willNot.beNil();
}

- (void)testDownloadFileCompletionSpecifiesURLInCompletionBlock {
__block BOOL destinationBlockExecuted = NO;
__block BOOL completionBlockExecuted = NO;
__block NSURL *downloadFilePath = nil;

NSURLSessionDownloadTask *downloadTask = [self.manager downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
progress:nil
destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
destinationBlockExecuted = YES;
NSURL *dirURL = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
return [dirURL URLByAppendingPathComponent:@"t1.file"];
}
completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
downloadFilePath = filePath;
completionBlockExecuted = YES;
}];
[downloadTask resume];
expect(completionBlockExecuted).will.equal(YES);
expect(destinationBlockExecuted).will.equal(YES);
expect(downloadFilePath).willNot.beNil();
}



@end

0 comments on commit 0a11dc4

Please sign in to comment.