-
Notifications
You must be signed in to change notification settings - Fork 584
/
Copy pathResponseTests.cs
68 lines (60 loc) · 2.87 KB
/
ResponseTests.cs
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
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
namespace SendGrid.Tests
{
public class ResponseTests
{
[Fact]
public async Task DeserializeResponseBodyAsync_NullHttpContent_ReturnsEmptyDictionary()
{
var response = new Response(HttpStatusCode.OK, null, null);
Dictionary<string, dynamic> responseBody = await response.DeserializeResponseBodyAsync();
Assert.Empty(responseBody);
}
[Fact]
public async Task DeserializeResponseBodyAsync_JsonHttpContent_ReturnsBodyAsDictionary()
{
var content = "{\"scopes\": [\"alerts.read\"]}";
var response = new Response(HttpStatusCode.OK, new StringContent(content), null);
Dictionary<string, dynamic> responseBody = await response.DeserializeResponseBodyAsync();
Assert.Equal(new JArray() { "alerts.read" }, responseBody["scopes"]);
}
[Fact]
public async Task DeserializeResponseBodyAsync_OverrideHttpContent_ReturnsBodyAsDictionary()
{
var content = "{\"scopes\": [\"alerts.read\"]}";
var response = new Response(HttpStatusCode.OK, null, null);
Dictionary<string, dynamic> responseBody = await response.DeserializeResponseBodyAsync(new StringContent(content));
Assert.Equal(new JArray() { "alerts.read" }, responseBody["scopes"]);
}
[Fact]
public void DeserializeResponseHeaders_NullHttpResponseHeaders_ReturnsEmptyDictionary()
{
var response = new Response(HttpStatusCode.OK, null, null);
Dictionary<string, string> responseHeadersDeserialized = response.DeserializeResponseHeaders();
Assert.Empty(responseHeadersDeserialized);
}
[Fact]
public void DeserializeResponseHeaders_HttpResponseHeaders_ReturnsHeadersAsDictionary()
{
var message = new HttpResponseMessage();
message.Headers.Add("HeaderKey", "HeaderValue");
var response = new Response(HttpStatusCode.OK, null, message.Headers);
Dictionary<string, string> responseHeadersDeserialized = response.DeserializeResponseHeaders();
Assert.Equal("HeaderValue", responseHeadersDeserialized["HeaderKey"]);
}
[Fact]
public void DeserializeResponseHeaders_OverrideHttpResponseHeaders_ReturnsHeadersAsDictionary()
{
var message = new HttpResponseMessage();
message.Headers.Add("HeaderKey", "HeaderValue");
var response = new Response(HttpStatusCode.OK, null, null);
Dictionary<string, string> responseHeadersDeserialized = response.DeserializeResponseHeaders(message.Headers);
Assert.Equal("HeaderValue", responseHeadersDeserialized["HeaderKey"]);
}
}
}