Skip to content

Commit

Permalink
NIT fix (#21540)
Browse files Browse the repository at this point in the history
  • Loading branch information
zihzhan-msft authored Jun 2, 2021
1 parent c77ed60 commit abba988
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ public virtual Response HangupCall(string callLegId, CancellationToken cancellat

/// <summary> Cancel all media operations in the call. </summary>
/// <param name="callLegId"> The call leg id. </param>
/// <param name="operationContext">The operation context. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response<CancelAllMediaOperationsResponse>> CancelAllMediaOperationsAsync(string callLegId, CancellationToken cancellationToken = default)
public virtual async Task<Response<CancelAllMediaOperationsResponse>> CancelAllMediaOperationsAsync(string callLegId, string operationContext = null, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallClient)}.{nameof(CancelAllMediaOperationsAsync)}");
scope.Start();
try
{
return await RestClient.CancelAllMediaOperationsAsync(callLegId, cancellationToken: cancellationToken).ConfigureAwait(false);
return await RestClient.CancelAllMediaOperationsAsync(callLegId, operationContext, cancellationToken: cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand All @@ -267,15 +268,16 @@ public virtual async Task<Response<CancelAllMediaOperationsResponse>> CancelAllM

/// <summary> Cancel all media operations in the call. </summary>
/// <param name="callLegId"> The call leg id. </param>
/// <param name="operationContext">The operation context. </param>
/// <param name="cancellationToken"> The cancellation token. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response<CancelAllMediaOperationsResponse> CancelAllMediaOperations(string callLegId, CancellationToken cancellationToken = default)
public virtual Response<CancelAllMediaOperationsResponse> CancelAllMediaOperations(string callLegId, string operationContext = null, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallClient)}.{nameof(CancelAllMediaOperations)}");
scope.Start();
try
{
return RestClient.CancelAllMediaOperations(callLegId, cancellationToken: cancellationToken);
return RestClient.CancelAllMediaOperations(callLegId, operationContext, cancellationToken: cancellationToken);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,25 @@ public async Task HangupCallAsyncOverload_Passes(string expectedCallLegId)
Assert.AreEqual(expectedResponse, actualResponse);
}

[TestCaseSource(nameof(TestData_CancelMediaOperations))]
public async Task CancelMediaOperationsAsyncOverload_Passes(string expectedCallLegId)
[TestCaseSource(nameof(TestData_CancelAllMediaOperations))]
public async Task CancelMediaOperationsAsyncOverload_Passes(string expectedCallLegId, string expectedOperationContext)
{
Mock<CallClient> mockClient = new Mock<CallClient>() { CallBase = true };
Response<CancelAllMediaOperationsResponse>? expectedResponse = default;
CancellationToken cancellationToken = new CancellationTokenSource().Token;
var callExpression = BuildExpression(x => x.CancelAllMediaOperationsAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()));
var callExpression = BuildExpression(x => x.CancelAllMediaOperationsAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()));

mockClient
.Setup(callExpression)
.ReturnsAsync((string callLegId, string operationContext, CancellationToken token) =>
{
Assert.AreEqual(expectedCallLegId, callLegId);
Assert.AreEqual(expectedOperationContext, operationContext);
Assert.AreEqual(cancellationToken, token);
return expectedResponse = new Mock<Response<CancelAllMediaOperationsResponse>>().Object;
});

Response<CancelAllMediaOperationsResponse> actualResponse = await mockClient.Object.CancelAllMediaOperationsAsync(expectedCallLegId, cancellationToken);
Response<CancelAllMediaOperationsResponse> actualResponse = await mockClient.Object.CancelAllMediaOperationsAsync(expectedCallLegId, expectedOperationContext, cancellationToken);

mockClient.Verify(callExpression, Times.Once());
Assert.AreEqual(expectedResponse, actualResponse);
Expand Down Expand Up @@ -161,7 +162,7 @@ public async Task PlayAudioAsyncOverload_Passes(string expectedCallLegId, Uri ex
}

[TestCaseSource(nameof(TestData_InviteParticipants))]
public async Task InviteParticipantsAsyncOverload_Passes(string expectedCallLegId, CommunicationIdentifier expectedParticipant, string expectedOperationContext, string? expectedAlternateCallerId = null)
public async Task InviteParticipantsAsyncOverload_Passes(string expectedCallLegId, CommunicationIdentifier expectedParticipant, string expectedAlternateCallerId, string expectedOperationContext)
{
Mock<CallClient> mockClient = new Mock<CallClient>() { CallBase = true };
Response? expectedResponse = default;
Expand All @@ -170,7 +171,7 @@ public async Task InviteParticipantsAsyncOverload_Passes(string expectedCallLegI

mockClient
.Setup(callExpression)
.ReturnsAsync((string callLegId, IEnumerable<CommunicationIdentifier> participants, string operationContext, string alternateCallerId, CancellationToken token) =>
.ReturnsAsync((string callLegId, CommunicationIdentifier participants, string operationContext, string alternateCallerId, CancellationToken token) =>
{
Assert.AreEqual(expectedCallLegId, callLegId);
Assert.AreEqual(expectedParticipant, participants);
Expand Down Expand Up @@ -221,11 +222,12 @@ public async Task RemoveParticipantAsyncOverload_Passes(string expectedCallLegId
};
}

private static IEnumerable<object?[]> TestData_CancelMediaOperations()
private static IEnumerable<object?[]> TestData_CancelAllMediaOperations()
{
return new List<object?[]>(){
new object?[] {
"4ab31d78-a189-4e50-afaa-f9610975b6cb",
"af82480b-6df3-4f4c-a58c-a6a78b614b36"
},
};
}
Expand Down Expand Up @@ -275,15 +277,15 @@ public async Task RemoveParticipantAsyncOverload_Passes(string expectedCallLegId
return new List<object?[]>(){
new object?[] {
"4ab31d78-a189-4e50-afaa-f9610975b6cb",
new List<CommunicationIdentifier>() { new PhoneNumberIdentifier("+14052882361"), new CommunicationUserIdentifier("50125645-5dca-4193-877d-4608ed2a0bc2"), },
"af82480b-6df3-4f4c-a58c-a6a78b614b36",
"+14052882362"
new CommunicationUserIdentifier("50125645-5dca-4193-877d-4608ed2a0bc2"),
"+14052882362",
"af82480b-6df3-4f4c-a58c-a6a78b614b36"
},
new object?[] {
"4ab31d78-a189-4e50-afaa-f9610975b6cb",
new List<CommunicationIdentifier>() { new PhoneNumberIdentifier("+14052882361"), new CommunicationUserIdentifier("50125645-5dca-4193-877d-4608ed2a0bc2"), },
"af82480b-6df3-4f4c-a58c-a6a78b614b36",
null
new CommunicationUserIdentifier("50125645-5dca-4193-877d-4608ed2a0bc2"),
null,
"af82480b-6df3-4f4c-a58c-a6a78b614b36"
},
};
}
Expand Down

0 comments on commit abba988

Please sign in to comment.