forked from ringcentral/ringcentral-csharp-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BinaryTest.cs
102 lines (87 loc) · 3.53 KB
/
BinaryTest.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
using System;
using System.Linq;
using System.Threading;
using Xunit;
namespace RingCentral.Test
{
[Collection("RestClient collection")]
public class BinaryTest : IDisposable
{
private RestClient rc;
private byte[] bytes;
public BinaryTest(RestClientFixture fixture)
{
rc = fixture.rc;
bytes = System.IO.File.ReadAllBytes("test.png");
}
[Fact]
public async void ProfileImage()
{
var extension = rc.Restapi().Account().Extension();
var temp = await extension.ProfileImage().Post(bytes, "test.png");
Assert.True(temp);
var content = await extension.ProfileImage().Get();
Assert.NotNull(content);
Assert.Equal(bytes, content.data);
var bytes4 = await extension.ProfileImage("90x90").Get();
Assert.NotNull(bytes4);
temp = await extension.ProfileImage().Put(bytes, "test.png");
Assert.True(temp);
content = await extension.ProfileImage().Get();
Assert.NotNull(content);
Assert.Equal(bytes, content.data);
var bytes6 = await extension.ProfileImage("90x90").Get();
Assert.NotNull(bytes6);
}
[Fact]
public async void MessageContent()
{
var extension = rc.Restapi().Account().Extension();
var response = await extension.MessageStore().List(new { dateFrom = DateTime.UtcNow.AddDays(-30).ToString("o") });
var messages = response.records;
// sms
var message = messages.Where(m => m.type == "SMS" && m.attachments != null && m.attachments.Length > 0).First();
var content = await extension.MessageStore(message.id).Content(message.attachments[0].id).Get();
var str = System.Text.Encoding.UTF8.GetString(content.data);
Assert.NotNull(str);
Assert.True(str.Length > 0);
// fax
message = messages.Where(m => m.type == "Fax" && m.messageStatus != "SendingFailed" && m.attachments != null && m.attachments.Length > 0).Skip(3).First();
content = await extension.MessageStore(message.id).Content(message.attachments[0].id).Get();
Assert.NotNull(content);
Assert.True(content.data.Length > 0);
System.IO.File.WriteAllBytes("test.pdf", content.data);
}
[Fact]
public async void RecordingContent()
{
var account = rc.Restapi().Account();
// List call Logs
var queryParams = new CallLogPath.ListParameters
{
type = new string[] { "Voice" },
view = "Detailed",
dateFrom = DateTime.UtcNow.AddDays(-365).ToString("o"),
withRecording = true,
perPage = 10,
};
var callLogs = await account.CallLog().List(queryParams);
if (callLogs.records.Length > 0)
{
// download a call recording
var callLog = callLogs.records[0];
if (callLog.recording != null)
{
var content = await account.Recording(callLog.recording.id).Content().Get();
Assert.NotNull(content);
Assert.True(content.data.Length > 0);
System.IO.File.WriteAllBytes("test.wav", content.data);
}
}
}
public void Dispose()
{
Thread.Sleep(100);
}
}
}