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"];

55565657

NSURLRequest *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

5859

completionHandler:^(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"];

77787879

NSURLRequest *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

8081

completionHandler:^(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"];

989999100

NSURLRequest *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

101102

completionHandler:^(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) {

107108

if (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;

131132

NSURL *dirURL = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];

132133

return [dirURL URLByAppendingPathComponent:@"t1.file"];

133134

}];

134135135136

NSURLSessionDownloadTask *downloadTask;

136-

downloadTask = [self.manager

137+

downloadTask = [self.sessionManager

137138

downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]

138139

progress:nil

139140

destination: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]

159160

progress:nil

160161

destination:^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) {

181182

if (error != NULL) {

182183

*error = [NSError errorWithDomain:@"Custom" code:-1 userInfo:nil];

183184

}

184185

return @"";

185186

}];

186187187188

NSURLSessionTask *nilTask;

188-

nilTask = [self.manager

189+

nilTask = [self.sessionManager

189190

GET:@"test"

190191

parameters:@{@"key":@"value"}

191192

headers: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];

210211

XCTAssertNotNil(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];

216217

XCTAssertNotNil(newManager.securityPolicy);

217218

XCTAssertNotNil(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];

228229

XCTAssertNotNil(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

236237

GET:@"image"

237238

parameters:nil

238239

headers:nil

@@ -254,7 +255,7 @@ - (void)testUploadProgressIsReportedForPOST {

254255255256

__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];

256257257-

[self.manager

258+

[self.sessionManager

258259

POST:@"post"

259260

parameters:payload

260261

headers:nil

@@ -276,7 +277,7 @@ - (void)testUploadProgressIsReportedForStreamingPost {

276277277278

__weak XCTestExpectation *expectation = [self expectationWithDescription:@"Progress Should equal 1.0"];

278279279-

[self.manager

280+

[self.sessionManager

280281

POST:@"post"

281282

parameters:nil

282283

headers: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

303304

GET:@"image"

304305

parameters:nil

305306

progress:^(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

326327

POST:@"post"

327328

parameters:payload

328329

progress:^(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

349350

POST:@"post"

350351

parameters:nil

351352

constructingBodyWithBlock:^(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

370371

GET:@"status/200"

371372

parameters:nil

372373

headers:nil

@@ -380,7 +381,7 @@ - (void)testThatSuccessBlockIsCalledFor200 {

380381381382

- (void)testThatFailureBlockIsCalledFor404 {

382383

XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];

383-

[self.manager

384+

[self.sessionManager

384385

GET:@"status/404"

385386

parameters:nil

386387

headers: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

399400

GET:@"status/204"

400401

parameters:nil

401402

headers:nil

@@ -413,7 +414,7 @@ - (void)testThatResponseObjectIsEmptyFor204 {

413414414415

- (void)testGET {

415416

XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];

416-

[self.manager

417+

[self.sessionManager

417418

GET:@"get"

418419

parameters:nil

419420

headers:nil

@@ -428,7 +429,7 @@ - (void)testGET {

428429429430

- (void)testHEAD {

430431

XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];

431-

[self.manager

432+

[self.sessionManager

432433

HEAD:@"get"

433434

parameters:nil

434435

headers:nil

@@ -442,7 +443,7 @@ - (void)testHEAD {

442443443444

- (void)testPOST {

444445

XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];

445-

[self.manager

446+

[self.sessionManager

446447

POST:@"post"

447448

parameters:@{@"key":@"value"}

448449

headers:@{@"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

462463

POST:@"post"

463464

parameters:@{@"key":@"value"}

464465

headers:@{@"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

485486

PUT:@"put"

486487

parameters:@{@"key":@"value"}

487488

headers:@{@"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

500501

DELETE:@"delete"

501502

parameters:@{@"key":@"value"}

502503

headers:@{@"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

515516

PATCH:@"patch"

516517

parameters:@{@"key":@"value"}

517518

headers:@{@"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

535536

GET:@"get"

536537

parameters:nil

537538

success:^(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

551552

POST:@"post"

552553

parameters:@{@"key":@"value"}

553554

success:^(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

567568

POST:@"post"

568569

parameters:@{@"key":@"value"}

569570

constructingBodyWithBlock:^(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

591592

GET:@"get"

592593

parameters:nil

593594

progress: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

608609

HEAD:@"get"

609610

parameters:nil

610611

success:^(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

624625

POST:@"post"

625626

parameters:@{@"key":@"value"}

626627

progress: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

641642

POST:@"post"

642643

parameters:@{@"key":@"value"}

643644

constructingBodyWithBlock:^(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

665666

PUT:@"put"

666667

parameters:@{@"key":@"value"}

667668

success:^(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

681682

DELETE:@"delete"

682683

parameters:@{@"key":@"value"}

683684

success:^(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

697698

PATCH:@"patch"

698699

parameters:@{@"key":@"value"}

699700

success:^(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

714715

GET:@"hidden-basic-auth/user/password"

715716

parameters:nil

716717

headers: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