summaryrefslogtreecommitdiffstats
path: root/SendGrid/UnitTest/UnitTest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'SendGrid/UnitTest/UnitTest.cs')
-rw-r--r--SendGrid/UnitTest/UnitTest.cs62
1 files changed, 62 insertions, 0 deletions
diff --git a/SendGrid/UnitTest/UnitTest.cs b/SendGrid/UnitTest/UnitTest.cs
index 5d1b696..853d59e 100644
--- a/SendGrid/UnitTest/UnitTest.cs
+++ b/SendGrid/UnitTest/UnitTest.cs
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
using NUnit.Framework;
using Newtonsoft.Json.Linq;
using SendGrid;
+using Newtonsoft.Json;
namespace UnitTest
{
@@ -94,4 +95,65 @@ namespace UnitTest
Task.WaitAll(tasks);
}
}
+
+ [TestFixture]
+ public class UnsubscribeGroups
+ {
+ static string _baseUri = "https://api.sendgrid.com/";
+ static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
+ public Client client = new Client(_apiKey, _baseUri);
+ private static string _unsubscribe_groups_key_id = "";
+
+ [Test]
+ public void UnsubscribeGroupsIntegrationTest()
+ {
+ int unsubscribeGroupId = 69;
+
+ TestGet();
+ TestGetUnique(unsubscribeGroupId);
+ TestPost();
+ TestDelete();
+ }
+
+ private void TestGet()
+ {
+ HttpResponseMessage response = client.UnsubscribeGroups.Get().Result;
+ Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
+ string rawString = response.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JsonConvert.DeserializeObject(rawString);
+ Assert.IsNotNull(jsonObject);
+ }
+
+ private void TestGetUnique(int unsubscribeGroupId)
+ {
+ HttpResponseMessage response = client.UnsubscribeGroups.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()
+ {
+ HttpResponseMessage response = client.UnsubscribeGroups.Post("C Sharp Unsubscribes", "Testing the C Sharp Library", false).Result;
+ Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
+ string rawString = response.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ string name = jsonObject.name.ToString();
+ string description = jsonObject.description.ToString();
+ _unsubscribe_groups_key_id = jsonObject.id.ToString();
+ bool is_default = jsonObject.is_default;
+ Assert.IsNotNull(name);
+ Assert.IsNotNull(description);
+ Assert.IsNotNull(_unsubscribe_groups_key_id);
+ Assert.IsNotNull(is_default);
+ }
+
+ private void TestDelete()
+ {
+ HttpResponseMessage response = client.UnsubscribeGroups.Delete(_unsubscribe_groups_key_id).Result;
+ Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
+ }
+
+ }
}