Skip to content

Commit

Permalink
GA2 - Add cancel live test & it's recordings (#39527)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishesingh-msft committed Nov 1, 2023
1 parent 822f8a1 commit 5de76fb
Show file tree
Hide file tree
Showing 13 changed files with 1,264 additions and 395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Azure.Communication.CallAutomation.Tests.Infrastructure;
using Azure.Core.TestFramework;
using Microsoft.Azure.Amqp.Framing;
using NUnit.Framework;

namespace Azure.Communication.CallAutomation.Tests.CallConnections
Expand Down Expand Up @@ -125,7 +124,6 @@ public async Task RemoveAUserCallTest()
/// 6. verify the participant is mutred successfully
/// </summary>
/// <returns></returns>
/// [Ignore("ignore until record asset infrastructure is in place")]
[RecordedTest]
public async Task MuteParticipantTest()
{
Expand Down Expand Up @@ -210,5 +208,90 @@ public async Task MuteParticipantTest()
await CleanUpCall(client, callConnectionId);
}
}

/// <summary>
/// Tests: CreateCall, AddParticipant, CancelAddParticipant
/// Test case: ACS to ACS call
/// 1. create a CallAutomationClient.
/// 2. create a call from source to ACS target.
/// 3. get updated call properties and check for the connected state.
/// 4. Add a Participant.
/// 5. Cancel the add participant
/// </summary>
/// <returns></returns>
[RecordedTest]
public async Task CancelAddParticipantTest()
{
// create caller and receiver
var user = await CreateIdentityUserAsync().ConfigureAwait(false);
var target = await CreateIdentityUserAsync().ConfigureAwait(false);
var participantToAdd = await CreateIdentityUserAsync().ConfigureAwait(false);
var client = CreateInstrumentedCallAutomationClientWithConnectionString(user);
var targetClient = CreateInstrumentedCallAutomationClientWithConnectionString(target);
string? callConnectionId = null;

try
{
// setup service bus
var uniqueId = await ServiceBusWithNewCall(user, target);

// create call and assert response
var createCallOptions = new CreateCallOptions(new CallInvite(target), new Uri(TestEnvironment.DispatcherCallback + $"?q={uniqueId}"));
CreateCallResult response = await client.CreateCallAsync(createCallOptions).ConfigureAwait(false);
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 answerCallOptions = new AnswerCallOptions(incomingCallContext, new Uri(TestEnvironment.DispatcherCallback));
AnswerCallResult answerResponse = await targetClient.AnswerCallAsync(answerCallOptions);

// wait for callConnected
var connectedEvent = await WaitForEvent<CallConnected>(callConnectionId, TimeSpan.FromSeconds(20));
Assert.IsNotNull(connectedEvent);
Assert.IsTrue(connectedEvent is CallConnected);
Assert.AreEqual(callConnectionId, ((CallConnected)connectedEvent!).CallConnectionId);

// add participant
var callConnection = response.CallConnection;
var operationContext = "context";
var addParticipantOptions = new AddParticipantOptions(new CallInvite(participantToAdd))
{
InvitationTimeoutInSeconds = 60,
OperationContext = operationContext,
};

var addParticipantResponse = await callConnection.AddParticipantAsync(addParticipantOptions);
Assert.AreEqual(operationContext, addParticipantResponse.Value.OperationContext);
Assert.IsNotNull(addParticipantResponse.Value.InvitationId);

// ensure invitation has arrived
await WaitForOperationCompletion(3000);

// cancel add participant
CancelAddParticipantOptions options = new(addParticipantResponse.Value.InvitationId)
{
OperationContext = operationContext
};
await callConnection.CancelAddParticipantAsync(options);

// wait for cancel event
var cancelAddParticipantSucceededEvent = await WaitForEvent<CancelAddParticipantSucceeded>(callConnectionId, TimeSpan.FromSeconds(20));
Assert.IsNotNull(cancelAddParticipantSucceededEvent);
Assert.IsTrue(cancelAddParticipantSucceededEvent is CancelAddParticipantSucceeded);
Assert.AreEqual(((CancelAddParticipantSucceeded)cancelAddParticipantSucceededEvent!).InvitationId, addParticipantResponse.Value.InvitationId);
}
catch (Exception ex)
{
Assert.Fail($"Unexpected error: {ex}");
}
finally
{
await CleanUpCall(client, callConnectionId);
}
}
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 5de76fb

Please sign in to comment.