|
1 | | -namespace SendGrid.Tests |
| 1 | +using SendGrid.Reliability; |
| 2 | + |
| 3 | +namespace SendGrid.Tests |
2 | 4 | { |
3 | 5 | using Helpers.Mail; |
4 | 6 | using Newtonsoft.Json; |
@@ -6050,21 +6052,32 @@ public void TestJsonNetReferenceHandling(string referenceHandlingProperty) |
6050 | 6052 |
|
6051 | 6053 |
|
6052 | 6054 | [Fact] |
6053 | | - public async Task TestRetryBehaviour() |
| 6055 | + public async Task TestRetryBehaviourThrowsTimeoutException() |
6054 | 6056 | { |
6055 | | - var host = "http://localhost:4010"; |
6056 | | - var headers = new Dictionary<string, string> { { "X-Mock", "200" } }; |
6057 | | - var options = new SendGridClientOptions() { ApiKey = fixture.apiKey, Host = host, RequestHeaders = headers }; |
6058 | | - options.ReliabilitySettings.UseRetryPolicy = true; |
6059 | | - options.ReliabilitySettings.RetryCount = 2; |
6060 | | - var sg = new SendGridClient(options); |
| 6057 | + var msg = new SendGridMessage(); |
| 6058 | + msg.SetFrom(new EmailAddress("[email protected]")); |
| 6059 | + msg.AddTo(new EmailAddress("[email protected]")); |
| 6060 | + msg.SetSubject("Hello World from the SendGrid CSharp Library"); |
| 6061 | + msg.AddContent(MimeType.Html, "HTML content"); |
| 6062 | + |
| 6063 | + var options = new SendGridClientOptions |
| 6064 | + { |
| 6065 | + ApiKey = fixture.apiKey, |
| 6066 | + ReliabilitySettings = {RetryCount = 2} |
| 6067 | + }; |
| 6068 | + |
6061 | 6069 | var id = "test_url_param"; |
6062 | 6070 |
|
6063 | | - var response = await sg.RequestAsync(method: SendGridClient.Method.POST, urlPath: "whitelabel/links/" + id + "/validate"); |
| 6071 | + var httpMessageHandler = new TimeOutExceptionThrowingHttpMessageHandler(20, "The operation timed out"); |
| 6072 | + var retryHandler = new RetryDelegatingHandler(httpMessageHandler, options.ReliabilitySettings); |
| 6073 | + |
| 6074 | + HttpClient clientToInject = new HttpClient(retryHandler); |
| 6075 | + var sg = new SendGridClient(clientToInject, options); |
6064 | 6076 |
|
6065 | | - Assert.True(HttpStatusCode.OK == response.StatusCode); |
6066 | | - } |
| 6077 | + var exception = await Assert.ThrowsAsync<TimeoutException>(() => sg.SendEmailAsync(msg)); |
6067 | 6078 |
|
| 6079 | + Assert.NotNull(exception); |
| 6080 | + } |
6068 | 6081 | } |
6069 | 6082 |
|
6070 | 6083 | public class FakeHttpMessageHandler : HttpMessageHandler |
|
0 commit comments