public async Task TestBatchApiRequestsTenRequestsAsync() { Trace.WriteLine("POST /batch"); // Start the batch request BatchApiRequest.StartNewBatchRequest(); // Make the API calls to be batched (at least one of each type) try { await TemplateTest.BuildAndSendCreateTemplateRequestWithAllParametersAsync(); // POST await Snippet.GetSnippetsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await RenderTest.BuildAndSendRenderTemplateRequestWithAllParametersId(); // POST await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await EmailTest.BuildAndSendEmailWithAllParametersAsync(); // POST await DripCampaign.GetDripCampaignsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET // Make the batch Api Reqeust var batchResponses = await BatchApiRequest.SendBatchApiRequest(); // Validate the response to the batch API request ValidateBatchApiCallResponses(batchResponses, 10); // Validate the response to the individual API calls ValidateIndividualBatchedApiCallResponse <Template>(batchResponses[0]); ValidateIndividualBatchedApiCallResponse <List <Snippet> >(batchResponses[1]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[2]); ValidateIndividualBatchedApiCallResponse <RenderTemplateResponse>(batchResponses[3]); ValidateIndividualBatchedApiCallResponse <List <Log> >(batchResponses[4]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[5]); ValidateIndividualBatchedApiCallResponse <EmailResponse>(batchResponses[6]); ValidateIndividualBatchedApiCallResponse <List <DripCampaignDetails> >(batchResponses[7]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[8]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[9]); } catch (AggregateException exception) { Assert.Fail(exception.ToString()); } }
public async Task TestBatchApiRequestsTwelveRequestsWithoutOverrideAsync() { Trace.WriteLine("POST /batch"); // Start the batch request BatchApiRequest.StartNewBatchRequest(); // Override the maximum number of API calls that can be included in this batch BatchApiRequest.OverrideMaximumBatchRequests(12); // Make the API calls to be batched (at least one of each type) try { await TemplateTest.BuildAndSendCreateTemplateRequestWithAllParametersAsync(); // POST await Snippet.GetSnippetsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await RenderTest.BuildAndSendRenderTemplateRequestWithAllParametersId(); // POST await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await EmailTest.BuildAndSendEmailWithAllParametersAsync(); // POST await DripCampaign.GetDripCampaignsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET // Make the batch Api Request var batchResponses = await BatchApiRequest.SendBatchApiRequest(); // Validate the response to the batch API request ValidateBatchApiCallResponses(batchResponses, 11); // Validate the response to the individual API calls ValidateIndividualBatchedApiCallResponse <Template>(batchResponses[0]); ValidateIndividualBatchedApiCallResponse <List <Snippet> >(batchResponses[1]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[2]); ValidateIndividualBatchedApiCallResponse <RenderTemplateResponse>(batchResponses[3]); ValidateIndividualBatchedApiCallResponse <List <Log> >(batchResponses[4]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[5]); ValidateIndividualBatchedApiCallResponse <EmailResponse>(batchResponses[6]); ValidateIndividualBatchedApiCallResponse <List <DripCampaignDetails> >(batchResponses[7]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[8]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[9]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[10]); } catch (InvalidOperationException exception) { Trace.WriteLine(String.Format("Successfully caught exception triggered by adding too many API calls to the batch API request. Error message: {0}", exception.Message)); Assert.IsTrue(true); } finally { // Return the max batch request limit to its default value BatchApiRequest.SetMaximumBatchRequestsToDefault(); } }
public async Task TestBatchApiRequestsElevenRequestsWithoutOverrideAsync() { Trace.WriteLine("POST /batch"); // Start the batch request BatchApiRequest.StartNewBatchRequest(); try { // Make the API calls to be batched (at least one of each type) await TemplateTest.BuildAndSendCreateTemplateRequestWithAllParametersAsync(); // POST await Snippet.GetSnippetsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await RenderTest.BuildAndSendRenderTemplateRequestWithAllParametersId(); // POST await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await EmailTest.BuildAndSendEmailWithAllParametersAsync(); // POST await DripCampaign.GetDripCampaignsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET // Add the 11th API Request try { await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET } catch (InvalidOperationException exception) { Trace.WriteLine(String.Format("Successfully caught exception triggered by adding too many API calls to the batch API request. Error message: {0}", exception.Message)); Assert.IsTrue(true); } // Send the batch AP Request and make sure it still goes through (with the previous 10 requests included) var batchResponses = await BatchApiRequest.SendBatchApiRequest(); // Validate the response to the batch API request ValidateBatchApiCallResponses(batchResponses, 10); // Validate the response to the individual API calls ValidateIndividualBatchedApiCallResponse <Template>(batchResponses[0]); ValidateIndividualBatchedApiCallResponse <List <Snippet> >(batchResponses[1]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[2]); ValidateIndividualBatchedApiCallResponse <RenderTemplateResponse>(batchResponses[3]); await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[5]); ValidateIndividualBatchedApiCallResponse <EmailResponse>(batchResponses[6]); ValidateIndividualBatchedApiCallResponse <List <DripCampaignDetails> >(batchResponses[7]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[8]); ValidateIndividualBatchedApiCallResponse <Customer>(batchResponses[9]); } catch (AggregateException exception) { Assert.Fail(exception.ToString()); } }