forked from ringcentral/RingCentral.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchGetTest.cs
146 lines (131 loc) · 6.36 KB
/
BatchGetTest.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Linq;
using Xunit;
namespace RingCentral.Tests
{
public class BatchGetTest
{
[Fact]
public async void GetMessages()
{
using (var rc = new RestClient(
Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_ID"),
Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_SECRET"),
Environment.GetEnvironmentVariable("RINGCENTRAL_SERVER_URL")
))
{
await rc.Authorize(
Environment.GetEnvironmentVariable("RINGCENTRAL_USERNAME"),
Environment.GetEnvironmentVariable("RINGCENTRAL_EXTENSION"),
Environment.GetEnvironmentVariable("RINGCENTRAL_PASSWORD")
);
var messages = await rc.Restapi().Account().Extension().MessageStore().List();
var validId1 = messages.records[0].id;
var validId2 = messages.records[1].id;
var invalidId = "7897036116";
var batchResponses = await rc.Restapi().Account().Extension()
.MessageStore($"{validId1},{invalidId},{validId2}").BatchGet();
Assert.Equal(3, batchResponses.Length);
var firstResponse = batchResponses[0];
Assert.Equal(validId1, firstResponse.content.id);
Assert.Equal(200, firstResponse.summary.status);
Assert.Null(firstResponse.error);
Assert.False(firstResponse.summary.isError);
var secondResponse = batchResponses[1];
Assert.True(secondResponse.summary.isError);
Assert.Null(secondResponse.content);
Assert.NotNull(secondResponse.error);
Assert.Equal(404, secondResponse.summary.status);
var thirdResponse = batchResponses[2];
Assert.Equal(validId2, thirdResponse.content.id);
Assert.Equal(200, thirdResponse.summary.status);
Assert.Null(thirdResponse.error);
Assert.False(thirdResponse.summary.isError);
}
}
[Fact]
public async void GetCallLogs()
{
using (var rc = new RestClient(
Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_ID"),
Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_SECRET"),
Environment.GetEnvironmentVariable("RINGCENTRAL_SERVER_URL")
))
{
await rc.Authorize(
Environment.GetEnvironmentVariable("RINGCENTRAL_USERNAME"),
Environment.GetEnvironmentVariable("RINGCENTRAL_EXTENSION"),
Environment.GetEnvironmentVariable("RINGCENTRAL_PASSWORD")
);
var callLogsResponse = await rc.Restapi().Account().Extension().CallLog()
.List(new ReadUserCallLogParameters
{perPage = 3, dateFrom = DateTime.UtcNow.AddYears(-1).ToString("O")});
var callLogIds = string.Join(',', callLogsResponse.records.Select(r => r.id));
var batchResponses = await rc.Restapi().Account().Extension().CallLog(callLogIds).BatchGet();
Assert.Equal(3, batchResponses.Length);
var callLog = batchResponses[0].content;
Assert.NotNull(callLog);
Assert.NotNull(callLog.id);
Assert.Equal(callLogIds, string.Join(',', batchResponses.Select(br => br.content.id)));
}
}
[Fact]
public async void GetCallLogs2()
{
using (var rc = new RestClient(
Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_ID"),
Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_SECRET"),
Environment.GetEnvironmentVariable("RINGCENTRAL_SERVER_URL")
))
{
await rc.Authorize(
Environment.GetEnvironmentVariable("RINGCENTRAL_USERNAME"),
Environment.GetEnvironmentVariable("RINGCENTRAL_EXTENSION"),
Environment.GetEnvironmentVariable("RINGCENTRAL_PASSWORD")
);
var callLogsResponse = await rc.Restapi().Account().Extension().CallLog()
.List(new ReadUserCallLogParameters
{perPage = 3, dateFrom = DateTime.UtcNow.AddYears(-3).ToString("O")});
var callLogIds = string.Join(',', callLogsResponse.records.Select(r => r.id));
var batchResponses =
await rc.BatchGet<UserCallLogRecord>(rc.Restapi().Account().Extension().CallLog(callLogIds).Path());
Assert.Equal(3, batchResponses.Length);
Assert.Equal(callLogIds, string.Join(',', batchResponses.Select(br => br.content.id)));
}
}
[Fact]
public async void OnlyOneId()
{
using (var rc = new RestClient(
Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_ID"),
Environment.GetEnvironmentVariable("RINGCENTRAL_CLIENT_SECRET"),
Environment.GetEnvironmentVariable("RINGCENTRAL_SERVER_URL")
))
{
await rc.Authorize(
Environment.GetEnvironmentVariable("RINGCENTRAL_USERNAME"),
Environment.GetEnvironmentVariable("RINGCENTRAL_EXTENSION"),
Environment.GetEnvironmentVariable("RINGCENTRAL_PASSWORD")
);
var callLogsResponse = await rc.Restapi().Account().Extension().CallLog()
.List(new ReadUserCallLogParameters {perPage = 1});
var callLogIds = string.Join(',', callLogsResponse.records.Select(r => r.id));
ArgumentException argumentException = null;
try
{
await rc.BatchGet<UserCallLogRecord>(rc.Restapi().Account().Extension().CallLog(callLogIds)
.Path());
}
catch (ArgumentException ae)
{
argumentException = ae;
}
finally
{
Assert.NotNull(argumentException);
Assert.Contains("should contain multiple IDs", argumentException.Message);
}
}
}
}
}