diff options
Diffstat (limited to 'SendGrid/UnitTest/UnitTest.cs')
-rw-r--r-- | SendGrid/UnitTest/UnitTest.cs | 120 |
1 files changed, 83 insertions, 37 deletions
diff --git a/SendGrid/UnitTest/UnitTest.cs b/SendGrid/UnitTest/UnitTest.cs index eab3481..4575e3e 100644 --- a/SendGrid/UnitTest/UnitTest.cs +++ b/SendGrid/UnitTest/UnitTest.cs @@ -155,50 +155,96 @@ namespace UnitTest Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); } - [TestFixture] - public class Suppressions + } + + [TestFixture] + public class Suppressions + { + static string _baseUri = "https://api.sendgrid.com/"; + static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); + public Client client = new Client(_apiKey, _baseUri); + + [Test] + public void SuppressionsIntegrationTest() { - static string _baseUri = "https://api.sendgrid.com/"; - static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); - public Client client = new Client(_apiKey, _baseUri); + int unsubscribeGroupId = 69; - [Test] - public void SuppressionsIntegrationTest() - { - int unsubscribeGroupId = 69; + TestGet(unsubscribeGroupId); + string[] emails = { "example@example.com", "example2@example.com" }; + TestPost(unsubscribeGroupId, emails); + TestDelete(unsubscribeGroupId, "example@example.com"); + TestDelete(unsubscribeGroupId, "example2@example.com"); + } - TestGet(unsubscribeGroupId); - string[] emails = { "example@example.com", "example2@example.com" }; - TestPost(unsubscribeGroupId, emails); - TestDelete(unsubscribeGroupId, "example@example.com"); - TestDelete(unsubscribeGroupId, "example2@example.com"); - } + private void TestGet(int unsubscribeGroupId) + { + HttpResponseMessage response = client.Suppressions.Get(unsubscribeGroupId).Result; + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + string rawString = response.Content.ReadAsStringAsync().Result; + dynamic jsonObject = JsonConvert.DeserializeObject(rawString); + Assert.IsNotNull(jsonObject); + } - private void TestGet(int unsubscribeGroupId) - { - HttpResponseMessage response = client.Suppressions.Get(unsubscribeGroupId).Result; - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JsonConvert.DeserializeObject(rawString); - Assert.IsNotNull(jsonObject); - } + private void TestPost(int unsubscribeGroupId, string[] emails) + { + HttpResponseMessage response = client.Suppressions.Post(unsubscribeGroupId, emails).Result; + Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); + string rawString = response.Content.ReadAsStringAsync().Result; + dynamic jsonObject = JObject.Parse(rawString); + string recipient_emails = jsonObject.recipient_emails.ToString(); + Assert.IsNotNull(recipient_emails); + } - private void TestPost(int unsubscribeGroupId, string[] emails) - { - HttpResponseMessage response = client.Suppressions.Post(unsubscribeGroupId, emails).Result; - Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JObject.Parse(rawString); - string recipient_emails = jsonObject.recipient_emails.ToString(); - Assert.IsNotNull(recipient_emails); - } + private void TestDelete(int unsubscribeGroupId, string email) + { + HttpResponseMessage response = client.Suppressions.Delete(unsubscribeGroupId, email).Result; + Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); + } - private void TestDelete(int unsubscribeGroupId, string email) - { - HttpResponseMessage response = client.Suppressions.Delete(unsubscribeGroupId, email).Result; - Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); - } + } + + [TestFixture] + public class GlobalSuppressions + { + static string _baseUri = "https://api.sendgrid.com/"; + static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); + public Client client = new Client(_apiKey, _baseUri); + + [Test] + public void SuppressionsIntegrationTest() + { + string email = "example3@example.com"; + + TestGet(email); + string[] emails = { "example1@example.com", "example2@example.com" }; + TestPost(emails); + TestDelete("example1@example.com"); + TestDelete("example2@example.com"); + } + private void TestGet(string email) + { + HttpResponseMessage response = client.GlobalSuppressions.Get(email).Result; + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + string rawString = response.Content.ReadAsStringAsync().Result; + dynamic jsonObject = JsonConvert.DeserializeObject(rawString); + Assert.IsNotNull(jsonObject); + } + + private void TestPost(string[] emails) + { + HttpResponseMessage response = client.GlobalSuppressions.Post(emails).Result; + Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); + string rawString = response.Content.ReadAsStringAsync().Result; + dynamic jsonObject = JObject.Parse(rawString); + string recipient_emails = jsonObject.recipient_emails.ToString(); + Assert.IsNotNull(recipient_emails); + } + + private void TestDelete(string email) + { + HttpResponseMessage response = client.GlobalSuppressions.Delete(email).Result; + Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); } } |