Skip to content

Commit

Permalink
Adding CallRecording live tests. (Azure#30435)
Browse files Browse the repository at this point in the history
* Initial commit

* new tests, same failures

* First Live Test

* Adding live tests

* Cleaning

* Adding PlayAudio live tests

* Updating Swagger

* AutoResting new swagger

* Adding Events for CallRecording and Play

* Fixing build

* Fixing new option bag

* Export API

* Fixing naming

* Fixing merge

* Fixing changes

* Fixing merge

* Applying PR comments
  • Loading branch information
cochi2 authored Aug 18, 2022
1 parent 62f2223 commit ba4ee34
Show file tree
Hide file tree
Showing 23 changed files with 1,948 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1917,4 +1917,4 @@
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
<ItemGroup>
<None Include="..\tests.yml" Link="\tests.yml" />
</ItemGroup>
<ItemGroup>
<Folder Include="SessionRecords\CallMediaLiveTests\" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Azure.Communication.CallingServer
{
internal class CallMediaLiveTests : CallAutomationClientLiveTestsBase
{
public CallMediaLiveTests(bool isAsync) : base(isAsync)
{ }

[Test]
public async Task PlayAudio()
{
CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString();
string callConnectionId = "";
try
{
var user = await CreateIdentityUserAsync().ConfigureAwait(false);
var targetUserId = TestEnvironment.TargetUserId;
var targetUser = new CommunicationUserIdentifier(targetUserId);
string ngrok = "https://localhost";
string playAudioUri = "https://localhost/bot-hold-music-2.wav";
var targets = new CommunicationIdentifier[] { targetUser };
var callResponse = await client.CreateCallAsync(new CallSource(user), targets, new Uri(ngrok)).ConfigureAwait(false);
Assert.NotNull(callResponse);
Assert.NotNull(callResponse.Value);
var callConnection = callResponse.Value.CallConnection;
callConnectionId = callConnection.CallConnectionId;
var playResponse = await callConnection.GetCallMedia().PlayAsync(
new FileSource(new Uri(playAudioUri)) { PlaySourceId = "playSourceId"},
new CommunicationUserIdentifier[] { targetUser });
Assert.NotNull(playResponse);
Assert.AreEqual(202, playResponse.Status);
}
catch (RequestFailedException ex)
{
Assert.Fail($"Unexpected error: {ex}");
}
finally
{
var callConnection = client.GetCallConnection(callConnectionId);
await callConnection.HangUpAsync(true).ConfigureAwait(false);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Azure.Communication.CallingServer
{
internal class CallRecordingLiveTests : CallAutomationClientLiveTestsBase
{
public CallRecordingLiveTests(bool isAsync) : base(isAsync)
{ }

[Test]
public async Task RecordingOperations()
{
if (SkipCallingServerInteractionLiveTests)
{
Assert.Ignore("Skip callingserver interaction live tests flag is on");
}

CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString();
string callConnectionId = "";
bool stopRecording = false;
try
{
var user = await CreateIdentityUserAsync().ConfigureAwait(false);
var targetUser = TestEnvironment.TargetUserId;
string ngrok = "https://localhost";
var targets = new CommunicationIdentifier[] { new CommunicationUserIdentifier(targetUser) };
var callResponse = await client.CreateCallAsync(new CallSource(user), targets, new Uri(ngrok)).ConfigureAwait(false);
Assert.NotNull(callResponse);
Assert.NotNull(callResponse.Value);
string callId = "serverCallId";
callConnectionId = callResponse.Value.CallConnection.CallConnectionId;
CallRecording callRecording = client.GetCallRecording();
StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator(callId))
{
RecordingStateCallbackEndpoint = new Uri(ngrok)
};
var recordingResponse = await callRecording.StartRecordingAsync(recordingOptions).ConfigureAwait(false);
Assert.NotNull(recordingResponse.Value);

var recordingId = recordingResponse.Value.RecordingId;
Assert.NotNull(recordingId);
await WaitForOperationCompletion().ConfigureAwait(false);

recordingResponse = await callRecording.GetRecordingStateAsync(recordingId).ConfigureAwait(false);
Assert.NotNull(recordingResponse.Value);
Assert.NotNull(recordingResponse.Value.RecordingState);
Assert.AreEqual(recordingResponse.Value.RecordingState, RecordingState.Active);

await callRecording.PauseRecordingAsync(recordingId);
await WaitForOperationCompletion().ConfigureAwait(false);
recordingResponse = await callRecording.GetRecordingStateAsync(recordingId).ConfigureAwait(false);
Assert.NotNull(recordingResponse.Value);
Assert.NotNull(recordingResponse.Value.RecordingState);
Assert.AreEqual(recordingResponse.Value.RecordingState, RecordingState.Inactive);

await callRecording.ResumeRecordingAsync(recordingId);
await WaitForOperationCompletion().ConfigureAwait(false);
recordingResponse = await callRecording.GetRecordingStateAsync(recordingId).ConfigureAwait(false);
Assert.NotNull(recordingResponse.Value);
Assert.NotNull(recordingResponse.Value.RecordingState);
Assert.AreEqual(recordingResponse.Value.RecordingState, RecordingState.Active);

await callRecording.StopRecordingAsync(recordingId);
await WaitForOperationCompletion().ConfigureAwait(false);
stopRecording = true;
recordingResponse = await callRecording.GetRecordingStateAsync(recordingId).ConfigureAwait(false);
}
catch (RequestFailedException ex)
{
if (ex.Status == 404 && stopRecording)
{
// recording stopped successfully
Assert.Pass();
}
Assert.Fail($"Unexpected error: {ex}");
}
finally
{
var callConnection = client.GetCallConnection(callConnectionId);
await callConnection.HangUpAsync(true).ConfigureAwait(false);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Azure.Communication.CallingServer
{
internal class ContentDownloadLiveTests : CallAutomationClientLiveTestsBase
{
public ContentDownloadLiveTests(bool isAsync) : base(isAsync)
{ }

[Test]
public async Task DownloadMetadata()
{
if (SkipCallingServerInteractionLiveTests)
{
Assert.Ignore("Skip callingserver interaction live tests flag is on");
}

CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString();
string documentId = "0-wus-d4-d4c223871b58d3664401b66d35fca784";
Uri metadataEndpoint = new Uri($"https://us-storage.asm.skype.com/v1/objects/{documentId}/content/acsmetadata");
CallRecording callRecordingClient = client.GetCallRecording();
Stream metadata = await callRecordingClient.DownloadStreamingAsync(metadataEndpoint);
Assert.IsNotNull(metadata);
JsonElement actual = JsonDocument.Parse(metadata).RootElement;
Assert.AreEqual(documentId, actual.GetProperty("chunkDocumentId").ToString());
}

[Test]
public async Task DownloadMetadata_404()
{
if (SkipCallingServerInteractionLiveTests)
{
Assert.Ignore("Skip callingserver interaction live tests flag is on");
}

CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString();
string nonExistentDocumentId = "0-wus-d4-d4c223871b58d3664401b66d35fca785";
Uri metadataEndpoint = new Uri($"https://us-storage.asm.skype.com/v1/objects/{nonExistentDocumentId}/content/acsmetadata");
CallRecording callRecordingClient = client.GetCallRecording();
try
{
Stream metadata = await callRecordingClient.DownloadStreamingAsync(metadataEndpoint);
Assert.IsNotNull(metadata);
JsonElement actual = JsonDocument.Parse(metadata).RootElement;
Assert.AreEqual(nonExistentDocumentId, actual.GetProperty("chunkDocumentId").ToString());
}
catch (RequestFailedException ex)
{
if (ex.Status == 404)
{
Assert.Pass("Recording was not found");
}
else
{
Assert.Fail($"Unexpected error: {ex}");
}
}
}

[Test]
public async Task DownloadMetadataRange()
{
if (SkipCallingServerInteractionLiveTests)
{
Assert.Ignore("Skip callingserver interaction live tests flag is on");
}

CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString();
int length = 5;
string documentId = "0-wus-d4-d4c223871b58d3664401b66d35fca784";
Uri metadataEndpoint = new Uri($"https://us-storage.asm.skype.com/v1/objects/{documentId}/content/acsmetadata");
CallRecording callRecordingClient = client.GetCallRecording();
Response<Stream> response = await callRecordingClient.DownloadStreamingAsync(metadataEndpoint, new HttpRange(0, length));
Assert.IsNotNull(response);
Assert.AreEqual(length, response.GetRawResponse().Headers.ContentLength);
}

[Test]
/// This test tries to get a US stored document id from EU endpoint.
/// The backend server will redirect (respond with a 301) the request to a US endpoint
/// and the SDK should be able to make the new request with no error.
public async Task DownloadMetadataWithRedirection()
{
if (SkipCallingServerInteractionLiveTests)
{
Assert.Ignore("Skip callingserver interaction live tests flag is on");
}

CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString();
string documentId = "0-wus-d4-d4c223871b58d3664401b66d35fca784";
Uri metadataEndpoint = new Uri($"https://eu-storage.asm.skype.com/v1/objects/{documentId}/content/acsmetadata");
CallRecording callRecordingClient = client.GetCallRecording();
Stream metadata = await callRecordingClient.DownloadStreamingAsync(metadataEndpoint);
Assert.IsNotNull(metadata);
JsonElement actual = JsonDocument.Parse(metadata).RootElement;
Assert.AreEqual(documentId, actual.GetProperty("chunkDocumentId").ToString());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Azure.Communication.CallingServer
{
internal class DeleteRecordingLiveTests : CallAutomationClientLiveTestsBase
{
public DeleteRecordingLiveTests(bool isAsync) : base(isAsync)
{ }

[Test]
public async Task DeleteRecording()
{
if (SkipCallingServerInteractionLiveTests)
{
Assert.Ignore("Skip callingserver interaction live tests flag is on");
}

CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString();
string documentId = "0-wus-d4-d4c223871b58d3664401b66d35fca784";
Uri contentEndpoint = new Uri($"https://us-storage.asm.skype.com/v1/objects/{documentId}");
CallRecording callRecordingClient = client.GetCallRecording();
Response response = await callRecordingClient.DeleteRecordingAsync(contentEndpoint);
Assert.IsNotNull(response);
Assert.AreEqual(200, response.Status);
}

[Test]
public async Task DeleteRecording404()
{
if (SkipCallingServerInteractionLiveTests)
{
Assert.Ignore("Skip callingserver interaction live tests flag is on");
}

CallAutomationClient client = CreateInstrumentedCallAutomationClientWithConnectionString();
string nonExistentDocumentId = "0-wus-d4-d4c223871b58d3664401b66d35fca785";
Uri contentEndpoint = new Uri($"https://us-storage.asm.skype.com/v1/objects/{nonExistentDocumentId}");
CallRecording callRecordingClient = client.GetCallRecording();
try
{
await callRecordingClient.DeleteRecordingAsync(contentEndpoint);
}
catch (RequestFailedException ex)
{
if (ex.Status == 404)
{
Assert.Pass("Recording was not found");
}
else
{
Assert.Fail($"Unexpected error: {ex}");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private CallAutomationClientOptions CreateServerCallingClientOptionsWithCorrelat
protected async Task WaitForOperationCompletion(int milliSeconds = 10000)
{
if (TestEnvironment.Mode != RecordedTestMode.Playback)
await Task.Delay(10000);
await Task.Delay(milliSeconds);
}

protected string GetResourceId()
Expand Down
Loading

0 comments on commit ba4ee34

Please sign in to comment.