|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using NUnit.Framework; |
| 7 | +using Azure.Communication.CallAutomation.Tests.Infrastructure; |
| 8 | +using Azure.Core.TestFramework; |
| 9 | +using Microsoft.AspNetCore.Http; |
| 10 | + |
| 11 | +namespace Azure.Communication.CallAutomation.Tests.CallMedias |
| 12 | +{ |
| 13 | + internal class CallMediaAutomatedLiveTests : CallAutomationClientAutomatedLiveTestsBase |
| 14 | + { |
| 15 | + public CallMediaAutomatedLiveTests(bool isAsync) : base(isAsync) |
| 16 | + { |
| 17 | + } |
| 18 | + |
| 19 | + [RecordedTest] |
| 20 | + public async Task ContinuousRecognitionTest() |
| 21 | + { |
| 22 | + /* Test case: ACS to ACS call |
| 23 | + * 1. create a CallAutomationClient and a target CallAutomationClient. |
| 24 | + * 2. create a call from source to one ACS target. |
| 25 | + * 3. get updated call properties and check for the connected state. |
| 26 | + * 4. start continuous dtmf recognition. |
| 27 | + * 5. again start continuous dtmf recognition and expect success. |
| 28 | + * 6. stop continuous dtmf recognition. |
| 29 | + * 7. wait for ContinuousDtmfRecognitionStopped event. |
| 30 | + * 8. again stop continuous dtmf recognition and expect success. |
| 31 | + * 10. clean up the call. |
| 32 | + */ |
| 33 | + |
| 34 | + // create caller and receiver |
| 35 | + CommunicationUserIdentifier user = await CreateIdentityUserAsync().ConfigureAwait(false); |
| 36 | + CommunicationUserIdentifier target = await CreateIdentityUserAsync().ConfigureAwait(false); |
| 37 | + |
| 38 | + CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString(user); |
| 39 | + CallAutomationClient targetClient = CreateInstrumentedCallAutomationClientWithConnectionString(target); |
| 40 | + |
| 41 | + // setup service bus |
| 42 | + var uniqueId = await ServiceBusWithNewCall(user, target); |
| 43 | + |
| 44 | + // create call and assert response |
| 45 | + CreateCallResult response = await client.CreateCallAsync(new CallInvite(target), new Uri(TestEnvironment.DispatcherCallback + $"?q={uniqueId}")); |
| 46 | + |
| 47 | + string callConnectionId = response.CallConnectionProperties.CallConnectionId; |
| 48 | + Assert.IsNotEmpty(response.CallConnectionProperties.CallConnectionId); |
| 49 | + |
| 50 | + // wait for incomingcall context |
| 51 | + string? incomingCallContext = await WaitForIncomingCallContext(uniqueId, TimeSpan.FromSeconds(20)); |
| 52 | + Assert.IsNotNull(incomingCallContext); |
| 53 | + |
| 54 | + // answer the call |
| 55 | + var answerCallOptions = new AnswerCallOptions(incomingCallContext, new Uri(TestEnvironment.DispatcherCallback)); |
| 56 | + var answerResponse = await targetClient.AnswerCallAsync(answerCallOptions); |
| 57 | + Assert.AreEqual(StatusCodes.Status200OK, answerResponse.GetRawResponse().Status); |
| 58 | + |
| 59 | + // wait for callConnected |
| 60 | + var connectedEvent = await WaitForEvent<CallConnected>(callConnectionId, TimeSpan.FromSeconds(20)); |
| 61 | + Assert.IsNotNull(connectedEvent); |
| 62 | + Assert.IsTrue(connectedEvent is CallConnected); |
| 63 | + Assert.IsTrue(((CallConnected)connectedEvent!).CallConnectionId == callConnectionId); |
| 64 | + |
| 65 | + // test get properties |
| 66 | + Response<CallConnectionProperties> properties = await response.CallConnection.GetCallConnectionPropertiesAsync().ConfigureAwait(false); |
| 67 | + Assert.AreEqual(CallConnectionState.Connected, properties.Value.CallConnectionState); |
| 68 | + |
| 69 | + try |
| 70 | + { |
| 71 | + // start continuous dtmf recognition |
| 72 | + var startContinuousDtmfResponse = await client.GetCallConnection(callConnectionId).GetCallMedia().StartContinuousDtmfRecognitionAsync(user); |
| 73 | + Assert.AreEqual(StatusCodes.Status200OK, startContinuousDtmfResponse.Status); |
| 74 | + |
| 75 | + // again start continuous dtmf recognition and expect success |
| 76 | + startContinuousDtmfResponse = await client.GetCallConnection(callConnectionId).GetCallMedia().StartContinuousDtmfRecognitionAsync(user); |
| 77 | + Assert.AreEqual(startContinuousDtmfResponse.Status, StatusCodes.Status200OK); |
| 78 | + |
| 79 | + // stop continuous dtmf recognition |
| 80 | + var stopContinuousDtmfResponse = await client.GetCallConnection(callConnectionId).GetCallMedia().StopContinuousDtmfRecognitionAsync(user); |
| 81 | + Assert.AreEqual(StatusCodes.Status200OK, stopContinuousDtmfResponse.Status); |
| 82 | + |
| 83 | + // wait for ContinuousDtmfRecognitionStopped event |
| 84 | + var continuousDtmfRecognitionStopped = await WaitForEvent<ContinuousDtmfRecognitionStopped>(callConnectionId, TimeSpan.FromSeconds(20)); |
| 85 | + Assert.IsNotNull(continuousDtmfRecognitionStopped); |
| 86 | + Assert.IsTrue(continuousDtmfRecognitionStopped is ContinuousDtmfRecognitionStopped); |
| 87 | + |
| 88 | + // again call stop coninuous recognition and expect success |
| 89 | + stopContinuousDtmfResponse = await client.GetCallConnection(callConnectionId).GetCallMedia().StopContinuousDtmfRecognitionAsync(user); |
| 90 | + Assert.AreEqual(StatusCodes.Status200OK, stopContinuousDtmfResponse.Status); |
| 91 | + } |
| 92 | + catch (RequestFailedException ex) |
| 93 | + { |
| 94 | + Assert.Fail($"Unexpected error: {ex}"); |
| 95 | + } |
| 96 | + finally |
| 97 | + { |
| 98 | + await CleanUpCall(client, callConnectionId); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments