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 TestNonDefaultRetryInterval() { // Set the timeout low enough that the API call is guaranteed to fail and has a negligible effect on the run time SendwithusClient.SetTimeoutInMilliseconds(FAILURE_TIMEOUT_MILLISECONDS); // Make sure we're using the default number of retries //SendwithusClient.RetryCount = SendwithusClient.DEFAULT_RETRY_COUNT; SendwithusClient.RetryCount = NON_DEFAULT_RETRY_COUNT; // Make sure we're using the default retry interval SendwithusClient.RetryIntervalMilliseconds = NON_DEFAULT_RETRY_INTERVAL_MILLISECONDS; // Send a GET request var startTime = Stopwatch.GetTimestamp(); try { var response = await Template.GetTemplateAsync(DEFAULT_TEMPLATE_ID); } catch (Exception ex) { var endTime = Stopwatch.GetTimestamp(); // Make sure the API call failed on a timeout //SendwithusClientTest.ValidateAggregateException<TaskCanceledException>(SendwithusClient.DEFAULT_RETRY_COUNT, ex); SendwithusClientTest.ValidateAggregateException <TaskCanceledException>(NON_DEFAULT_RETRY_COUNT, ex); // Validate the API call's execution time var elapsedTime = endTime - startTime; var elapsedMilliSeconds = elapsedTime * (1000.0 / Stopwatch.Frequency); SendwithusClientTest.ValidateApiCallExecutionTime(elapsedMilliSeconds); } 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; // Set the retry interval back to its default value SendwithusClient.RetryIntervalMilliseconds = SendwithusClient.DEFAULT_RETRY_INTERVAL_MILLISECONDS; } }
public async Task TestTimeoutFailure() { // Set the timeout to a value that is sure to trigger a failure SendwithusClient.SetTimeoutInMilliseconds(FAILURE_TIMEOUT_MILLISECONDS); // Send the GET request try { var response = await Template.GetTemplateAsync(DEFAULT_TEMPLATE_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); } }
public async Task TestDefaultRetryCountWithPostAsync() { // 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 POST request try { var createTemplateResponse = await TemplateTest.BuildAndSendCreateTemplateRequestWithAllParametersAsync(); } 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); } }
public async Task TestDefaultRetryCountWithDeleteAsync() { // 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 DELETE request try { var deleteCustomerReponse = await Customer.DeleteCustomerAsync(CustomerTest.NEW_CUSTOMER_EMAIL_ADDRESS); } 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); } }
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); } }