-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rsarkar/call automation automated test setup (#31369)
* Initial addition * Updated with unique id generation Updated to cleanup process for service bus after test * Add Unmixed Audio live tests * ACS CallAutomation automated tests setup with samples * revert changes in CallingServer.Tests package * rebase with main * fix cspell errors * minor fixes in RecordedEventListener Co-authored-by: Min Woo Lee 🧊 <[email protected]> Co-authored-by: williamzhao87 <[email protected]>
- Loading branch information
1 parent
9d854c6
commit 8c184c6
Showing
23 changed files
with
4,227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ation.CallAutomation/tests/CallAutomationClient/CallAutomationClientAutomatedLiveTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Azure.Communication.CallAutomation; | ||
using Azure.Communication.CallAutomation.Tests.Infrastructure; | ||
using Azure.Communication.Identity; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Microsoft.AspNetCore.Http; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
|
||
namespace Azure.Communication.CallAutomation | ||
{ | ||
internal class CallAutomationClientAutomatedLiveTests : CallAutomationClientAutomatedLiveTestsBase | ||
{ | ||
public CallAutomationClientAutomatedLiveTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
[RecordedTest] | ||
public async Task CreateCallToACSGetCallAndHangUpCallTest() | ||
{ | ||
/* Test case: ACS to ACS call | ||
* 1. create a CallAutomationClient. | ||
* 2. create a call from source to one ACS target. | ||
* 3. get updated call properties and check for the connected state. | ||
* 4. hang up the call. | ||
* 5. once call is hung up, verify disconnected event | ||
*/ | ||
|
||
CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString(); | ||
|
||
try | ||
{ | ||
// create caller and receiver | ||
var user = await CreateIdentityUserAsync().ConfigureAwait(false); | ||
var target = await CreateIdentityUserAsync().ConfigureAwait(false); | ||
|
||
// setup service bus | ||
var uniqueId = await ServiceBusWithNewCall(user, target); | ||
|
||
// create call and assert response | ||
CreateCallResult response = await client.CreateCallAsync(new CreateCallOptions(new CallSource(user), new CommunicationIdentifier[] { target }, new Uri(TestEnvironment.DispatcherCallback + $"?q={uniqueId}"))).ConfigureAwait(false); | ||
string callConnectionId = response.CallConnectionProperties.CallConnectionId; | ||
Assert.IsNotEmpty(response.CallConnectionProperties.CallConnectionId); | ||
|
||
// wait for incomingcall context | ||
string? incomingCallContext = await WaitForIncomingCallContext(uniqueId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(incomingCallContext); | ||
|
||
// answer the call | ||
AnswerCallResult answerResponse = await client.AnswerCallAsync(incomingCallContext, new Uri(TestEnvironment.DispatcherCallback)); | ||
|
||
// wait for callConnected | ||
var connectedEvent = await WaitForEvent<CallConnected>(callConnectionId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(connectedEvent); | ||
Assert.IsTrue(connectedEvent is CallConnected); | ||
Assert.IsTrue(((CallConnected)connectedEvent!).CallConnectionId == callConnectionId); | ||
|
||
// test get properties | ||
Response<CallConnectionProperties> properties = await response.CallConnection.GetCallConnectionPropertiesAsync().ConfigureAwait(false); | ||
Assert.AreEqual(CallConnectionState.Connected, properties.Value.CallConnectionState); | ||
|
||
// try hangup | ||
await response.CallConnection.HangUpAsync(true).ConfigureAwait(false); | ||
var disconnectedEvent = await WaitForEvent<CallDisconnected>(callConnectionId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(disconnectedEvent); | ||
Assert.IsTrue(disconnectedEvent is CallDisconnected); | ||
Assert.IsTrue(((CallDisconnected)disconnectedEvent!).CallConnectionId == callConnectionId); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Assert.Fail($"Unexpected error: {ex}"); | ||
} | ||
} | ||
} | ||
} |
193 changes: 193 additions & 0 deletions
193
...Azure.Communication.CallAutomation/tests/CallRecording/CallRecordingAutomatedLiveTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Azure.Communication.CallAutomation; | ||
using Azure.Communication.CallAutomation.Tests.Infrastructure; | ||
using Azure.Communication.Identity; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Microsoft.AspNetCore.Http; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
|
||
namespace Azure.Communication.CallAutomation | ||
{ | ||
internal class CallRecordingAutomatedLiveTests : CallAutomationClientAutomatedLiveTestsBase | ||
{ | ||
public CallRecordingAutomatedLiveTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
[RecordedTest] | ||
public async Task CreateACSCallAndUnmixedAudioTest() | ||
{ | ||
/* Test case: ACS to ACS call | ||
* 1. create a CallAutomationClient. | ||
* 2. create a call from source to one ACS target. | ||
* 3. get updated call properties and check for the connected state. | ||
* 4. start recording the call without channel affinity | ||
* 5. stop recording the call | ||
* 6. hang up the call. | ||
* 7. once call is hung up, verify disconnected event | ||
*/ | ||
|
||
CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString(); | ||
|
||
try | ||
{ | ||
// create caller and receiver | ||
var user = await CreateIdentityUserAsync().ConfigureAwait(false); | ||
var target = await CreateIdentityUserAsync().ConfigureAwait(false); | ||
|
||
// setup service bus | ||
var uniqueId = await ServiceBusWithNewCall(user, target); | ||
|
||
// create call and assert response | ||
CreateCallResult response = await client.CreateCallAsync(new CreateCallOptions(new CallSource(user), new CommunicationIdentifier[] { target }, new Uri(TestEnvironment.DispatcherCallback + $"?q={uniqueId}"))).ConfigureAwait(false); | ||
string callConnectionId = response.CallConnectionProperties.CallConnectionId; | ||
Assert.IsNotEmpty(response.CallConnectionProperties.CallConnectionId); | ||
|
||
// wait for incomingcall context | ||
string? incomingCallContext = await WaitForIncomingCallContext(uniqueId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(incomingCallContext); | ||
|
||
// answer the call | ||
var answerResponse = await client.AnswerCallAsync(incomingCallContext, new Uri(TestEnvironment.DispatcherCallback)); | ||
Assert.AreEqual(answerResponse.GetRawResponse().Status, StatusCodes.Status200OK); | ||
|
||
// wait for callConnected | ||
var connectedEvent = await WaitForEvent<CallConnected>(callConnectionId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(connectedEvent); | ||
Assert.IsTrue(connectedEvent is CallConnected); | ||
Assert.IsTrue(((CallConnected)connectedEvent!).CallConnectionId == callConnectionId); | ||
|
||
// test get properties | ||
Response<CallConnectionProperties> properties = await response.CallConnection.GetCallConnectionPropertiesAsync().ConfigureAwait(false); | ||
Assert.AreEqual(CallConnectionState.Connected, properties.Value.CallConnectionState); | ||
|
||
// try start recording unmixed audio - no channel affinity | ||
var startRecordingResponse = await client.GetCallRecording().StartRecordingAsync( | ||
new StartRecordingOptions(new ServerCallLocator(properties.Value.ServerCallId)) | ||
{ | ||
RecordingChannel = RecordingChannel.Unmixed, | ||
RecordingContent = RecordingContent.Audio, | ||
RecordingFormat = RecordingFormat.Wav, | ||
RecordingStateCallbackEndpoint = new Uri(TestEnvironment.DispatcherCallback) | ||
}); | ||
Assert.AreEqual(StatusCodes.Status200OK, startRecordingResponse.GetRawResponse().Status); | ||
Assert.NotNull(startRecordingResponse.Value.RecordingId); | ||
|
||
// try stop recording | ||
var stopRecordingResponse = await client.GetCallRecording().StopRecordingAsync(startRecordingResponse.Value.RecordingId); | ||
Assert.AreEqual(StatusCodes.Status204NoContent, stopRecordingResponse.Status); | ||
|
||
// wait for CallRecordingStateChanged event TODO: Figure out why this event not being received | ||
// var recordingStartedEvent = await WaitForEvent<CallRecordingStateChanged>(callConnectionId, TimeSpan.FromSeconds(20)); | ||
// Assert.IsNotNull(recordingStartedEvent); | ||
// Assert.IsTrue(recordingStartedEvent is CallRecordingStateChanged); | ||
// Assert.IsTrue(((CallRecordingStateChanged)recordingStartedEvent!).CallConnectionId == callConnectionId); | ||
|
||
// try hangup | ||
await response.CallConnection.HangUpAsync(true).ConfigureAwait(false); | ||
var disconnectedEvent = await WaitForEvent<CallDisconnected>(callConnectionId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(disconnectedEvent); | ||
Assert.IsTrue(disconnectedEvent is CallDisconnected); | ||
Assert.IsTrue(((CallDisconnected)disconnectedEvent!).CallConnectionId == callConnectionId); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Assert.Fail($"Unexpected error: {ex}"); | ||
} | ||
} | ||
|
||
[RecordedTest] | ||
public async Task CreateACSCallUnmixedAudioAffinityTest() | ||
{ | ||
/* Test case: ACS to ACS call | ||
* 1. create a CallAutomationClient. | ||
* 2. create a call from source to one ACS target. | ||
* 3. get updated call properties and check for the connected state. | ||
* 4. start recording the call with channel affinity | ||
* 5. stop recording the call | ||
* 6. hang up the call. | ||
* 7. once call is hung up, verify disconnected event | ||
*/ | ||
|
||
CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString(); | ||
|
||
try | ||
{ | ||
// create caller and receiver | ||
var user = await CreateIdentityUserAsync().ConfigureAwait(false); | ||
var target = await CreateIdentityUserAsync().ConfigureAwait(false); | ||
|
||
// setup service bus | ||
var uniqueId = await ServiceBusWithNewCall(user, target); | ||
|
||
// create call and assert response | ||
CreateCallResult response = await client.CreateCallAsync(new CreateCallOptions(new CallSource(user), new CommunicationIdentifier[] { target }, new Uri(TestEnvironment.DispatcherCallback + $"?q={uniqueId}"))).ConfigureAwait(false); | ||
string callConnectionId = response.CallConnectionProperties.CallConnectionId; | ||
Assert.IsNotEmpty(response.CallConnectionProperties.CallConnectionId); | ||
|
||
// wait for incomingcall context | ||
string? incomingCallContext = await WaitForIncomingCallContext(uniqueId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(incomingCallContext); | ||
|
||
// answer the call | ||
var answerResponse = await client.AnswerCallAsync(incomingCallContext, new Uri(TestEnvironment.DispatcherCallback)); | ||
Assert.AreEqual(answerResponse.GetRawResponse().Status, StatusCodes.Status200OK); | ||
|
||
// wait for callConnected | ||
var connectedEvent = await WaitForEvent<CallConnected>(callConnectionId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(connectedEvent); | ||
Assert.IsTrue(connectedEvent is CallConnected); | ||
Assert.IsTrue(((CallConnected)connectedEvent!).CallConnectionId == callConnectionId); | ||
|
||
// test get properties | ||
Response<CallConnectionProperties> properties = await response.CallConnection.GetCallConnectionPropertiesAsync().ConfigureAwait(false); | ||
Assert.AreEqual(CallConnectionState.Connected, properties.Value.CallConnectionState); | ||
|
||
// try start recording unmixed audio with channel affinity | ||
var startRecordingResponse = await client.GetCallRecording().StartRecordingAsync( | ||
new StartRecordingOptions(new ServerCallLocator(properties.Value.ServerCallId)) | ||
{ | ||
RecordingChannel = RecordingChannel.Unmixed, | ||
RecordingContent = RecordingContent.Audio, | ||
RecordingFormat = RecordingFormat.Wav, | ||
RecordingStateCallbackEndpoint = new Uri(TestEnvironment.DispatcherCallback), | ||
ChannelAffinity = new List<ChannelAffinity> | ||
{ | ||
new ChannelAffinity { Channel = 0, Participant = user }, | ||
new ChannelAffinity { Channel = 1, Participant = target } | ||
} | ||
}); | ||
Assert.AreEqual(StatusCodes.Status200OK, startRecordingResponse.GetRawResponse().Status); | ||
Assert.NotNull(startRecordingResponse.Value.RecordingId); | ||
|
||
// try stop recording | ||
var stopRecordingResponse = await client.GetCallRecording().StopRecordingAsync(startRecordingResponse.Value.RecordingId); | ||
Assert.AreEqual(StatusCodes.Status204NoContent, stopRecordingResponse.Status); | ||
|
||
// wait for CallRecordingStateChanged event TODO: Figure out why event not received | ||
// var recordingStartedEvent = await WaitForEvent<CallRecordingStateChanged>(callConnectionId, TimeSpan.FromSeconds(20)); | ||
// Assert.IsNotNull(recordingStartedEvent); | ||
// Assert.IsTrue(recordingStartedEvent is CallRecordingStateChanged); | ||
// Assert.IsTrue(((CallRecordingStateChanged)recordingStartedEvent!).CallConnectionId == callConnectionId); | ||
|
||
// try hangup | ||
await response.CallConnection.HangUpAsync(true).ConfigureAwait(false); | ||
var disconnectedEvent = await WaitForEvent<CallDisconnected>(callConnectionId, TimeSpan.FromSeconds(20)); | ||
Assert.IsNotNull(disconnectedEvent); | ||
Assert.IsTrue(disconnectedEvent is CallDisconnected); | ||
Assert.IsTrue(((CallDisconnected)disconnectedEvent!).CallConnectionId == callConnectionId); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Assert.Fail($"Unexpected error: {ex}"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.