|
4 | 4 | using Newtonsoft.Json.Linq;
|
5 | 5 | using RichardSzalay.MockHttp;
|
6 | 6 | using System;
|
| 7 | +using System.Net; |
7 | 8 | using sms = Mailjet.Client.Resources.SMS;
|
8 | 9 |
|
9 | 10 | namespace Mailjet.Tests
|
@@ -69,6 +70,50 @@ public void TestGetAsync()
|
69 | 70 | Assert.IsTrue(JToken.DeepEquals(expectedData, response.GetData()));
|
70 | 71 | }
|
71 | 72 |
|
| 73 | + [TestMethod] |
| 74 | + public void TestTooManyRequestsStatus() |
| 75 | + { |
| 76 | + var mockHttp = new MockHttpMessageHandler(); |
| 77 | + mockHttp.When("https://api.mailjet.com/v3/*") |
| 78 | + .Respond(((HttpStatusCode) 429)); |
| 79 | + |
| 80 | + // Inject the handler into your application code |
| 81 | + IMailjetClient client = new MailjetClient(ApiKeyTest, ApiSecretTest, mockHttp); |
| 82 | + |
| 83 | + MailjetRequest request = new MailjetRequest |
| 84 | + { |
| 85 | + Resource = Apikey.Resource, |
| 86 | + }; |
| 87 | + |
| 88 | + MailjetResponse response = client.GetAsync(request).Result; |
| 89 | + |
| 90 | + Assert.AreEqual(429, response.StatusCode); |
| 91 | + Assert.AreEqual("Too many requests", response.GetErrorInfo()); |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + [TestMethod] |
| 96 | + public void TestInternalServerErrorStatus() |
| 97 | + { |
| 98 | + var mockHttp = new MockHttpMessageHandler(); |
| 99 | + mockHttp.When("https://api.mailjet.com/v3/*") |
| 100 | + .Respond(HttpStatusCode.InternalServerError); |
| 101 | + |
| 102 | + |
| 103 | + // Inject the handler into your application code |
| 104 | + IMailjetClient client = new MailjetClient(ApiKeyTest, ApiSecretTest, mockHttp); |
| 105 | + |
| 106 | + MailjetRequest request = new MailjetRequest |
| 107 | + { |
| 108 | + Resource = Apikey.Resource, |
| 109 | + }; |
| 110 | + |
| 111 | + MailjetResponse response = client.GetAsync(request).Result; |
| 112 | + |
| 113 | + Assert.AreEqual(500, response.StatusCode); |
| 114 | + Assert.AreEqual("Internal Server Error", response.GetErrorInfo()); |
| 115 | + } |
| 116 | + |
72 | 117 | [TestMethod]
|
73 | 118 | public void TestSmsCountAsync()
|
74 | 119 | {
|
|
0 commit comments