-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathCancellationTest.cs
67 lines (64 loc) · 1.8 KB
/
CancellationTest.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
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace RingCentral.Tests;
[Collection("Sequential")]
public class CancellationTest
{
[Fact]
public async void CancelAfter()
{
var rc = await ReusableRestClient.GetInstance();
var sendFaxMessageRequest = new CreateFaxMessageRequest
{
to = new[]
{
new FaxReceiver
{
phoneNumber = Environment.GetEnvironmentVariable("RINGCENTRAL_RECEIVER"),
name = "The Receiver"
}
},
attachments = new[]
{
new Attachment
{
filename = "rc.png",
content = File.ReadAllBytes("./rc.png")
},
new Attachment
{
filename = "glip.png",
content = File.ReadAllBytes("./glip.png")
},
new Attachment
{
filename = "hello.txt",
content = Encoding.UTF8.GetBytes("Hello 888")
}
}
};
var source = new CancellationTokenSource();
var token = source.Token;
source.CancelAfter(10); // impossible to send a fax within 10ms
var taskCanceledException = false;
try
{
await rc.Restapi().Account().Extension().Fax().Post(sendFaxMessageRequest, new RestRequestConfig
{
cancellationToken = token
});
}
catch (TaskCanceledException)
{
taskCanceledException = true;
}
finally
{
Assert.True(taskCanceledException);
}
}
}