diff options
author | Elmer Thomas <elmer@thinkingserious.com> | 2015-11-11 19:00:21 -0800 |
---|---|---|
committer | Elmer Thomas <elmer@thinkingserious.com> | 2015-11-11 19:00:38 -0800 |
commit | a1b515989a7c842e12559cefacbdfda0ca57e29f (patch) | |
tree | d9034657480650fce402a76be57579929de1f480 /SendGrid/UnitTest/UnitTest.cs | |
parent | c1551277b840a61e3a62f9c72f7273b496f63f17 (diff) | |
download | sendgrid-csharp-a1b515989a7c842e12559cefacbdfda0ca57e29f.zip sendgrid-csharp-a1b515989a7c842e12559cefacbdfda0ca57e29f.tar.gz sendgrid-csharp-a1b515989a7c842e12559cefacbdfda0ca57e29f.tar.bz2 |
Updating tests
Diffstat (limited to 'SendGrid/UnitTest/UnitTest.cs')
-rw-r--r-- | SendGrid/UnitTest/UnitTest.cs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/SendGrid/UnitTest/UnitTest.cs b/SendGrid/UnitTest/UnitTest.cs new file mode 100644 index 0000000..0b5e2bd --- /dev/null +++ b/SendGrid/UnitTest/UnitTest.cs @@ -0,0 +1,69 @@ +using System; +using System.Net; +using System.Net.Http; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json.Linq; +using SendGrid; + +namespace UnitTest +{ + [TestClass] + public class UnitTest + { + static string _baseUri = "https://api.sendgrid.com/"; + static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); + public Client client = new Client(_apiKey, _baseUri); + private static string _api_key_id = ""; + + [TestMethod] + public void ApiKeysIntegrationTest() + { + TestGet(); + TestPost(); + TestPatch(); + TestDelete(); + } + + private void TestGet() + { + HttpResponseMessage response = client.ApiKeys.Get(); + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + string rawString = response.Content.ReadAsStringAsync().Result; + dynamic jsonObject = JObject.Parse(rawString); + string jsonString = jsonObject.result.ToString(); + Assert.IsNotNull(jsonString); + } + + private void TestPost() + { + HttpResponseMessage response = client.ApiKeys.Post("CSharpTestKey"); + Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); + string rawString = response.Content.ReadAsStringAsync().Result; + dynamic jsonObject = JObject.Parse(rawString); + string api_key = jsonObject.api_key.ToString(); + _api_key_id = jsonObject.api_key_id.ToString(); + string name = jsonObject.name.ToString(); + Assert.IsNotNull(api_key); + Assert.IsNotNull(_api_key_id); + Assert.IsNotNull(name); + } + + private void TestPatch() + { + HttpResponseMessage response = client.ApiKeys.Patch(_api_key_id, "CSharpTestKeyPatched"); + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + string rawString = response.Content.ReadAsStringAsync().Result; + dynamic jsonObject = JObject.Parse(rawString); + _api_key_id = jsonObject.api_key_id.ToString(); + string name = jsonObject.name.ToString(); + Assert.IsNotNull(_api_key_id); + Assert.IsNotNull(name); + } + + private void TestDelete() + { + HttpResponseMessage response = client.ApiKeys.Delete(_api_key_id); + Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); + } + } +} |