-
Notifications
You must be signed in to change notification settings - Fork 25
/
LowLevelApiTest.cs
50 lines (42 loc) · 1.75 KB
/
LowLevelApiTest.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
using System.Net;
using System.Net.Http;
using Newtonsoft.Json;
using Xunit;
namespace RingCentral.Tests;
[Collection("Sequential")]
public class LowLevelApiTest
{
[Fact]
public async void DifferentResponseTypes()
{
var rc = await ReusableRestClient.GetInstance();
// return a definition type
var country = await rc.Get<CountryInfoDictionaryModel>("/restapi/v1.0/dictionary/country/46");
Assert.Equal("China", country.name);
// return a string
var str = await rc.Get<string>("/restapi/v1.0/dictionary/country/46");
Assert.Contains("China", str);
// return HttpResponseMessage
var responseMessage = await rc.Get<HttpResponseMessage>("/restapi/v1.0/dictionary/country/46");
Assert.Equal(HttpStatusCode.OK, responseMessage.StatusCode);
// non-generic version
var responseMessage2 = await rc.Get("/restapi/v1.0/dictionary/country/46");
Assert.Equal(HttpStatusCode.OK, responseMessage2.StatusCode);
}
[Fact]
public async void GetExtensionInfo()
{
var rc = await ReusableRestClient.GetInstance();
// normal way to get extension info
var extInfo = await rc.Restapi().Account().Extension().Get();
Assert.NotNull(extInfo.id);
// low level way to get extension info + headers info
var httpResponseMessage = await rc.Get(rc.Restapi().Account().Extension().Path());
var headers = httpResponseMessage.Headers;
Assert.NotNull(headers);
var responseBodyStr = await httpResponseMessage.Content.ReadAsStringAsync();
Assert.NotNull(responseBodyStr);
extInfo = JsonConvert.DeserializeObject<GetExtensionInfoResponse>(responseBodyStr);
Assert.NotNull(extInfo.id);
}
}