forked from ringcentral/RingCentral.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContactTest.cs
82 lines (72 loc) · 3.28 KB
/
ContactTest.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
using System;
using Newtonsoft.Json;
using Xunit;
namespace RingCentral.Tests
{
public class ContactTest
{
[Fact]
public async void ContactActions()
{
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")
);
const string phoneNumber = "+15889546648";
var addressBook = rc.Restapi().Account().Extension().AddressBook();
var listt = await addressBook.Contact().List(new ListContactsParameters
{phoneNumber = new[] {phoneNumber}});
foreach (var item in listt.records)
{
await addressBook.Contact(item.id.ToString()).Delete();
}
// list
var list = await addressBook.Contact().List();
Assert.NotNull(list);
Assert.Equal(1, list.paging.page);
var total = list.paging.totalElements;
// create
var contact = await addressBook.Contact().Post(new PersonalContactRequest
{
firstName = "FirstName",
lastName = "LastName",
homePhone = phoneNumber
});
Assert.NotNull(contact);
Assert.Equal("LastName", contact.lastName);
// list again
list = await addressBook.Contact().List();
Assert.Equal(total + 1, list.paging.totalElements);
// search
list = await addressBook.Contact().List(new ListContactsParameters {phoneNumber = new[] {phoneNumber}});
Assert.Equal(1, list.paging.totalElements);
var contactId = list.records[0].id;
// update
contact.lastName = "LastName2";
var contactRequest =
JsonConvert.DeserializeObject<PersonalContactRequest>(JsonConvert.SerializeObject(contact));
var contact2 = await addressBook.Contact(contactId.ToString()).Put(contactRequest);
Assert.NotNull(contact2);
Assert.Equal("LastName2", contact2.lastName);
// get
var contact3 = await addressBook.Contact(contactId.ToString()).Get();
Assert.NotNull(contact3);
Assert.Equal("FirstName", contact3.firstName);
Assert.Equal("LastName2", contact3.lastName);
// delete
await addressBook.Contact(contactId.ToString()).Delete();
// search again
list = await addressBook.Contact()
.List(new ListContactsParameters() {phoneNumber = new[] {phoneNumber}});
Assert.Equal(0, list.paging.totalElements);
}
}
}
}