Example #1
0
        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.GetLogsAsync();                                                     // GET

                await EspAccount.SetDefaultEspAccountAsync(DEFAULT_ESP_ACCOUNT_ID);           // PUT

                await EmailTest.BuildAndSendEmailWithAllParametersAsync();                    // POST

                await DripCampaign.GetDripCampaignsAsync();                                   // GET

                await CustomerTest.BuildAndSendCreateCustomerRequest();                       // POST

                await Customer.DeleteCustomerAsync(CustomerTest.NEW_CUSTOMER_EMAIL_ADDRESS);  // DELETE

                // 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 <EspAccountResponse>(batchResponses[5]);
                ValidateIndividualBatchedApiCallResponse <EmailResponse>(batchResponses[6]);
                ValidateIndividualBatchedApiCallResponse <List <DripCampaignDetails> >(batchResponses[7]);
                ValidateIndividualBatchedApiCallResponse <GenericApiCallStatus>(batchResponses[8]);
                ValidateIndividualBatchedApiCallResponse <GenericApiCallStatus>(batchResponses[9]);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
        public async Task TestGetEspAccountsWithoutParametersAsync()
        {
            Trace.WriteLine("GET /esp_accounts");

            // Make the API call
            try
            {
                var espAccounts = await EspAccount.GetAccountsAsync();

                // Validate the response
                SendwithusClientTest.ValidateResponse(espAccounts);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
        public async Task TestSetDefaultEspAccountAsync()
        {
            Trace.WriteLine("PUT /esp_accounts/set_default");

            // Make the API call
            try
            {
                var espAccountResponse = await EspAccount.SetDefaultEspAccountAsync(DEFAULT_ESP_ACCOUNT_ID);

                // Validate the response
                SendwithusClientTest.ValidateResponse(espAccountResponse);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
        public async Task TestGetEspAccountsWithInvalidParameterAsync()
        {
            Trace.WriteLine("GET /esp_accounts");

            // Build the query parameters
            var queryParameters = new Dictionary <string, object>();

            queryParameters.Add("esp_type", INVALID_ESP_ACCOUNT_TYPE);

            // Make the API call
            try
            {
                var response = await EspAccount.GetAccountsAsync(queryParameters);

                Assert.Fail("Failed to throw exception");
            }
            catch (AggregateException exception)
            {
                // Make sure the response was HTTP 400 Bad Request
                SendwithusClientTest.ValidateException(exception, HttpStatusCode.BadRequest);
            }
        }
        public async Task TestGetEspAccountsWithAllParametersAsync()
        {
            Trace.WriteLine("GET /esp_accounts");

            // Build the query parameters
            var queryParameters = new Dictionary <string, object>();

            queryParameters.Add("esp_type", DEFAULT_ESP_ACCOUNT_TYPE);

            // Make the API call
            try
            {
                var espAccounts = await EspAccount.GetAccountsAsync(queryParameters);

                // Validate the response
                SendwithusClientTest.ValidateResponse(espAccounts);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
        public async Task TestDefaultRetryCountWithPutAsync()
        {
            // Set the timeout low enough that the API call is guaranteed to fail
            SendwithusClient.SetTimeoutInMilliseconds(FAILURE_TIMEOUT_MILLISECONDS);

            // Make sure we're using the default number of retries
            SendwithusClient.RetryCount = SendwithusClient.DEFAULT_RETRY_COUNT;

            // Send a PUT request
            try
            {
                var setDefaultEspAccountResponse = await EspAccount.SetDefaultEspAccountAsync(DEFAULT_ESP_ACCOUNT_ID);
            }
            catch (Exception ex)
            {
                SendwithusClientTest.ValidateAggregateException <TaskCanceledException>(SendwithusClient.DEFAULT_RETRY_COUNT, ex);
            }
            finally
            {
                // Set the timeout back to its default value
                SendwithusClient.SetTimeoutInMilliseconds(SendwithusClient.DEFAULT_TIMEOUT_MILLISECONDS);
            }
        }
Example #7
0
        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.GetLogsAsync();                                                     // GET

                await EspAccount.SetDefaultEspAccountAsync(DEFAULT_ESP_ACCOUNT_ID);           // PUT

                await EmailTest.BuildAndSendEmailWithAllParametersAsync();                    // POST

                await DripCampaign.GetDripCampaignsAsync();                                   // GET

                await CustomerTest.BuildAndSendCreateCustomerRequest();                       // POST

                await Customer.DeleteCustomerAsync(CustomerTest.NEW_CUSTOMER_EMAIL_ADDRESS);  // DELETE

                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 <EspAccountResponse>(batchResponses[5]);
                ValidateIndividualBatchedApiCallResponse <EmailResponse>(batchResponses[6]);
                ValidateIndividualBatchedApiCallResponse <List <DripCampaignDetails> >(batchResponses[7]);
                ValidateIndividualBatchedApiCallResponse <GenericApiCallStatus>(batchResponses[8]);
                ValidateIndividualBatchedApiCallResponse <GenericApiCallStatus>(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();
            }
        }
Example #8
0
        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.GetLogsAsync();                                                     // GET

                await EspAccount.SetDefaultEspAccountAsync(DEFAULT_ESP_ACCOUNT_ID);           // PUT

                await EmailTest.BuildAndSendEmailWithAllParametersAsync();                    // POST

                await DripCampaign.GetDripCampaignsAsync();                                   // GET

                await CustomerTest.BuildAndSendCreateCustomerRequest();                       // POST

                await Customer.DeleteCustomerAsync(CustomerTest.NEW_CUSTOMER_EMAIL_ADDRESS);  // DELETE

                // 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]);
                ValidateIndividualBatchedApiCallResponse <List <Log> >(batchResponses[4]);
                ValidateIndividualBatchedApiCallResponse <EspAccountResponse>(batchResponses[5]);
                ValidateIndividualBatchedApiCallResponse <EmailResponse>(batchResponses[6]);
                ValidateIndividualBatchedApiCallResponse <List <DripCampaignDetails> >(batchResponses[7]);
                ValidateIndividualBatchedApiCallResponse <GenericApiCallStatus>(batchResponses[8]);
                ValidateIndividualBatchedApiCallResponse <GenericApiCallStatus>(batchResponses[9]);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }