Skip to content

Commit

Permalink
Rsarkar/call automation automated test setup (#31369)
Browse files Browse the repository at this point in the history
* 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
3 people authored Sep 23, 2022
1 parent 9d854c6 commit 8c184c6
Show file tree
Hide file tree
Showing 23 changed files with 4,227 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Azure.Messaging.ServiceBus" />
<PackageReference Include="Azure.Core.Amqp" />
<PackageReference Include="Microsoft.Azure.Amqp" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(AzureCoreTestFramework)" />
<ProjectReference Include="..\..\Azure.Communication.Identity\src\Azure.Communication.Identity.csproj" />
Expand All @@ -18,6 +22,7 @@
<None Include="..\tests.yml" Link="\tests.yml" />
</ItemGroup>
<ItemGroup>
<Folder Include="SessionRecordedEvents\" />
<Folder Include="SessionRecords\CallMediaLiveTests\" />
<Folder Include="SessionRecords\CallConnectionLiveTests\" />
</ItemGroup>
Expand Down
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}");
}
}
}
}
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}");
}
}
}
}
Loading

0 comments on commit 8c184c6

Please sign in to comment.