Ejemplo n.º 1
0
        public async Task TestGetTemplatesWithInvalidApiKeyAsync()
        {
            Trace.WriteLine(String.Format("GET /templates with invalid API Key: {0}", INVALID_API_KEY));

            // Set the API Key to an invalid key and save the original key
            var originalApiKey = SendwithusClient.ApiKey;

            SendwithusClient.ApiKey = INVALID_API_KEY;

            // Make the API call
            try
            {
                var templates = await Template.GetTemplatesAsync();
            }
            catch (AggregateException exception)
            {
                // Make sure the response was HTTP 403 Forbidden
                SendwithusClientTest.ValidateException(exception, HttpStatusCode.Forbidden);
            }
            finally
            {
                // Set the API Key back to its original value
                SendwithusClient.ApiKey = originalApiKey;
            }
        }
Ejemplo n.º 2
0
        public async Task TestAddLocaleToTemplateWithAllParmetersAsync()
        {
            // Create a new template to add a locale to
            // Otherwise, if an existing template were used, this test might fail because the new locale could already exist on the template
            var newTemplate = await BuildAndSendCreateTemplateRequestWithAllParametersAsync();

            var templateId = newTemplate.id;

            // Make the API call
            Trace.WriteLine(String.Format("POST /templates/{0}/locales", templateId));
            var templateVersionName    = "Published French Version";
            var templateSubject        = "Ce est un nouveau modèle!";
            var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject);

            updatedTemplateVersion.html      = "<html><head></head><body><h1>Nouveau modèle!</h1></body></html>";
            updatedTemplateVersion.text      = "un texte";
            updatedTemplateVersion.preheader = "A French Preheader";

            try
            {
                var template = await Template.AddLocaleToTemplate(templateId, ALTERNATE_LOCALE, updatedTemplateVersion);

                // Validate the response
                SendwithusClientTest.ValidateResponse(template);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 3
0
        public async Task TestGetLogsWithAllParametersAsync()
        {
            Trace.WriteLine("GET /logs");

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

            queryParameters.Add("count", DEFAULT_COUNT);
            queryParameters.Add("offset", DEFAULT_OFFSET);
            queryParameters.Add("created_gt", LOG_CREATED_AFTER_TIME);
            queryParameters.Add("created_gte", LOG_CREATED_AFTER_TIME);
            queryParameters.Add("created_lt", LOG_CREATED_BEFORE_TIME);
            queryParameters.Add("created_lte", LOG_CREATED_BEFORE_TIME);

            // Make the API call
            try
            {
                var logs = await Log.GetLogsAsync(queryParameters);

                // Validate the response
                SendwithusClientTest.ValidateResponse(logs);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 4
0
        public async Task TestActivateDripCampaignAsyncWithAllParameters()
        {
            Trace.WriteLine(String.Format("POST /drip_campaigns/{0}/activate with all parameters", DEFAULT_CAMPAIGN_ID));

            // Build the drip campaign object
            var recipient    = new EmailRecipient(DEFAULT_RECIPIENT_EMAIL_ADDRESS, DEFAULT_EMAIL_NAME);
            var dripCampaign = new DripCampaign(recipient);

            dripCampaign.cc.Add(new EmailRecipient(DEFAULT_CC_EMAIL_ADDRESS_1, DEFAULT_EMAIL_NAME));
            dripCampaign.cc.Add(new EmailRecipient(DEFAULT_CC_EMAIL_ADDRESS_2, DEFAULT_EMAIL_NAME));
            dripCampaign.bcc.Add(new EmailRecipient(DEFAULT_BCC_EMAIL_ADDRESS_1, DEFAULT_EMAIL_NAME));
            dripCampaign.bcc.Add(new EmailRecipient(DEFAULT_BCC_EMAIL_ADDRESS_2, DEFAULT_EMAIL_NAME));
            dripCampaign.sender.address  = DEFAULT_SENDER_EMAIL_ADDRESS;
            dripCampaign.sender.name     = DEFAULT_SENDER_NAME;
            dripCampaign.sender.reply_to = DEFAULT_REPLY_TO_EMAIL_ADDRESS;
            dripCampaign.tags.Add(DEFAULT_TAG_1);
            dripCampaign.tags.Add(DEFAULT_TAG_2);
            dripCampaign.tags.Add(DEFAULT_TAG_3);
            dripCampaign.locale      = DEFAULT_LOCALE;
            dripCampaign.esp_account = DEFAULT_ESP_ACCOUNT_ID;
            dripCampaign.email_data.Add("amount", "$12.00");

            // Make the API call
            try
            {
                var dripCampaignResponse = await dripCampaign.ActivateAsync(DEFAULT_CAMPAIGN_ID);

                // Validate the response
                SendwithusClientTest.ValidateResponse(dripCampaignResponse);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 5
0
        public async Task TestNonDefaultRetryCountAsync()
        {
            // Set the timeout low enough that the API call is guaranteed to fail
            SendwithusClient.SetTimeoutInMilliseconds(FAILURE_TIMEOUT_MILLISECONDS);

            // Use a non-default number of retries
            SendwithusClient.RetryCount = NON_DEFAULT_RETRY_COUNT;

            // Send a GET request
            try
            {
                var response = await Template.GetTemplateAsync(DEFAULT_TEMPLATE_ID);
            }
            catch (Exception ex)
            {
                SendwithusClientTest.ValidateAggregateException <TaskCanceledException>(NON_DEFAULT_RETRY_COUNT, ex);
            }
            finally
            {
                // Set the timeout back to its default value
                SendwithusClient.SetTimeoutInMilliseconds(SendwithusClient.DEFAULT_TIMEOUT_MILLISECONDS);

                // Set the retry count back to its default value
                SendwithusClient.RetryCount = SendwithusClient.DEFAULT_RETRY_COUNT;
            }
        }
        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());
            }
        }
        /// <summary>
        /// Validates a batch API call response
        /// Makes sure the reponse is not null, and checks the number of API responses against the number that were expected
        /// </summary>
        /// <param name="responses">The collection of BatchApiResponses from the batch API call</param>
        /// <param name="expectedResponseCount">The expected number of BatchApiResponse</param>
        private void ValidateBatchApiCallResponses(List <BatchApiResponse> responses, int expectedResponseCount)
        {
            // Standard validation of the response (make sure the response isn't null)
            SendwithusClientTest.ValidateResponse(responses);

            // Make sure we received the expected number of batch API responses
            Assert.AreEqual(expectedResponseCount, responses.Count);
        }
Ejemplo n.º 8
0
        public async Task TestGetCustomerWithInvalidEmailAddressAsync()
        {
            // Make the API call
            Trace.WriteLine(String.Format("GET /customers/{0}", INVALID_CUSTOMER_EMAIL_ADDRESS));
            try
            {
                var customerResponse = await Customer.GetCustomerAsync(INVALID_CUSTOMER_EMAIL_ADDRESS);

                Assert.Fail("Failed to throw exception");
            }
            catch (AggregateException exception)
            {
                // Make sure the response was HTTP 400 Bad Request
                SendwithusClientTest.ValidateException(exception, HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 9
0
        public async Task TestGetCustomerAsync()
        {
            // Make the API call
            Trace.WriteLine(String.Format("GET /customers/{0}", DEFAULT_CUSTOMER_EMAIL_ADDRESS));
            try
            {
                var customerResponse = await Customer.GetCustomerAsync(DEFAULT_CUSTOMER_EMAIL_ADDRESS);

                // Validate the response
                SendwithusClientTest.ValidateResponse(customerResponse);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 10
0
        public async Task TestGetTemplateByIdAndLocaleInvalidLocaleAsync()
        {
            // Make the API call
            Trace.WriteLine(String.Format("GET /templates/{0}/locales/{1} with invalid locale", DEFAULT_TEMPLATE_ID, INVALID_LOCALE));
            try
            {
                var template = await Template.GetTemplateAsync(DEFAULT_TEMPLATE_ID, INVALID_LOCALE);

                Assert.Fail("Failed to throw exception");
            }
            catch (AggregateException exception)
            {
                // Make sure the response was HTTP 400 Bad Request
                SendwithusClientTest.ValidateException(exception, HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 11
0
        public async Task TestCreateTemplateWithAllParametersAsync()
        {
            // Make the API call
            Trace.WriteLine(String.Format("PUT /templates/"));
            try
            {
                var template = await BuildAndSendCreateTemplateRequestWithAllParametersAsync();

                // Validate the response
                SendwithusClientTest.ValidateResponse(template);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 12
0
        public async Task TestGetTemplateByIdAsync()
        {
            // Make the API call
            Trace.WriteLine(String.Format("GET /templates/{0}", DEFAULT_TEMPLATE_ID));
            try
            {
                var template = await Template.GetTemplateAsync(DEFAULT_TEMPLATE_ID);

                // Validate the response
                SendwithusClientTest.ValidateResponse(template);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 13
0
        public async Task TestGetTemplatesAsync()
        {
            // Make the API call
            Trace.WriteLine("GET /templates");
            try
            {
                var templates = await Template.GetTemplatesAsync();

                // Validate the response
                SendwithusClientTest.ValidateResponse(templates);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 14
0
        public async Task TestGetTemplateVersionByIdAndLocaleAsync()
        {
            // Make the API call
            Trace.WriteLine(String.Format("GET /templates/{0}/locales/{1}/versions/{2}", DEFAULT_TEMPLATE_ID, DEFAULT_LOCALE, DEFAULT_VERSION_ID));
            try
            {
                var templateVersion = await Template.GetTemplateVersionAsync(DEFAULT_TEMPLATE_ID, DEFAULT_LOCALE, DEFAULT_VERSION_ID);

                // Validate the response
                SendwithusClientTest.ValidateResponse(templateVersion);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 15
0
        public async Task TestGetDripCampaignsAsync()
        {
            Trace.WriteLine("GET /drip_campaigns");

            // Make the API call
            try
            {
                var dripCampaignDetails = await DripCampaign.GetDripCampaignsAsync();

                // Validate the response
                SendwithusClientTest.ValidateResponse(dripCampaignDetails);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 16
0
        public async Task TestDeactivateFromAllDripCampaignsAsync()
        {
            Trace.WriteLine(String.Format("POST /drip_campaigns/{0}/deactivate", DEFAULT_CAMPAIGN_ID));

            // Make the API call
            try
            {
                var dripCampaignDeactivateResponse = await DripCampaign.DeactivateFromAllCampaignsAsync(DEFAULT_RECIPIENT_EMAIL_ADDRESS);

                // Validate the response
                SendwithusClientTest.ValidateResponse(dripCampaignDeactivateResponse);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 17
0
        public async Task TestCreateOrUpdateCustomerWithAllParametersAsync()
        {
            Trace.WriteLine("POST /customers");

            // Build the new customer and send the create customer request
            try
            {
                var genericApiCallStatus = await BuildAndSendCreateCustomerRequest();

                // Validate the response
                SendwithusClientTest.ValidateResponse(genericApiCallStatus);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 18
0
        public async Task TestDeleteCustomerAsync()
        {
            Trace.WriteLine(String.Format("DELETE /customers", NEW_CUSTOMER_EMAIL_ADDRESS));

            // Make the API call
            try
            {
                var genericApiCallStatus = await Customer.DeleteCustomerAsync(NEW_CUSTOMER_EMAIL_ADDRESS);

                // Validate the response
                SendwithusClientTest.ValidateResponse(genericApiCallStatus);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 19
0
        public async Task TestGetLogsWithNoParametersAsync()
        {
            Trace.WriteLine("GET /logs");

            // Make the API call
            try
            {
                var logs = await Log.GetLogsAsync();

                // Validate the response
                SendwithusClientTest.ValidateResponse(logs);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 20
0
        public async Task TestGetSnippetsAsync()
        {
            Trace.WriteLine("GET /snippets");

            // Make the API call
            try
            {
                var snippets = await Snippet.GetSnippetsAsync();

                // Validate the response
                SendwithusClientTest.ValidateResponse(snippets);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 21
0
        public async Task TestGetSnippetAsync()
        {
            Trace.WriteLine(String.Format("GET /snippets/{0}", DEFAULT_SNIPPET_ID));

            // Make the API call
            try
            {
                var snippet = await Snippet.GetSnippetAsync(DEFAULT_SNIPPET_ID);

                // Validate the response
                SendwithusClientTest.ValidateResponse(snippet);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 22
0
        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());
            }
        }
Ejemplo n.º 23
0
        public async Task TestGetDripCampaignAsync()
        {
            Trace.WriteLine(String.Format("GET /drip_campaigns/{0}", DEFAULT_CAMPAIGN_ID));

            // Make the API call
            try
            {
                var response = await DripCampaign.GetDripCampaignAsync(DEFAULT_CAMPAIGN_ID);

                // Validate the response
                SendwithusClientTest.ValidateResponse(response);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 24
0
        public async Task TestGetSnippetWithInvalidIDAsync()
        {
            Trace.WriteLine("GET /snippets with an invalid ID");

            // Make the API call
            try
            {
                var snippet = await Snippet.GetSnippetAsync(INVALID_SNIPPET_ID);

                Assert.Fail("Failed to throw exception");
            }
            catch (AggregateException exception)
            {
                // Make sure the response was HTTP 400 Bad Request
                SendwithusClientTest.ValidateException(exception, HttpStatusCode.BadRequest);
            }
        }
Ejemplo n.º 25
0
        public async Task TestResendLogAsync()
        {
            Trace.WriteLine("POST /resend");

            // Make the API call
            try
            {
                var logResendResponse = await Log.ResendLogAsync(DEFAULT_LOG_ID);

                // Validate the response
                SendwithusClientTest.ValidateResponse(logResendResponse);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 26
0
        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());
            }
        }
Ejemplo n.º 27
0
        public async Task TestGetLogEventsAsync()
        {
            Trace.WriteLine(String.Format("GET /logs/{0}/events", DEFAULT_LOG_ID));

            // Make the API call
            try
            {
                var logEvents = await Log.GetLogEventsAsync(DEFAULT_LOG_ID);

                // Validate the response
                SendwithusClientTest.ValidateResponse(logEvents);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 28
0
        public async Task TestRenderTemplateWithAllParametersNameAsync()
        {
            Trace.WriteLine("POST /render");

            // Make the API call
            try
            {
                var renderTemplateResponse = await BuildAndSendRenderTemplateRequestWithAllParametersName();

                // Validate the response
                SendwithusClientTest.ValidateResponse(renderTemplateResponse);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 29
0
        public async Task TestSendEmailWithAllParametersAsync()
        {
            Trace.WriteLine("POST /send");

            // Construct and send an email with all of the optional data
            try
            {
                var response = await BuildAndSendEmailWithAllParametersAsync();

                // Validate the response
                SendwithusClientTest.ValidateResponse(response);
            }
            catch (AggregateException exception)
            {
                Assert.Fail(exception.ToString());
            }
        }
Ejemplo n.º 30
0
        public async Task TestActivateDripCampaignWithInvalidParameters()
        {
            Trace.WriteLine(String.Format("POST /drip_campaigns/{0}/activate with invalid campaign ID", INVALID_CAMPAIGN_ID));

            // Build the drip campaign object
            var recipient    = new EmailRecipient(DEFAULT_RECIPIENT_EMAIL_ADDRESS);
            var dripCampaign = new DripCampaign(recipient);

            // Make the API call
            try {
                var response = await dripCampaign.ActivateAsync(INVALID_CAMPAIGN_ID);
            }
            catch (AggregateException exception)
            {
                // Make sure the response was HTTP 400 Bad Request
                SendwithusClientTest.ValidateException(exception, HttpStatusCode.BadRequest);
            }
        }