@@ -14,7 +14,8 @@ namespace Sinch.Tests.Features.Voice
1414 public class SinchEvents
1515 {
1616 private readonly HttpClient _httpClient = new HttpClient ( ) ;
17- private ISinchVoiceClient _voiceClient ;
17+ private static IVoiceSinchEvents _voiceSinchEvents ;
18+ private static IVoiceSinchEvents _voiceSinchEventsWithAuth ;
1819 private HttpResponseMessage _pieReturnResponse ;
1920 private string _rawPieSequenceContent ;
2021 private HttpResponseMessage _pieSequenceResponse ;
@@ -33,24 +34,8 @@ public class SinchEvents
3334 [ Given ( @"the Voice Webhooks handler is available" ) ]
3435 public void GivenTheVoiceSinchEventsHandlerIsAvailable ( )
3536 {
36- _voiceClient = new SinchClient (
37- new SinchClientConfiguration
38- {
39- SinchOptions = new SinchOptions
40- {
41- ApiUrlOverrides = new ApiUrlOverrides ( )
42- {
43- VoiceUrl = "http://localhost:3019" ,
44- VoiceApplicationManagementUrl = "http://localhost:3020"
45- }
46- } ,
47- VoiceConfiguration = new SinchVoiceConfiguration ( )
48- {
49- AppKey = "appKey" ,
50- AppSecret = "YXBwU2VjcmV0"
51- }
52- }
53- ) . Voice ;
37+ _voiceSinchEvents = new SinchClient ( ) . Voice . SinchEvents ;
38+ _voiceSinchEventsWithAuth = Utils . TestSinchVoiceClient . SinchEvents ;
5439 }
5540
5641 [ When ( @"I send a request to trigger a ""PIE"" event with a ""return"" type" ) ]
@@ -63,15 +48,15 @@ public async Task WhenISendARequestToTriggerAEventWithAType()
6348 public async Task ThenTheHeaderOfTheEventWithATypeContainsAValidAuthorization ( )
6449 {
6550 _rawPieSequenceContent = await _pieReturnResponse . Content . ReadAsStringAsync ( ) ;
66- _voiceClient . SinchEvents . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
51+ _voiceSinchEventsWithAuth . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
6752 _pieReturnResponse . GetAllHeaders ( ) ,
6853 _rawPieSequenceContent ) . Should ( ) . BeTrue ( ) ;
6954 }
7055
7156 [ Then ( @"the Voice event describes a ""PIE"" event with a ""return"" type" ) ]
7257 public void ThenTheVoiceEventDescribesAEventWithAType ( )
7358 {
74- _voiceClient . SinchEvents . ParseEvent ( _rawPieSequenceContent ) . As < PromptInputEvent > ( ) . Should ( ) . BeEquivalentTo (
59+ _voiceSinchEvents . ParseEvent ( _rawPieSequenceContent ) . As < PromptInputEvent > ( ) . Should ( ) . BeEquivalentTo (
7560 new PromptInputEvent
7661 {
7762 CallId = "1ce0ffee-ca11-ca11-ca11-abcdef000013" ,
@@ -99,15 +84,15 @@ public async Task WhenISendARequestToTriggerAPieEventWithATypeSequence()
9984 public async Task ThenTheHeaderOfTheEventWithAPieTypeSequenceContainsAValidAuthorization ( )
10085 {
10186 _rawPieSequenceContent = await _pieSequenceResponse . Content . ReadAsStringAsync ( ) ;
102- _voiceClient . SinchEvents . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
87+ _voiceSinchEventsWithAuth . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
10388 _pieSequenceResponse . GetAllHeaders ( ) ,
10489 _rawPieSequenceContent ) . Should ( ) . BeTrue ( ) ;
10590 }
10691
10792 [ Then ( @"the Voice event describes a ""PIE"" event with a ""sequence"" type" ) ]
10893 public void ThenTheVoiceEventDescribesAPieEventWithASequenceType ( )
10994 {
110- _voiceClient . SinchEvents . ParseEvent ( _rawPieSequenceContent ) . As < PromptInputEvent > ( ) . Should ( ) . BeEquivalentTo (
95+ _voiceSinchEvents . ParseEvent ( _rawPieSequenceContent ) . As < PromptInputEvent > ( ) . Should ( ) . BeEquivalentTo (
11196 new PromptInputEvent
11297 {
11398 CallId = "1ce0ffee-ca11-ca11-ca11-abcdef000023" ,
@@ -135,15 +120,15 @@ public async Task WhenISendARequestToTriggerAEvent()
135120 public async Task ThenTheHeaderOfTheEventDiceContainsAValidAuthorization ( )
136121 {
137122 _rawDiceContent = await _diceResponse . Content . ReadAsStringAsync ( ) ;
138- _voiceClient . SinchEvents . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
123+ _voiceSinchEventsWithAuth . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
139124 _diceResponse . GetAllHeaders ( ) ,
140125 _rawDiceContent ) . Should ( ) . BeTrue ( ) ;
141126 }
142127
143128 [ Then ( @"the Voice event describes a ""DICE"" event" ) ]
144129 public void ThenTheVoiceEventDescribesAEvent ( )
145130 {
146- _voiceClient . SinchEvents . ParseEvent ( _rawDiceContent ) . Should ( ) . BeEquivalentTo ( new DisconnectedCallEvent
131+ _voiceSinchEvents . ParseEvent ( _rawDiceContent ) . Should ( ) . BeEquivalentTo ( new DisconnectedCallEvent
147132 {
148133 CallId = "1ce0ffee-ca11-ca11-ca11-abcdef000033" ,
149134 Timestamp = Helpers . ParseUtc ( "2024-06-06T16:59:42Z" ) ,
@@ -182,15 +167,15 @@ public async Task WhenISendARequestToTriggerAceEvent()
182167 public async Task ThenTheHeaderOfTheEventContainsAValidAuthorization ( )
183168 {
184169 _rawAceContent = await _aceResponse . Content . ReadAsStringAsync ( ) ;
185- _voiceClient . SinchEvents . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
170+ _voiceSinchEventsWithAuth . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
186171 _aceResponse . GetAllHeaders ( ) ,
187172 _rawAceContent ) . Should ( ) . BeTrue ( ) ;
188173 }
189174
190175 [ Then ( @"the Voice event describes a ""ACE"" event" ) ]
191176 public void ThenTheVoiceEventDescribesAceEvent ( )
192177 {
193- _voiceClient . SinchEvents . ParseEvent ( _rawAceContent ) . Should ( ) . BeEquivalentTo ( new AnsweredCallEvent
178+ _voiceSinchEvents . ParseEvent ( _rawAceContent ) . Should ( ) . BeEquivalentTo ( new AnsweredCallEvent
194179 {
195180 CallId = "1ce0ffee-ca11-ca11-ca11-abcdef000043" ,
196181 CallResourceUrl = null ,
@@ -212,15 +197,15 @@ public async Task WhenISendARequestToTriggerIceEvent()
212197 public async Task ThenTheHeaderOfTheIceEventContainsAValidAuthorization ( )
213198 {
214199 _rawIceContent = await _iceResponse . Content . ReadAsStringAsync ( ) ;
215- _voiceClient . SinchEvents . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
200+ _voiceSinchEventsWithAuth . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
216201 _iceResponse . GetAllHeaders ( ) ,
217202 _rawIceContent ) . Should ( ) . BeTrue ( ) ;
218203 }
219204
220205 [ Then ( @"the Voice event describes a ""ICE"" event" ) ]
221206 public void ThenTheVoiceEventDescribesAIceEvent ( )
222207 {
223- _voiceClient . SinchEvents . ParseEvent ( _rawIceContent ) . As < IncomingCallEvent > ( ) . Should ( ) . BeEquivalentTo (
208+ _voiceSinchEvents . ParseEvent ( _rawIceContent ) . As < IncomingCallEvent > ( ) . Should ( ) . BeEquivalentTo (
224209 new IncomingCallEvent ( )
225210 {
226211 CallId = "1ce0ffee-ca11-ca11-ca11-abcdef000053" ,
@@ -257,15 +242,15 @@ public async Task WhenISendARequestToTriggerARecordFinishedEvent()
257242 public async Task ThenTheHeaderOfTheRecordingFinishedEventContainsAValidAuthorization ( )
258243 {
259244 _rawEventRecordAvailableContent = await _eventRecordingFinishedResponse . Content . ReadAsStringAsync ( ) ;
260- _voiceClient . SinchEvents . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
245+ _voiceSinchEventsWithAuth . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
261246 _eventRecordingFinishedResponse . GetAllHeaders ( ) ,
262247 _rawEventRecordAvailableContent ) . Should ( ) . BeTrue ( ) ;
263248 }
264249
265250 [ Then ( @"the Voice event describes a ""notify"" event with a ""recording_finished"" type" ) ]
266251 public void ThenTheVoiceEventDescribesANotifyEventWithARecordFinishedType ( )
267252 {
268- _voiceClient . SinchEvents . ParseEvent ( _rawEventRecordAvailableContent ) . As < NotificationEvent > ( ) . Should ( ) . BeEquivalentTo (
253+ _voiceSinchEvents . ParseEvent ( _rawEventRecordAvailableContent ) . As < NotificationEvent > ( ) . Should ( ) . BeEquivalentTo (
269254 new NotificationEvent ( )
270255 {
271256 CallId = "33dd8e62-0ac6-4e0c-a89f-36d121f861f9" ,
@@ -285,15 +270,15 @@ public async Task WhenISendARequestToTriggerARecordingAvailableEvent()
285270 public async Task ThenTheHeaderOfTheRecordingAvailableEventContainsAValidAuthorization ( )
286271 {
287272 _rawEventRecordAvailableContent = await _eventRecordingAvailableResponse . Content . ReadAsStringAsync ( ) ;
288- _voiceClient . SinchEvents . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
273+ _voiceSinchEventsWithAuth . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
289274 _eventRecordingAvailableResponse . GetAllHeaders ( ) ,
290275 _rawEventRecordAvailableContent ) . Should ( ) . BeTrue ( ) ;
291276 }
292277
293278 [ Then ( @"the Voice event describes a ""notify"" event with a ""recording_available"" type" ) ]
294279 public void ThenTheVoiceEventNotifyDescribesAEventWithARecordingAvailableType ( )
295280 {
296- _voiceClient . SinchEvents . ParseEvent ( _rawEventRecordAvailableContent ) . As < NotificationEvent > ( ) . Should ( ) . BeEquivalentTo (
281+ _voiceSinchEvents . ParseEvent ( _rawEventRecordAvailableContent ) . As < NotificationEvent > ( ) . Should ( ) . BeEquivalentTo (
297282 new NotificationEvent ( )
298283 {
299284 CallId = "33dd8e62-0ac6-4e0c-a89f-36d121f861f9" ,
@@ -314,15 +299,15 @@ public async Task WhenISendARequestToTriggerATranscriptionAvailableEvent()
314299 public async Task ThenTheHeaderOfTheTranscriptionAvailableEventContainsAValidAuthorization ( )
315300 {
316301 _rawEventTransactionContent = await _eventTranscriptionAvailableResponse . Content . ReadAsStringAsync ( ) ;
317- _voiceClient . SinchEvents . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
302+ _voiceSinchEventsWithAuth . ValidateAuthenticationHeader ( HttpMethod . Post , "/webhooks/voice" ,
318303 _eventTranscriptionAvailableResponse . GetAllHeaders ( ) ,
319304 _rawEventTransactionContent ) . Should ( ) . BeTrue ( ) ;
320305 }
321306
322307 [ Then ( @"the Voice event describes a ""notify"" event with a ""transcription_available"" type" ) ]
323308 public void ThenTheVoiceEventDescribesANotifyEventWithATranscriptionAvailableType ( )
324309 {
325- _voiceClient . SinchEvents . ParseEvent ( _rawEventTransactionContent ) . As < NotificationEvent > ( ) . Should ( ) . BeEquivalentTo (
310+ _voiceSinchEvents . ParseEvent ( _rawEventTransactionContent ) . As < NotificationEvent > ( ) . Should ( ) . BeEquivalentTo (
326311 new NotificationEvent ( )
327312 {
328313 CallId = "33dd8e62-0ac6-4e0c-a89f-36d121f861f9" ,
0 commit comments