-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathBatchGetTest.cs
109 lines (93 loc) · 4.09 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
using System;
using System.Linq;
using Xunit;
namespace RingCentral.Tests;
[Collection("Sequential")]
public class BatchGetTest
{
[Fact]
public async void GetMessages()
{
var rc = await ReusableRestClient.GetInstance();
var messages = await rc.Restapi().Account().Extension().MessageStore().List(new ListMessagesParameters
{
dateFrom = DateTime.UtcNow.AddDays(-365).ToString("O")
});
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();
var batchResponses = await rc.BatchGet<GetMessageInfoResponse>(rc.Restapi().Account().Extension()
.MessageStore($"{validId1},{invalidId},{validId2}").Path());
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()
{
var rc = await ReusableRestClient.GetInstance();
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();
var batchResponses =
await rc.BatchGet<CallLogRecord>(rc.Restapi().Account().Extension().CallLog(callLogIds).Path());
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()
{
var rc = await ReusableRestClient.GetInstance();
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<CallLogRecord>(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()
{
var rc = await ReusableRestClient.GetInstance();
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<CallLogRecord>(rc.Restapi().Account().Extension().CallLog(callLogIds)
.Path());
}
catch (ArgumentException ae)
{
argumentException = ae;
}
finally
{
Assert.NotNull(argumentException);
Assert.Contains("should contain multiple IDs", argumentException.Message);
}
}
}