public async Task TestBatchApiRequestsAbortRequestAsync()
        {
            Trace.WriteLine("POST /batch");

            // Start the batch request
            BatchApiRequest.StartNewBatchRequest();

            try
            {
                // Make the API call to be batched
                await Template.GetTemplatesAsync();

                // Abort the batch request
                BatchApiRequest.AbortBatchRequest();

                // Make another API call and make sure it goes through
                var snippets = await Snippet.GetSnippetsAsync();

                SendwithusClientTest.ValidateResponse(snippets);

                // Make the aborted batch API Reqeust anyways
                var batchResponses = await BatchApiRequest.SendBatchApiRequest();

                // Make sure no API calls were included in the batch request (empty request)
                ValidateBatchApiCallResponses(batchResponses, 0);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
        private async Task <BatchRequestResponse> SendBatchRequestAsync(Func <Task> executeRequests)
        {
            BatchApiRequest.StartNewBatchRequest();

            try
            {
                bool isBatchSuccess = true;
                var  data           = new List <object>();

                await executeRequests();

                List <BatchApiResponse> batchResponses = await BatchApiRequest.SendBatchApiRequest();

                for (int i = 0; i < batchResponses.Count; i++)
                {
                    BatchApiResponse batchResponse = batchResponses[i];
                    if (batchResponse.status_code != 200)
                    {
                        isBatchSuccess = false;
                        BatchApiRequest.AbortBatchRequest();
                        break;
                    }
                    var body = batchResponses[i].GetBody <object>();
                    data.Add(body);
                }

                var response = new BatchRequestResponse(isBatchSuccess, "200", data.ToJson());
                return(response);
            }
            catch (AggregateException ex)
            {
                BatchApiRequest.AbortBatchRequest();
                return(new BatchRequestResponse(false, "500", null, ex.ToString()));
            }
            catch (InvalidOperationException ex)
            {
                BatchApiRequest.AbortBatchRequest();
                return(new BatchRequestResponse(false, "500", null, ex.ToString()));
            }
        }