|
| 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 NUnit.Framework.Internal; |
| 8 | + |
| 9 | +namespace Azure.Communication.CallingServer |
| 10 | +{ |
| 11 | + internal class CallAutomationClientLiveTests : CallAutomationClientLiveTestsBase |
| 12 | + { |
| 13 | + public CallAutomationClientLiveTests(bool isAsync) : base(isAsync) |
| 14 | + { |
| 15 | + } |
| 16 | + |
| 17 | + [Test] |
| 18 | + public async Task CreateCallToACSGetCallAndHangUpCallTest() |
| 19 | + { |
| 20 | + /* Test case: ACS to ACS call |
| 21 | + * 1. create a CallAutomationClient. |
| 22 | + * 2. create a call from source to one ACS target. |
| 23 | + * 3. get updated call properties and check for the connected state. |
| 24 | + * 4. hang up the call. |
| 25 | + * 5. once call is hung up, verify that call connection cannot be found. |
| 26 | + */ |
| 27 | + if (SkipCallingServerInteractionLiveTests) |
| 28 | + Assert.Ignore("Skip callingserver interaction live tests flag is on."); |
| 29 | + |
| 30 | + CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString(); |
| 31 | + bool wasConnected = false; |
| 32 | + |
| 33 | + try |
| 34 | + { |
| 35 | + var user = await CreateIdentityUserAsync().ConfigureAwait(false); |
| 36 | + var targets = new CommunicationIdentifier[] { new CommunicationUserIdentifier(TestEnvironment.TargetUserId) }; |
| 37 | + CreateCallResult response = await client.CreateCallAsync(new CallSource(user), targets, new Uri(TestEnvironment.AppCallbackUrl)).ConfigureAwait(false); |
| 38 | + Assert.IsNotEmpty(response.CallConnectionProperties.CallConnectionId); |
| 39 | + Assert.AreEqual(CallConnectionState.Connecting, response.CallConnectionProperties.CallConnectionState); |
| 40 | + await WaitForOperationCompletion().ConfigureAwait(false); |
| 41 | + |
| 42 | + Response<CallConnectionProperties> properties = await response.CallConnection.GetCallConnectionPropertiesAsync().ConfigureAwait(false); |
| 43 | + Assert.AreEqual(CallConnectionState.Connected, properties.Value.CallConnectionState); |
| 44 | + wasConnected = true; |
| 45 | + |
| 46 | + await response.CallConnection.HangUpAsync(true).ConfigureAwait(false); |
| 47 | + await WaitForOperationCompletion().ConfigureAwait(false); |
| 48 | + properties = await response.CallConnection.GetCallConnectionPropertiesAsync().ConfigureAwait(false); |
| 49 | + |
| 50 | + Assert.Fail("Call Connection should not be found after calling HangUp"); |
| 51 | + } |
| 52 | + catch (RequestFailedException ex) |
| 53 | + { |
| 54 | + if (ex.Status == 404 && wasConnected) |
| 55 | + { |
| 56 | + // call hung up successfully |
| 57 | + Assert.Pass(); |
| 58 | + } |
| 59 | + Assert.Fail($"Unexpected error: {ex}"); |
| 60 | + } |
| 61 | + catch (Exception ex) |
| 62 | + { |
| 63 | + Assert.Fail($"Unexpected error: {ex}"); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + [Test] |
| 68 | + public async Task CreateCallToPSTNGetCallAndHangUpCallTest() |
| 69 | + { |
| 70 | + /* Test case: ACS to PSTN call |
| 71 | + * 1. create a CallAutomationClient. |
| 72 | + * 2. create a call from source to one PSTN target. |
| 73 | + * 3. get updated call properties and check for the connected state. |
| 74 | + * 4. hang up the call. |
| 75 | + * 5. once call is hung up, verify that call connection cannot be found. |
| 76 | + */ |
| 77 | + |
| 78 | + if (SkipCallingServerInteractionLiveTests) |
| 79 | + Assert.Ignore("Skip callingserver interaction live tests flag is on."); |
| 80 | + |
| 81 | + CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString(); |
| 82 | + bool wasConnected = false; |
| 83 | + |
| 84 | + try |
| 85 | + { |
| 86 | + var user = await CreateIdentityUserAsync().ConfigureAwait(false); |
| 87 | + var source = new CallSource(user) { |
| 88 | + CallerId = new PhoneNumberIdentifier(TestEnvironment.SourcePhoneNumber) |
| 89 | + }; |
| 90 | + |
| 91 | + var targets = new CommunicationIdentifier[] { new PhoneNumberIdentifier(TestEnvironment.TargetPhoneNumber) }; |
| 92 | + CreateCallResult response = await client.CreateCallAsync(source, targets, new Uri(TestEnvironment.AppCallbackUrl)).ConfigureAwait(false); |
| 93 | + Assert.IsNotEmpty(response.CallConnectionProperties.CallConnectionId); |
| 94 | + Assert.AreEqual("connecting", response.CallConnectionProperties.CallConnectionState.ToString()); |
| 95 | + await WaitForOperationCompletion().ConfigureAwait(false); |
| 96 | + |
| 97 | + Response<CallConnectionProperties> properties = await response.CallConnection.GetCallConnectionPropertiesAsync().ConfigureAwait(false); |
| 98 | + Assert.AreEqual(CallConnectionState.Connected, properties.Value.CallConnectionState); |
| 99 | + wasConnected = true; |
| 100 | + |
| 101 | + await response.CallConnection.HangUpAsync(true).ConfigureAwait(false); |
| 102 | + await WaitForOperationCompletion().ConfigureAwait(false); |
| 103 | + properties = await response.CallConnection.GetCallConnectionPropertiesAsync().ConfigureAwait(false); |
| 104 | + |
| 105 | + Assert.Fail("Call Connection should not be found after calling HangUp"); |
| 106 | + } |
| 107 | + catch (RequestFailedException ex) |
| 108 | + { |
| 109 | + if (ex.Status == 404 && wasConnected) |
| 110 | + { |
| 111 | + // call hung up successfully |
| 112 | + Assert.Pass(); |
| 113 | + } |
| 114 | + Assert.Fail($"Request failed error: {ex}"); |
| 115 | + } |
| 116 | + catch (Exception ex) |
| 117 | + { |
| 118 | + Assert.Fail($"Unexpected error: {ex}"); |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | +} |
0 commit comments