Update tests to use new API · ElfSundae/AFNetworking@0579f71
@@ -25,24 +25,25 @@
2525#import "AFSecurityPolicy.h"
26262727@interface AFHTTPSessionManagerTests : AFTestCase
28-@property (readwrite, nonatomic, strong) AFHTTPSessionManager *manager;
28+@property (readwrite, nonatomic, strong) AFHTTPSessionManager *sessionManager;
2929@end
30303131@implementation AFHTTPSessionManagerTests
32323333- (void)setUp {
3434 [super setUp];
35- self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:self.baseURL];
35+ self.sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:self.baseURL];
3636}
37373838- (void)tearDown {
39- [self.manager invalidateSessionCancelingTasks:YES];
39+ [self.sessionManager invalidateSessionCancelingTasks:YES resetSession:YES];
40+ self.sessionManager = nil;
4041 [super tearDown];
4142}
42434344#pragma mark - init
4445- (void)testSharedManagerIsNotEqualToInitdManager {
45-XCTAssertFalse([[AFHTTPSessionManager manager] isEqual:self.manager]);
46+XCTAssertFalse([[AFHTTPSessionManager manager] isEqual:self.sessionManager]);
4647}
47484849#pragma mark - misc
@@ -54,7 +55,7 @@ - (void)testThatOperationInvokesCompletionHandlerWithResponseObjectOnSuccess {
5455 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
55565657NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/get" relativeToURL:self.baseURL]];
57-NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
58+NSURLSessionDataTask *task = [self.sessionManager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
5859completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
5960 blockResponseObject = responseObject;
6061 blockError = error;
@@ -76,7 +77,7 @@ - (void)testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure {
7677 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
77787879NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:self.baseURL]];
79-NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
80+NSURLSessionDataTask *task = [self.sessionManager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil
8081completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
8182 blockError = error;
8283 [expectation fulfill];
@@ -97,13 +98,13 @@ - (void)testThatRedirectBlockIsCalledWhen302IsEncountered {
9798 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
989999100NSURLRequest *redirectRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:self.baseURL]];
100-NSURLSessionDataTask *redirectTask = [self.manager dataTaskWithRequest:redirectRequest uploadProgress:nil downloadProgress:nil
101+NSURLSessionDataTask *redirectTask = [self.sessionManager dataTaskWithRequest:redirectRequest uploadProgress:nil downloadProgress:nil
101102completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
102103 blockError = error;
103104 [expectation fulfill];
104105 }];
105106106- [self.manager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest *(NSURLSession *session, NSURLSessionTask *task, NSURLResponse *response, NSURLRequest *request) {
107+ [self.sessionManager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest *(NSURLSession *session, NSURLSessionTask *task, NSURLResponse *response, NSURLRequest *request) {
107108if (response) {
108109 success = YES;
109110 }
@@ -126,14 +127,14 @@ - (void)testDownloadFileCompletionSpecifiesURLInCompletionWithManagerDidFinishBl
126127 __block NSURL *downloadFilePath = nil;
127128 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
128129129- [self.manager setDownloadTaskDidFinishDownloadingBlock:^NSURL *(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location) {
130+ [self.sessionManager setDownloadTaskDidFinishDownloadingBlock:^NSURL *(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location) {
130131 managerDownloadFinishedBlockExecuted = YES;
131132NSURL *dirURL = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
132133return [dirURL URLByAppendingPathComponent:@"t1.file"];
133134 }];
134135135136NSURLSessionDownloadTask *downloadTask;
136- downloadTask = [self.manager
137+ downloadTask = [self.sessionManager
137138downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
138139progress:nil
139140destination:nil
@@ -155,7 +156,7 @@ - (void)testDownloadFileCompletionSpecifiesURLInCompletionBlock {
155156 __block NSURL *downloadFilePath = nil;
156157 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
157158158-NSURLSessionDownloadTask *downloadTask = [self.manager downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
159+NSURLSessionDownloadTask *downloadTask = [self.sessionManager downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
159160progress:nil
160161destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
161162 destinationBlockExecuted = YES;
@@ -177,15 +178,15 @@ - (void)testDownloadFileCompletionSpecifiesURLInCompletionBlock {
177178- (void)testThatSerializationErrorGeneratesErrorAndNullTaskForGET {
178179 XCTestExpectation *expectation = [self expectationWithDescription:@"Serialization should fail"];
179180180- [self.manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
181+ [self.sessionManager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
181182if (error != NULL) {
182183 *error = [NSError errorWithDomain:@"Custom" code:-1 userInfo:nil];
183184 }
184185return @"";
185186 }];
186187187188NSURLSessionTask *nilTask;
188- nilTask = [self.manager
189+ nilTask = [self.sessionManager
189190GET:@"test"
190191parameters:@{@"key":@"value"}
191192headers:nil
@@ -206,12 +207,12 @@ - (void)testSupportsSecureCoding {
206207}
207208208209- (void)testCanBeEncoded {
209-NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.manager];
210+NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.sessionManager];
210211XCTAssertNotNil(data);
211212}
212213213214- (void)testCanBeDecoded {
214-NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.manager];
215+NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.sessionManager];
215216 AFHTTPSessionManager *newManager = [NSKeyedUnarchiver unarchiveObjectWithData:data];
216217XCTAssertNotNil(newManager.securityPolicy);
217218XCTAssertNotNil(newManager.requestSerializer);
@@ -224,15 +225,15 @@ - (void)testCanBeDecoded {
224225#pragma mark - NSCopying
225226226227- (void)testCanBeCopied {
227- AFHTTPSessionManager *copyManager = [self.manager copy];
228+ AFHTTPSessionManager *copyManager = [self.sessionManager copy];
228229XCTAssertNotNil(copyManager);
229230}
230231231232#pragma mark - Progress
232233233234- (void)testDownloadProgressIsReportedForGET {
234235 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
235- [self.manager
236+ [self.sessionManager
236237GET:@"image"
237238parameters:nil
238239headers:nil
@@ -254,7 +255,7 @@ - (void)testUploadProgressIsReportedForPOST {
254255255256 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
256257257- [self.manager
258+ [self.sessionManager
258259POST:@"post"
259260parameters:payload
260261headers:nil
@@ -276,7 +277,7 @@ - (void)testUploadProgressIsReportedForStreamingPost {
276277277278 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
278279279- [self.manager
280+ [self.sessionManager
280281POST:@"post"
281282parameters:nil
282283headers:nil
@@ -299,7 +300,7 @@ - (void)testDownloadProgressIsReportedForDeprecatedGET {
299300 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
300301#pragma clang diagnostic push
301302#pragma clang diagnostic ignored "-Wdeprecated-declarations"
302- [self.manager
303+ [self.sessionManager
303304GET:@"image"
304305parameters:nil
305306progress:^(NSProgress * _Nonnull downloadProgress) {
@@ -322,7 +323,7 @@ - (void)testUploadProgressIsReportedForDeprecatedPOST {
322323 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
323324#pragma clang diagnostic push
324325#pragma clang diagnostic ignored "-Wdeprecated-declarations"
325- [self.manager
326+ [self.sessionManager
326327POST:@"post"
327328parameters:payload
328329progress:^(NSProgress * _Nonnull uploadProgress) {
@@ -345,7 +346,7 @@ - (void)testUploadProgressIsReportedForStreamingDeprecatedPost {
345346 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];
346347#pragma clang diagnostic push
347348#pragma clang diagnostic ignored "-Wdeprecated-declarations"
348- [self.manager
349+ [self.sessionManager
349350POST:@"post"
350351parameters:nil
351352constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
@@ -366,7 +367,7 @@ - (void)testUploadProgressIsReportedForStreamingDeprecatedPost {
366367367368- (void)testThatSuccessBlockIsCalledFor200 {
368369 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
369- [self.manager
370+ [self.sessionManager
370371GET:@"status/200"
371372parameters:nil
372373headers:nil
@@ -380,7 +381,7 @@ - (void)testThatSuccessBlockIsCalledFor200 {
380381381382- (void)testThatFailureBlockIsCalledFor404 {
382383 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
383- [self.manager
384+ [self.sessionManager
384385GET:@"status/404"
385386parameters:nil
386387headers:nil
@@ -395,7 +396,7 @@ - (void)testThatFailureBlockIsCalledFor404 {
395396- (void)testThatResponseObjectIsEmptyFor204 {
396397 __block id urlResponseObject = nil;
397398 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
398- [self.manager
399+ [self.sessionManager
399400GET:@"status/204"
400401parameters:nil
401402headers:nil
@@ -413,7 +414,7 @@ - (void)testThatResponseObjectIsEmptyFor204 {
413414414415- (void)testGET {
415416 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
416- [self.manager
417+ [self.sessionManager
417418GET:@"get"
418419parameters:nil
419420headers:nil
@@ -428,7 +429,7 @@ - (void)testGET {
428429429430- (void)testHEAD {
430431 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
431- [self.manager
432+ [self.sessionManager
432433HEAD:@"get"
433434parameters:nil
434435headers:nil
@@ -442,7 +443,7 @@ - (void)testHEAD {
442443443444- (void)testPOST {
444445 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
445- [self.manager
446+ [self.sessionManager
446447POST:@"post"
447448parameters:@{@"key":@"value"}
448449headers:@{@"field":@"value"}
@@ -458,7 +459,7 @@ - (void)testPOST {
458459459460- (void)testPOSTWithConstructingBody {
460461 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
461- [self.manager
462+ [self.sessionManager
462463POST:@"post"
463464parameters:@{@"key":@"value"}
464465headers:@{@"field":@"value"}
@@ -481,7 +482,7 @@ - (void)testPOSTWithConstructingBody {
481482482483- (void)testPUT {
483484 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
484- [self.manager
485+ [self.sessionManager
485486PUT:@"put"
486487parameters:@{@"key":@"value"}
487488headers:@{@"field":@"value"}
@@ -496,7 +497,7 @@ - (void)testPUT {
496497497498- (void)testDELETE {
498499 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
499- [self.manager
500+ [self.sessionManager
500501DELETE:@"delete"
501502parameters:@{@"key":@"value"}
502503headers:@{@"field":@"value"}
@@ -511,7 +512,7 @@ - (void)testDELETE {
511512512513- (void)testPATCH {
513514 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
514- [self.manager
515+ [self.sessionManager
515516PATCH:@"patch"
516517parameters:@{@"key":@"value"}
517518headers:@{@"field":@"value"}
@@ -531,7 +532,7 @@ - (void)testDeprecatedGETWithoutProgress {
531532 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
532533#pragma clang diagnostic push
533534#pragma clang diagnostic ignored "-Wdeprecated-declarations"
534- [self.manager
535+ [self.sessionManager
535536GET:@"get"
536537parameters:nil
537538success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
@@ -547,7 +548,7 @@ - (void)testDeprecatedPOSTWithoutProgress {
547548 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
548549#pragma clang diagnostic push
549550#pragma clang diagnostic ignored "-Wdeprecated-declarations"
550- [self.manager
551+ [self.sessionManager
551552POST:@"post"
552553parameters:@{@"key":@"value"}
553554success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
@@ -563,7 +564,7 @@ - (void)testDeprecatedPOSTWithoutProgressWithConstructingBody {
563564 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
564565#pragma clang diagnostic push
565566#pragma clang diagnostic ignored "-Wdeprecated-declarations"
566- [self.manager
567+ [self.sessionManager
567568POST:@"post"
568569parameters:@{@"key":@"value"}
569570constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
@@ -587,7 +588,7 @@ - (void)testDeprecatedGETWithoutHeaders {
587588 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
588589#pragma clang diagnostic push
589590#pragma clang diagnostic ignored "-Wdeprecated-declarations"
590- [self.manager
591+ [self.sessionManager
591592GET:@"get"
592593parameters:nil
593594progress:nil
@@ -604,7 +605,7 @@ - (void)testDeprecatedHEADWithoutHeaders {
604605 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
605606#pragma clang diagnostic push
606607#pragma clang diagnostic ignored "-Wdeprecated-declarations"
607- [self.manager
608+ [self.sessionManager
608609HEAD:@"get"
609610parameters:nil
610611success:^(NSURLSessionDataTask * _Nonnull task) {
@@ -620,7 +621,7 @@ - (void)testDeprecatedPOSTWithoutHeaders {
620621 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
621622#pragma clang diagnostic push
622623#pragma clang diagnostic ignored "-Wdeprecated-declarations"
623- [self.manager
624+ [self.sessionManager
624625POST:@"post"
625626parameters:@{@"key":@"value"}
626627progress:nil
@@ -637,7 +638,7 @@ - (void)testDeprecatedPOSTWithoutHeadersWithConstructingBody {
637638 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
638639#pragma clang diagnostic push
639640#pragma clang diagnostic ignored "-Wdeprecated-declarations"
640- [self.manager
641+ [self.sessionManager
641642POST:@"post"
642643parameters:@{@"key":@"value"}
643644constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
@@ -661,7 +662,7 @@ - (void)testDeprecatedPUTWithoutHeaders {
661662 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
662663#pragma clang diagnostic push
663664#pragma clang diagnostic ignored "-Wdeprecated-declarations"
664- [self.manager
665+ [self.sessionManager
665666PUT:@"put"
666667parameters:@{@"key":@"value"}
667668success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
@@ -677,7 +678,7 @@ - (void)testDeprecatedDELETEWithoutHeaders {
677678 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
678679#pragma clang diagnostic push
679680#pragma clang diagnostic ignored "-Wdeprecated-declarations"
680- [self.manager
681+ [self.sessionManager
681682DELETE:@"delete"
682683parameters:@{@"key":@"value"}
683684success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
@@ -693,7 +694,7 @@ - (void)testDeprecatedPATCHWithoutHeaders {
693694 XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
694695#pragma clang diagnostic push
695696#pragma clang diagnostic ignored "-Wdeprecated-declarations"
696- [self.manager
697+ [self.sessionManager
697698PATCH:@"patch"
698699parameters:@{@"key":@"value"}
699700success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
@@ -709,8 +710,8 @@ - (void)testDeprecatedPATCHWithoutHeaders {
709710710711- (void)testHiddenBasicAuthentication {
711712 __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Request should finish"];
712- [self.manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"user" password:@"password"];
713- [self.manager
713+ [self.sessionManager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"user" password:@"password"];
714+ [self.sessionManager
714715GET:@"hidden-basic-auth/user/password"
715716parameters:nil
716717headers:nil
@@ -798,7 +799,7 @@ - (void)testInvalidServerTrustProducesCorrectErrorForCertificatePinning {
798799 [expectation fulfill];
799800 }];
800801 [self waitForExpectationsWithCommonTimeout];
801- [manager invalidateSessionCancelingTasks:YES];
802+ [manager invalidateSessionCancelingTasks:YES resetSession:NO];
802803}
803804804805- (void)testInvalidServerTrustProducesCorrectErrorForPublicKeyPinning {
@@ -823,7 +824,7 @@ - (void)testInvalidServerTrustProducesCorrectErrorForPublicKeyPinning {
823824 [expectation fulfill];
824825 }];
825826 [self waitForExpectationsWithCommonTimeout];
826- [manager invalidateSessionCancelingTasks:YES];
827+ [manager invalidateSessionCancelingTasks:YES resetSession:NO];
827828}
828829829830@end