blob: d614864ad737ab09e93bb12fd4c2316c282c862c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
using System;
using System.Net;
using System.Net.Http;
using NUnit.Framework;
using Newtonsoft.Json.Linq;
using SendGrid;
namespace UnitTest
{
[TestFixture]
public class UnitTest
{
static string _baseUri = "https://api.sendgrid.com/";
static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
public Client client = new Client(_apiKey, _baseUri);
private static string _api_key_id = "";
[Test]
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);
}
}
}
|