@@ -26,29 +26,34 @@ - (void)tearDown {
2626 // Put teardown code here. This method is called after the invocation of each test method in the class.
2727}
2828
29- - (void )testInit {
29+ - (void )testInitWithNilRequestStepArray {
3030 NSError *error;
31- MSBatchRequestContent *requestContent = [[MSBatchRequestContent alloc ] initWithRequests: nil error: &error];
31+ [[MSBatchRequestContent alloc ] initWithRequests: nil error: &error];
3232 XCTAssertNil (error);
33+ }
3334
35+ - (void )testInitWithRequestStepArray {
3436 MSBatchRequestStep *mockBatchStep = [[MSBatchRequestStep alloc ] initWithId: @" 1" request: self .requestForMock andDependsOn: nil ];
35-
36- requestContent = [[MSBatchRequestContent alloc ] initWithRequests: @[mockBatchStep] error: &error];
37+ NSError *error;
38+ MSBatchRequestContent * requestContent = [[MSBatchRequestContent alloc ] initWithRequests: @[mockBatchStep] error: &error];
3739 XCTAssertNil (error);
40+ }
3841
42+ - (void )testInitWithMoreRequestStepsThanLimit {
3943 NSMutableArray *batchStepArray = [NSMutableArray new ];
44+ // Testing whether intitalizing the MSBatchRequestContent with more than max limit [currently 20], produces a client side error.
4045 for (int i=0 ;i<21 ;i++) {
4146 MSBatchRequestStep *batchStep = [[MSBatchRequestStep alloc ] initWithId: [NSString stringWithFormat: @" %d " ,i] request: self .requestForMock andDependsOn: nil ];
4247 [batchStepArray addObject: batchStep];
4348 }
44-
45- requestContent = [[MSBatchRequestContent alloc ] initWithRequests: batchStepArray error: &error];
49+ NSError *error;
50+ MSBatchRequestContent * requestContent = [[MSBatchRequestContent alloc ] initWithRequests: batchStepArray error: &error];
4651 XCTAssertNotNil (error);
4752 XCTAssertEqual (error.code , MSErrorCodeMaximumLimitReached);
4853
4954}
5055
51- - (void ) testAddBatchRequestStep {
56+ - (MSBatchRequestContent *) createBatchRequestContentWithCoupleOfSteps {
5257 NSError *error;
5358 MSBatchRequestContent *requestContent = [[MSBatchRequestContent alloc ] initWithRequests: nil error: &error];
5459 XCTAssertNil (error);
@@ -63,34 +68,51 @@ - (void)testAddBatchRequestStep {
6368 [requestContent addBatchRequestStep: driveBatchStep error: &error];
6469 XCTAssertNil (error);
6570
71+ return requestContent;
72+ }
73+
74+ - (void )testAddBatchRequestStepSuccessful {
75+ MSBatchRequestContent *requestContent = [self createBatchRequestContentWithCoupleOfSteps ];
6676 NSMutableDictionary *batchRequestContent = [requestContent getBatchRequestContent ];
6777 XCTAssertNotNil ([batchRequestContent objectForKey: @" requests" ]);
6878
6979 // Test for number of request step content
7080 NSArray *batchContentArray = [batchRequestContent objectForKey: @" requests" ];
7181 XCTAssertNotNil (batchContentArray);
7282 XCTAssertEqual (batchContentArray.count , 2 );
83+ }
7384
85+ - (void )testAddBatchRequestWithDuplicateRequest {
86+ MSBatchRequestContent *requestContent = [self createBatchRequestContentWithCoupleOfSteps ];
87+ NSMutableURLRequest *driveRequest = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: @" /me/drive" ]];
88+ MSBatchRequestStep *driveBatchStep = [[MSBatchRequestStep alloc ] initWithId: @" 2" request: driveRequest andDependsOn: @[@" 1" ]];
7489 // Test for duplicate request id
90+ NSError *error;
7591 [requestContent addBatchRequestStep: driveBatchStep error: &error];
7692 XCTAssertNotNil (error);
7793 XCTAssertEqual (error.code , MSErrorCodeNonUniqueRequestId);
78- error = nil ;
94+ }
7995
96+ - (void )testAddBatchReuqestWithEmptyRequestId {
97+ MSBatchRequestContent *requestContent = [self createBatchRequestContentWithCoupleOfSteps ];
8098 // Test for empty request id
8199 MSBatchRequestStep *empty = [[MSBatchRequestStep alloc ] initWithId: @" " request: self .requestForMock andDependsOn: nil ];
100+ NSError *error;
82101 [requestContent addBatchRequestStep: empty error: &error];
83102 XCTAssertNotNil (error);
84103 XCTAssertEqual (error.code , MSErrorCodeEmptyRequestId);
85- error = nil ;
104+ }
86105
87- // Add more request steps to reach the limit
88- for (int i=3 ;i<=20 ;i++) {
106+ - (void )testAddBatchRequestWithMoreStepsThanLimit {
107+ NSError *error;
108+ MSBatchRequestContent *requestContent = [[MSBatchRequestContent alloc ] initWithRequests: nil error: &error];
109+ XCTAssertNil (error);
110+ // Add request steps to reach the limit
111+ for (int i=1 ;i<=20 ;i++) {
89112 MSBatchRequestStep *batchStep = [[MSBatchRequestStep alloc ] initWithId: [NSString stringWithFormat: @" %d " ,i] request: self .requestForMock andDependsOn: nil ];
90113 [requestContent addBatchRequestStep: batchStep error: &error];
91114 XCTAssertNil (error);
92115 }
93-
94116 // Add one more to tip over the threshold value
95117 MSBatchRequestStep *batchStep = [[MSBatchRequestStep alloc ] initWithId: @" 21" request: self .requestForMock andDependsOn: nil ];
96118 [requestContent addBatchRequestStep: batchStep error: &error];
0 commit comments