Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use call invite in redirect and fix tests #34037

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public CallAutomationClient(System.Uri pmaEndpoint, string connectionString, Azu
public virtual Azure.Communication.CallAutomation.EventProcessor GetEventProcessor() { throw null; }
public virtual Azure.Communication.CommunicationUserIdentifier GetSourceIdentity() { throw null; }
public virtual Azure.Response RedirectCall(Azure.Communication.CallAutomation.RedirectCallOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response RedirectCall(string incomingCallContext, Azure.Communication.CommunicationIdentifier target, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response RedirectCall(string incomingCallContext, Azure.Communication.CallAutomation.CallInvite callInvite, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> RedirectCallAsync(Azure.Communication.CallAutomation.RedirectCallOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> RedirectCallAsync(string incomingCallContext, Azure.Communication.CommunicationIdentifier target, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> RedirectCallAsync(string incomingCallContext, Azure.Communication.CallAutomation.CallInvite callInvite, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response RejectCall(Azure.Communication.CallAutomation.RejectCallOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response RejectCall(string incomingCallContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> RejectCallAsync(Azure.Communication.CallAutomation.RejectCallOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -863,9 +863,9 @@ internal RecordingStateResult() { }
}
public partial class RedirectCallOptions
{
public RedirectCallOptions(string incomingCallContext, Azure.Communication.CommunicationIdentifier target) { }
public RedirectCallOptions(string incomingCallContext, Azure.Communication.CallAutomation.CallInvite callInvite) { }
public Azure.Communication.CallAutomation.CallInvite CallInvite { get { throw null; } }
public string IncomingCallContext { get { throw null; } }
public Azure.Communication.CommunicationIdentifier Target { get { throw null; } }
}
public partial class RejectCallOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ private static AnswerCallRequestInternal CreateAnswerCallRequest(AnswerCallOptio
}

/// Redirect an incoming call to the target identity.
/// <param name="incomingCallContext"> The incoming call context </param>
/// <param name="target"> The target identity. </param>
/// <param name="incomingCallContext"> The incoming call context. </param>
/// <param name="callInvite"> The target where the call is redirected to. </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>
/// <exception cref="ArgumentNullException"><paramref name="incomingCallContext"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
public virtual async Task<Response> RedirectCallAsync(string incomingCallContext, CommunicationIdentifier target, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="callInvite"/> is null.</exception>
public virtual async Task<Response> RedirectCallAsync(string incomingCallContext, CallInvite callInvite, CancellationToken cancellationToken = default)
{
RedirectCallOptions options = new RedirectCallOptions(incomingCallContext, target);
RedirectCallOptions options = new RedirectCallOptions(incomingCallContext, callInvite);

return await RedirectCallAsync(options, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -269,7 +269,7 @@ public virtual async Task<Response> RedirectCallAsync(RedirectCallOptions option
if (options == null)
throw new ArgumentNullException(nameof(options));

RedirectCallRequestInternal request = new RedirectCallRequestInternal(options.IncomingCallContext, CommunicationIdentifierSerializer.Serialize(options.Target));
RedirectCallRequestInternal request = new RedirectCallRequestInternal(options.IncomingCallContext, CommunicationIdentifierSerializer.Serialize(options.CallInvite.Target));
var repeatabilityHeaders = new RepeatabilityHeaders();

return await AzureCommunicationServicesRestClient.RedirectCallAsync(
Expand All @@ -288,14 +288,14 @@ public virtual async Task<Response> RedirectCallAsync(RedirectCallOptions option

/// Redirect an incoming call to the target identities.
/// <param name="incomingCallContext"> The incoming call context </param>
/// <param name="target"> The target identities. </param>
/// <param name="callInvite"> The target where the call is redirected to. </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>
/// <exception cref="ArgumentNullException"><paramref name="incomingCallContext"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
public virtual Response RedirectCall(string incomingCallContext, CommunicationIdentifier target, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="callInvite"/> is null.</exception>
public virtual Response RedirectCall(string incomingCallContext, CallInvite callInvite, CancellationToken cancellationToken = default)
{
RedirectCallOptions options = new RedirectCallOptions(incomingCallContext, target);
RedirectCallOptions options = new RedirectCallOptions(incomingCallContext, callInvite);

return RedirectCall(options, cancellationToken);
}
Expand All @@ -315,7 +315,7 @@ public virtual Response RedirectCall(RedirectCallOptions options, CancellationTo
if (options == null)
throw new ArgumentNullException(nameof(options));

RedirectCallRequestInternal request = new RedirectCallRequestInternal(options.IncomingCallContext, CommunicationIdentifierSerializer.Serialize(options.Target));
RedirectCallRequestInternal request = new RedirectCallRequestInternal(options.IncomingCallContext, CommunicationIdentifierSerializer.Serialize(options.CallInvite.Target));
var repeatabilityHeaders = new RepeatabilityHeaders();

return AzureCommunicationServicesRestClient.RedirectCall(
Expand Down Expand Up @@ -430,45 +430,9 @@ public virtual Response RejectCall(RejectCallOptions options, CancellationToken
/// <returns></returns>
public virtual async Task<Response<CreateCallResult>> CreateCallAsync(CallInvite callInvite, Uri callbackUri, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallAutomationClient)}.{nameof(CreateCall)}");
scope.Start();
try
{
if (callInvite == null)
{
throw new ArgumentNullException(nameof(callInvite));
}
CreateCallOptions options = new CreateCallOptions(callInvite, callbackUri);

if (callbackUri == null)
{
throw new ArgumentNullException(nameof(callbackUri));
}

var createCallOptions = new CreateCallOptions(callInvite, callbackUri);

CreateCallRequestInternal request = CreateCallRequest(createCallOptions);
var repeatabilityHeaders = new RepeatabilityHeaders();

var createCallResponse = await AzureCommunicationServicesRestClient.CreateCallAsync(
request,
repeatabilityHeaders.RepeatabilityRequestId,
repeatabilityHeaders.GetRepeatabilityFirstSentString(),
cancellationToken
).ConfigureAwait(false);

var result = new CreateCallResult(
GetCallConnection(createCallResponse.Value.CallConnectionId),
new CallConnectionProperties(createCallResponse.Value));
result.SetEventProcessor(EventProcessor, createCallResponse.Value.CallConnectionId, request.OperationContext);

return Response.FromValue(result,
createCallResponse.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
return await CreateCallAsync(options, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -523,45 +487,9 @@ public virtual async Task<Response<CreateCallResult>> CreateCallAsync(CreateCall
/// <returns></returns>
public virtual Response<CreateCallResult> CreateCall(CallInvite callInvite, Uri callbackUri, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallAutomationClient)}.{nameof(CreateCall)}");
scope.Start();
try
{
if (callInvite == null)
{
throw new ArgumentNullException(nameof(callInvite));
}

if (callbackUri == null)
{
throw new ArgumentNullException(nameof(callbackUri));
}

var createCallOptions = new CreateCallOptions(callInvite, callbackUri);

CreateCallRequestInternal request = CreateCallRequest(createCallOptions);
var repeatabilityHeaders = new RepeatabilityHeaders();

var createCallResponse = AzureCommunicationServicesRestClient.CreateCall(
request,
repeatabilityHeaders.RepeatabilityRequestId,
repeatabilityHeaders.GetRepeatabilityFirstSentString(),
cancellationToken
);

var result = new CreateCallResult(
GetCallConnection(createCallResponse.Value.CallConnectionId),
new CallConnectionProperties(createCallResponse.Value));
result.SetEventProcessor(EventProcessor, createCallResponse.Value.CallConnectionId, request.OperationContext);
CreateCallOptions options = new CreateCallOptions(callInvite, callbackUri);

return Response.FromValue(result,
createCallResponse.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
return CreateCall(options, cancellationToken);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class RedirectCallOptions
/// Creates a new RedirectCallOptions object.
/// </summary>
/// <param name="incomingCallContext"></param>
/// <param name="target"></param>
public RedirectCallOptions(string incomingCallContext, CommunicationIdentifier target)
/// <param name="callInvite"></param>
public RedirectCallOptions(string incomingCallContext, CallInvite callInvite)
{
IncomingCallContext = incomingCallContext;
Target = target;
CallInvite = callInvite;
}

/// <summary>
Expand All @@ -27,8 +27,8 @@ public RedirectCallOptions(string incomingCallContext, CommunicationIdentifier t
public string IncomingCallContext { get; }

/// <summary>
/// The target identity.
/// Call invitee information.
/// </summary>
public CommunicationIdentifier Target { get; }
public CallInvite CallInvite { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,41 +128,41 @@ public void AnswerCall_401AuthFailed(string incomingCallContext, Uri callbackUri
}

[TestCaseSource(nameof(TestData_RedirectCall))]
public async Task RedirectCallAsync_204NoContent(string incomingCallContext, CommunicationIdentifier target)
public async Task RedirectCallAsync_204NoContent(string incomingCallContext, CallInvite callInvite)
{
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(204);

var response = await callAutomationClient.RedirectCallAsync(incomingCallContext, target).ConfigureAwait(false);
var response = await callAutomationClient.RedirectCallAsync(incomingCallContext, callInvite).ConfigureAwait(false);
Assert.NotNull(response);
Assert.AreEqual((int)HttpStatusCode.NoContent, response.Status);
}

[TestCaseSource(nameof(TestData_RedirectCall))]
public void RedirectCall_204NoContent(string incomingCallContext, CommunicationIdentifier target)
public void RedirectCall_204NoContent(string incomingCallContext, CallInvite callInvite)
{
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(204);

var response = callAutomationClient.RedirectCall(incomingCallContext, target);
var response = callAutomationClient.RedirectCall(incomingCallContext, callInvite);
Assert.NotNull(response);
Assert.AreEqual((int)HttpStatusCode.NoContent, response.Status);
}

[TestCaseSource(nameof(TestData_RedirectCall))]
public void RedirectCallAsync_404NotFound(string incomingCallContext, CommunicationIdentifier target)
public void RedirectCallAsync_404NotFound(string incomingCallContext, CallInvite callInvite)
{
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(404);

RequestFailedException? ex = Assert.ThrowsAsync<RequestFailedException>(async() => await callAutomationClient.RedirectCallAsync(incomingCallContext, target).ConfigureAwait(false));
RequestFailedException? ex = Assert.ThrowsAsync<RequestFailedException>(async() => await callAutomationClient.RedirectCallAsync(incomingCallContext, callInvite).ConfigureAwait(false));
Assert.NotNull(ex);
Assert.AreEqual(ex?.Status, 404);
}

[TestCaseSource(nameof(TestData_RedirectCall))]
public void RedirectCall_404NotFound(string incomingCallContext, CommunicationIdentifier target)
public void RedirectCall_404NotFound(string incomingCallContext, CallInvite callInvite)
{
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(404);

RequestFailedException? ex = Assert.Throws<RequestFailedException>(() => callAutomationClient.RedirectCall(incomingCallContext, target));
RequestFailedException? ex = Assert.Throws<RequestFailedException>(() => callAutomationClient.RedirectCall(incomingCallContext, callInvite));
Assert.NotNull(ex);
Assert.AreEqual(ex?.Status, 404);
}
Expand Down Expand Up @@ -402,7 +402,7 @@ private static void ValidateCallConnectionProperties(CallConnectionProperties pr
new object?[]
{
"dummyIncomingCallContext",
new CommunicationUserIdentifier("12345")
new CallInvite(new CommunicationUserIdentifier("12345"))
},
};
}
Expand Down