forked from sgrassie/csharp-github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiscTests.cs
More file actions
62 lines (50 loc) · 1.61 KB
/
MiscTests.cs
File metadata and controls
62 lines (50 loc) · 1.61 KB
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
namespace GitHubAPI.Tests
{
using NUnit.Framework;
using RestSharp;
using RestSharp.Deserializers;
[TestFixture]
public class MiscTests
{
[Test]
public void DynamicResponse_WithCustomDeserializer()
{
var restRequest = new RestRequest
{
Resource = "/users/sgrassie"
};
var client = new RestClient
{
BaseUrl = "https://api.github.com"
};
client.AddHandler("application/json", new DynamicJsonDeserializer());
dynamic response = client.Execute<dynamic>(restRequest);
NUnit.Framework.Assert.That(response.Data["login"], Is.StringMatching("sgrassie"));
}
[Test]
public void DynamicReponse_WithExtensionMethod()
{
var restRequest = new RestRequest
{
Resource = "/users/sgrassie"
};
var client = new RestClient
{
BaseUrl = "https://api.github.com"
};
var response = client.Execute(restRequest);
var dynamicPart = response.Dynamic();
NUnit.Framework.Assert.That(dynamicPart.login, Is.StringMatching("sgrassie"));
}
}
public class DynamicJsonDeserializer : IDeserializer
{
public string RootElement { get; set; }
public string Namespace { get; set; }
public string DateFormat { get; set; }
public T Deserialize<T>(IRestResponse response)
{
return (T)SimpleJson.DeserializeObject(response.Content);
}
}
}