forked from ringcentral/RingCentral.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserAgentTest.cs
49 lines (42 loc) · 1.68 KB
/
UserAgentTest.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
using System;
using System.Linq;
using RingCentral.Net.Events;
using Xunit;
namespace RingCentral.Tests
{
public class UserAgentTest
{
[Fact]
public async void AfterCall()
{
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 eventsExtension = new EventsExtension();
rc.InstallExtension(eventsExtension);
var count = 0;
void EventHandler(object sender, HttpMessages httpMessages)
{
var userAgent = httpMessages.httpRequestMessage.Headers
.First(i => i.Key == "X-User-Agent").Value.ToArray();
Assert.Single(userAgent);
Assert.StartsWith("Unknown/0.0.1 RingCentral.Net/", userAgent[0]);
count += 1;
}
eventsExtension.RequestSuccess += EventHandler;
var china = await rc.Restapi().Dictionary().Country("46").Get();
Assert.Equal("China", china.name);
Assert.Equal(1, count);
eventsExtension.RequestSuccess -= EventHandler;
}
}
}
}