1
1
using Google . Protobuf ;
2
+ using Google . Protobuf . Collections ;
3
+ using Xunit ;
4
+ using Xunit . Abstractions ;
2
5
3
6
namespace Livekit . Server . Sdk . Dotnet . Test
4
7
{
5
8
[ Collection ( "Integration tests" ) ]
6
9
public class SipServiceClientTest
7
10
{
8
11
private ServiceClientFixture fixture ;
12
+ private readonly ITestOutputHelper output ;
9
13
10
- public SipServiceClientTest ( ServiceClientFixture fixture )
14
+ public SipServiceClientTest ( ServiceClientFixture fixture , ITestOutputHelper output )
11
15
{
12
16
this . fixture = fixture ;
17
+ this . output = output ;
13
18
}
14
19
15
20
private SipServiceClient sipClient = new SipServiceClient (
16
21
ServiceClientFixture . TEST_HTTP_URL ,
17
22
ServiceClientFixture . TEST_API_KEY ,
18
23
ServiceClientFixture . TEST_API_SECRET
19
24
) ;
25
+ private readonly RoomServiceClient roomClient = new RoomServiceClient (
26
+ ServiceClientFixture . TEST_HTTP_URL ,
27
+ ServiceClientFixture . TEST_API_KEY ,
28
+ ServiceClientFixture . TEST_API_SECRET
29
+ ) ;
20
30
21
31
[ Fact ]
22
32
[ Trait ( "Category" , "Integration" ) ]
@@ -67,6 +77,23 @@ public async Task Create_Sip_Inbound_Trunk()
67
77
Assert . Equal ( request . Trunk . AllowedNumbers , response . AllowedNumbers ) ;
68
78
}
69
79
80
+ [ Fact ]
81
+ [ Trait ( "Category" , "Integration" ) ]
82
+ [ Trait ( "Category" , "SipService" ) ]
83
+ public async Task Create_Sip_Inbound_Trunk_Exceptions ( )
84
+ {
85
+ Twirp . Exception ex = await Assert . ThrowsAsync < Twirp . Exception > (
86
+ async ( ) =>
87
+ await sipClient . CreateSIPInboundTrunk (
88
+ new CreateSIPInboundTrunkRequest { Trunk = new SIPInboundTrunkInfo { } }
89
+ )
90
+ ) ;
91
+ Assert . Equal (
92
+ "for security, one of the fields must be set: AuthUsername+AuthPassword, AllowedAddresses or Numbers" ,
93
+ ex . Message
94
+ ) ;
95
+ }
96
+
70
97
[ Fact ]
71
98
[ Trait ( "Category" , "Integration" ) ]
72
99
[ Trait ( "Category" , "SipService" ) ]
@@ -92,13 +119,50 @@ public async Task Create_Sip_Outbound_Trunk()
92
119
Assert . Equal ( request . Trunk . AuthPassword , response . AuthPassword ) ;
93
120
}
94
121
122
+ [ Fact ]
123
+ [ Trait ( "Category" , "Integration" ) ]
124
+ [ Trait ( "Category" , "SipService" ) ]
125
+ public async Task Create_Sip_Outbound_Trunk_Exceptions ( )
126
+ {
127
+ Twirp . Exception ex = await Assert . ThrowsAsync < Twirp . Exception > (
128
+ async ( ) =>
129
+ await sipClient . CreateSIPOutboundTrunk (
130
+ new CreateSIPOutboundTrunkRequest { Trunk = new SIPOutboundTrunkInfo { } }
131
+ )
132
+ ) ;
133
+ Assert . Equal ( "no trunk numbers specified" , ex . Message ) ;
134
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
135
+ async ( ) =>
136
+ await sipClient . CreateSIPOutboundTrunk (
137
+ new CreateSIPOutboundTrunkRequest
138
+ {
139
+ Trunk = new SIPOutboundTrunkInfo { Address = "my-test-trunk.com" } ,
140
+ }
141
+ )
142
+ ) ;
143
+ Assert . Equal ( "no trunk numbers specified" , ex . Message ) ;
144
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
145
+ async ( ) =>
146
+ await sipClient . CreateSIPOutboundTrunk (
147
+ new CreateSIPOutboundTrunkRequest
148
+ {
149
+ Trunk = new SIPOutboundTrunkInfo { Numbers = { "+111" , "+222" } } ,
150
+ }
151
+ )
152
+ ) ;
153
+ Assert . Equal ( "no outbound address specified" , ex . Message ) ;
154
+ }
155
+
95
156
[ Fact ]
96
157
[ Trait ( "Category" , "Integration" ) ]
97
158
[ Trait ( "Category" , "SipService" ) ]
98
159
public async Task Get_Sip_Inbound_Trunk ( )
99
160
{
100
161
var inboundTrunk = await sipClient . CreateSIPInboundTrunk (
101
- new CreateSIPInboundTrunkRequest { Trunk = new SIPInboundTrunkInfo { } }
162
+ new CreateSIPInboundTrunkRequest
163
+ {
164
+ Trunk = new SIPInboundTrunkInfo { Numbers = { "+111" , "+222" } } ,
165
+ }
102
166
) ;
103
167
var getRequest = new GetSIPInboundTrunkRequest { SipTrunkId = inboundTrunk . SipTrunkId } ;
104
168
var response = await sipClient . GetSIPInboundTrunk ( getRequest ) ;
@@ -112,7 +176,14 @@ public async Task Get_Sip_Inbound_Trunk()
112
176
public async Task Get_Sip_Outound_Trunk ( )
113
177
{
114
178
var outboundTrunk = await sipClient . CreateSIPOutboundTrunk (
115
- new CreateSIPOutboundTrunkRequest { Trunk = new SIPOutboundTrunkInfo { } }
179
+ new CreateSIPOutboundTrunkRequest
180
+ {
181
+ Trunk = new SIPOutboundTrunkInfo
182
+ {
183
+ Numbers = { "+111" , "+222" } ,
184
+ Address = "my-test-trunk.com" ,
185
+ } ,
186
+ }
116
187
) ;
117
188
var getRequest = new GetSIPOutboundTrunkRequest
118
189
{
@@ -129,7 +200,10 @@ public async Task Get_Sip_Outound_Trunk()
129
200
public async Task Delete_Sip_Trunk ( )
130
201
{
131
202
var trunk = await sipClient . CreateSIPInboundTrunk (
132
- new CreateSIPInboundTrunkRequest { Trunk = new SIPInboundTrunkInfo { } }
203
+ new CreateSIPInboundTrunkRequest
204
+ {
205
+ Trunk = new SIPInboundTrunkInfo { Numbers = { "+111" , "+222" } } ,
206
+ }
133
207
) ;
134
208
var allTrunks = await sipClient . ListSIPInboundTrunk ( new ListSIPInboundTrunkRequest { } ) ;
135
209
Assert . Contains ( allTrunks . Items , t => t . SipTrunkId == trunk . SipTrunkId ) ;
@@ -185,5 +259,162 @@ public async Task Dispatch_Rule()
185
259
r => r . SipDispatchRuleId == dispatchRule . SipDispatchRuleId
186
260
) ;
187
261
}
262
+
263
+ [ Fact ]
264
+ [ Trait ( "Category" , "Integration" ) ]
265
+ [ Trait ( "Category" , "SipService" ) ]
266
+ public async Task Create_Sip_Participant ( )
267
+ {
268
+ Twirp . Exception ex = await Assert . ThrowsAsync < Twirp . Exception > (
269
+ async ( ) =>
270
+ await sipClient . CreateSIPParticipant (
271
+ new CreateSIPParticipantRequest { SipTrunkId = "non-existing-trunk" }
272
+ )
273
+ ) ;
274
+ Assert . Equal ( "requested sip trunk does not exist" , ex . Message ) ;
275
+
276
+ SIPOutboundTrunkInfo trunk = await sipClient . CreateSIPOutboundTrunk (
277
+ new CreateSIPOutboundTrunkRequest
278
+ {
279
+ Trunk = new SIPOutboundTrunkInfo
280
+ {
281
+ Name = "Demo outbound trunk" ,
282
+ Address = "my-test-trunk.com" ,
283
+ Numbers = { "+1234567890" } ,
284
+ AuthUsername = "username" ,
285
+ AuthPassword = "password" ,
286
+ } ,
287
+ }
288
+ ) ;
289
+
290
+ CreateSIPParticipantRequest request = new CreateSIPParticipantRequest
291
+ {
292
+ SipTrunkId = "trunk" ,
293
+ } ;
294
+
295
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
296
+ async ( ) =>
297
+ await sipClient . CreateSIPParticipant (
298
+ new CreateSIPParticipantRequest { SipTrunkId = "non-existing-trunk" }
299
+ )
300
+ ) ;
301
+ Assert . Equal ( "requested sip trunk does not exist" , ex . Message ) ;
302
+
303
+ request . SipTrunkId = trunk . SipTrunkId ;
304
+
305
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
306
+ async ( ) => await sipClient . CreateSIPParticipant ( request )
307
+ ) ;
308
+ Assert . Equal ( "call-to number must be set" , ex . Message ) ;
309
+
310
+ request . SipCallTo = "+3333" ;
311
+
312
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
313
+ async ( ) => await sipClient . CreateSIPParticipant ( request )
314
+ ) ;
315
+ Assert . Equal ( "room name must be set" , ex . Message ) ;
316
+
317
+ request . RoomName = TestConstants . ROOM_NAME ;
318
+
319
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
320
+ async ( ) => await sipClient . CreateSIPParticipant ( request )
321
+ ) ;
322
+ Assert . Equal ( "update room failed: identity cannot be empty" , ex . Message ) ;
323
+
324
+ request . ParticipantIdentity = TestConstants . PARTICIPANT_IDENTITY ;
325
+
326
+ request . ParticipantName = "Test Caller" ;
327
+ request . SipNumber = "+1111" ;
328
+ request . RingingTimeout = new Google . Protobuf . WellKnownTypes . Duration { Seconds = 10 } ;
329
+ request . PlayDialtone = true ;
330
+ request . ParticipantMetadata = "meta" ;
331
+ request . ParticipantAttributes . Add ( "extra" , "1" ) ;
332
+ request . MediaEncryption = SIPMediaEncryption . SipMediaEncryptRequire ;
333
+ request . MaxCallDuration = new Google . Protobuf . WellKnownTypes . Duration { Seconds = 99 } ;
334
+ request . KrispEnabled = true ;
335
+ request . IncludeHeaders = SIPHeaderOptions . SipAllHeaders ;
336
+ request . Dtmf = "1234#" ;
337
+ request . HidePhoneNumber = true ;
338
+ request . Headers . Add ( "X-A" , "A" ) ;
339
+
340
+ SIPParticipantInfo sipParticipantInfo = await sipClient . CreateSIPParticipant ( request ) ;
341
+
342
+ Assert . NotNull ( sipParticipantInfo ) ;
343
+ Assert . Equal ( TestConstants . PARTICIPANT_IDENTITY , request . ParticipantIdentity ) ;
344
+ Assert . Equal ( TestConstants . ROOM_NAME , request . RoomName ) ;
345
+
346
+ var sipParticipant = await roomClient . GetParticipant (
347
+ new RoomParticipantIdentity
348
+ {
349
+ Room = TestConstants . ROOM_NAME ,
350
+ Identity = TestConstants . PARTICIPANT_IDENTITY ,
351
+ }
352
+ ) ;
353
+ Assert . NotNull ( sipParticipant ) ;
354
+ Assert . Equal ( TestConstants . PARTICIPANT_IDENTITY , sipParticipant . Identity ) ;
355
+ Assert . Equal ( "Test Caller" , sipParticipant . Name ) ;
356
+ Assert . Equal ( "meta" , sipParticipant . Metadata ) ;
357
+ Assert . Equal ( "1" , sipParticipant . Attributes [ "extra" ] ) ;
358
+ }
359
+
360
+ [ Fact ]
361
+ [ Trait ( "Category" , "Integration" ) ]
362
+ [ Trait ( "Category" , "SipService" ) ]
363
+ public async Task Transfer_Sip_Participant ( )
364
+ {
365
+ var trunk = await sipClient . CreateSIPOutboundTrunk (
366
+ new CreateSIPOutboundTrunkRequest
367
+ {
368
+ Trunk = new SIPOutboundTrunkInfo
369
+ {
370
+ Name = "Demo outbound trunk" ,
371
+ Address = "my-test-trunk.com" ,
372
+ Numbers = { "+1234567890" } ,
373
+ AuthUsername = "username" ,
374
+ AuthPassword = "password" ,
375
+ } ,
376
+ }
377
+ ) ;
378
+
379
+ var request = new CreateSIPParticipantRequest
380
+ {
381
+ SipTrunkId = trunk . SipTrunkId ,
382
+ SipCallTo = "+3333" ,
383
+ RoomName = TestConstants . ROOM_NAME ,
384
+ ParticipantIdentity = TestConstants . PARTICIPANT_IDENTITY ,
385
+ ParticipantName = "Test Caller" ,
386
+ SipNumber = "+1111" ,
387
+ } ;
388
+
389
+ SIPParticipantInfo sipParticipantInfo = await sipClient . CreateSIPParticipant ( request ) ;
390
+
391
+ var transferRequest = new TransferSIPParticipantRequest { } ;
392
+
393
+ Twirp . Exception ex = await Assert . ThrowsAsync < Twirp . Exception > (
394
+ async ( ) => await sipClient . TransferSIPParticipant ( transferRequest )
395
+ ) ;
396
+ Assert . Equal ( "Missing room name" , ex . Message ) ;
397
+
398
+ transferRequest . RoomName = TestConstants . ROOM_NAME ;
399
+
400
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
401
+ async ( ) => await sipClient . TransferSIPParticipant ( transferRequest )
402
+ ) ;
403
+ Assert . Equal ( "Missing participant identity" , ex . Message ) ;
404
+
405
+ transferRequest . ParticipantIdentity = TestConstants . PARTICIPANT_IDENTITY ;
406
+ transferRequest . TransferTo = "+14155550100" ;
407
+ transferRequest . PlayDialtone = false ;
408
+
409
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
410
+ async ( ) => await sipClient . TransferSIPParticipant ( transferRequest )
411
+ ) ;
412
+ Assert . Equal ( "can't transfer non established call" , ex . Message ) ;
413
+
414
+ ex = await Assert . ThrowsAsync < Twirp . Exception > (
415
+ async ( ) => await sipClient . TransferSIPParticipant ( transferRequest )
416
+ ) ;
417
+ Assert . Equal ( "participant does not exist" , ex . Message ) ;
418
+ }
188
419
}
189
420
}
0 commit comments