-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathWebSocketTest.cs
44 lines (41 loc) · 1.77 KB
/
WebSocketTest.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
using System.Threading.Tasks;
using RingCentral.Net.WebSocket;
using Xunit;
namespace RingCentral.Tests;
[Collection("Sequential")]
public class WebSocketTest
{
[Fact]
public async void SendAndReceive()
{
var rc = await ReusableRestClient.GetInstance();
var webSocketExtension = new WebSocketExtension(new WebSocketOptions { debugMode = true });
await rc.InstallExtension(webSocketExtension);
var eventFilters = new[] { "/restapi/v1.0/account/~/extension/~/message-store" };
var count = 0;
await webSocketExtension.Subscribe(eventFilters, message => { count += 1; });
var extInfo = await rc.Restapi().Account().Extension().Get();
await rc.Restapi().Account().Extension().CompanyPager().Post(new CreateInternalTextMessageRequest
{
from = new PagerCallerInfoRequest { extensionNumber = extInfo.extensionNumber },
to = new[] { new PagerCallerInfoRequest { extensionNumber = extInfo.extensionNumber } },
text = "Hello world"
});
await Task.Delay(20000);
Assert.True(count > 0);
webSocketExtension.enabled = false;
}
[Fact]
public async void RevokeSubscription()
{
var rc = await ReusableRestClient.GetInstance();
var webSocketExtension = new WebSocketExtension(new WebSocketOptions { debugMode = true });
await rc.InstallExtension(webSocketExtension);
var eventFilters = new[] { "/restapi/v1.0/account/~/extension/~/message-store" };
var subscription = await webSocketExtension.Subscribe(eventFilters, message => { });
webSocketExtension.RawMessageReceived += (sender, s) => { };
await Task.Delay(5000);
await subscription.Revoke();
webSocketExtension.enabled = false;
}
}