Skip to content

Commit 48b37c8

Browse files
RejectReason to be optional for Reject (Azure#31797)
* RejectionReason now optional * Update API * Update API * Fixing tests Co-authored-by: Min Woo Lee 🧊 <[email protected]>
1 parent 08a9098 commit 48b37c8

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

sdk/communication/Azure.Communication.CallAutomation/api/Azure.Communication.CallAutomation.netstandard2.0.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public CallAutomationClient(System.Uri pmaEndpoint, string connectionString, Azu
6161
public virtual System.Threading.Tasks.Task<Azure.Response> RedirectCallAsync(Azure.Communication.CallAutomation.RedirectCallOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
6262
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; }
6363
public virtual Azure.Response RejectCall(Azure.Communication.CallAutomation.RejectCallOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
64-
public virtual Azure.Response RejectCall(string incomingCallContext, Azure.Communication.CallAutomation.CallRejectReason callRejectReason, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
64+
public virtual Azure.Response RejectCall(string incomingCallContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
6565
public virtual System.Threading.Tasks.Task<Azure.Response> RejectCallAsync(Azure.Communication.CallAutomation.RejectCallOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
66-
public virtual System.Threading.Tasks.Task<Azure.Response> RejectCallAsync(string incomingCallContext, Azure.Communication.CallAutomation.CallRejectReason callRejectReason, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
66+
public virtual System.Threading.Tasks.Task<Azure.Response> RejectCallAsync(string incomingCallContext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
6767
}
6868
public partial class CallAutomationClientOptions : Azure.Core.ClientOptions
6969
{
@@ -682,8 +682,8 @@ public RedirectCallOptions(string incomingCallContext, Azure.Communication.Commu
682682
}
683683
public partial class RejectCallOptions
684684
{
685-
public RejectCallOptions(string incomingCallContext, Azure.Communication.CallAutomation.CallRejectReason callRejectReason) { }
686-
public Azure.Communication.CallAutomation.CallRejectReason CallRejectReason { get { throw null; } }
685+
public RejectCallOptions(string incomingCallContext) { }
686+
public Azure.Communication.CallAutomation.CallRejectReason CallRejectReason { get { throw null; } set { } }
687687
public string IncomingCallContext { get { throw null; } }
688688
public Azure.Communication.CallAutomation.RepeatabilityHeaders RepeatabilityHeaders { get { throw null; } set { } }
689689
}

sdk/communication/Azure.Communication.CallAutomation/src/CallAutomationClient.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,12 @@ public virtual Response RedirectCall(RedirectCallOptions options, CancellationTo
300300

301301
/// Reject an incoming call.
302302
/// <param name="incomingCallContext"> The incoming call context </param>
303-
/// <param name="callRejectReason"> The reason for rejecting call. </param>
304303
/// <param name="cancellationToken"> The cancellation token. </param>
305304
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
306305
/// <exception cref="ArgumentNullException"><paramref name="incomingCallContext"/> is null.</exception>
307-
public virtual async Task<Response> RejectCallAsync(string incomingCallContext, CallRejectReason callRejectReason, CancellationToken cancellationToken = default)
306+
public virtual async Task<Response> RejectCallAsync(string incomingCallContext, CancellationToken cancellationToken = default)
308307
{
309-
RejectCallOptions options = new RejectCallOptions(incomingCallContext, callRejectReason);
308+
RejectCallOptions options = new RejectCallOptions(incomingCallContext);
310309

311310
return await RejectCallAsync(options, cancellationToken).ConfigureAwait(false);
312311
}
@@ -347,13 +346,12 @@ public virtual async Task<Response> RejectCallAsync(RejectCallOptions options, C
347346

348347
/// Reject an incoming call.
349348
/// <param name="incomingCallContext"> The incoming call context </param>
350-
/// <param name="callRejectReason"> The reason for rejecting call. </param>
351349
/// <param name="cancellationToken"> The cancellation token. </param>
352350
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
353351
/// <exception cref="ArgumentNullException"><paramref name="incomingCallContext"/> is null.</exception>
354-
public virtual Response RejectCall(string incomingCallContext, CallRejectReason callRejectReason, CancellationToken cancellationToken = default)
352+
public virtual Response RejectCall(string incomingCallContext, CancellationToken cancellationToken = default)
355353
{
356-
RejectCallOptions options = new RejectCallOptions(incomingCallContext, callRejectReason);
354+
RejectCallOptions options = new RejectCallOptions(incomingCallContext);
357355

358356
return RejectCall(options, cancellationToken);
359357
}

sdk/communication/Azure.Communication.CallAutomation/src/Models/RejectCallOptions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ public class RejectCallOptions
1414
/// Creates a new RejectCallOptions object.
1515
/// </summary>
1616
/// <param name="incomingCallContext"></param>
17-
/// <param name="callRejectReason"></param>
18-
public RejectCallOptions(string incomingCallContext, CallRejectReason callRejectReason)
17+
public RejectCallOptions(string incomingCallContext)
1918
{
2019
IncomingCallContext = incomingCallContext;
21-
CallRejectReason = callRejectReason;
2220
}
2321

2422
/// <summary>
@@ -29,7 +27,7 @@ public RejectCallOptions(string incomingCallContext, CallRejectReason callReject
2927
/// <summary>
3028
/// The reason for rejecting call.
3129
/// </summary>
32-
public CallRejectReason CallRejectReason { get; }
30+
public CallRejectReason CallRejectReason { get; set; } = CallRejectReason.None;
3331

3432
/// <summary>
3533
/// Repeatability Headers.

sdk/communication/Azure.Communication.CallAutomation/tests/CallAutomationClients/CallAutomationClientAutomatedLiveTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public async Task CreateCallAndReject()
130130
Assert.IsNotNull(incomingCallContext);
131131

132132
// answer the call
133-
var rejectCallOptions = new RejectCallOptions(incomingCallContext, CallRejectReason.None) {
133+
var rejectCallOptions = new RejectCallOptions(incomingCallContext) {
134134
RepeatabilityHeaders = new RepeatabilityHeaders(new Guid("fed6e917-f1df-4e21-b7de-c26d0947124b"), new DateTimeOffset(2022, 9, 19, 22, 20, 00, new TimeSpan(0, 0, 0)))
135135
};
136136
Response rejectResponse = await client.RejectCallAsync(rejectCallOptions);

sdk/communication/Azure.Communication.CallAutomation/tests/CallAutomationClients/CallAutomationClientTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ public async Task RejectCallAsync_204NoContent(string incomingCallContext, CallR
143143
{
144144
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(204);
145145

146-
var response = await callAutomationClient.RejectCallAsync(incomingCallContext, reason).ConfigureAwait(false);
146+
RejectCallOptions rejectOption = new RejectCallOptions(incomingCallContext);
147+
rejectOption.CallRejectReason = reason;
148+
149+
var response = await callAutomationClient.RejectCallAsync(rejectOption).ConfigureAwait(false);
147150
Assert.NotNull(response);
148151
Assert.AreEqual((int)HttpStatusCode.NoContent, response.Status);
149152
}
@@ -153,7 +156,10 @@ public void RejectCall_204NoContent(string incomingCallContext, CallRejectReason
153156
{
154157
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(204);
155158

156-
var response = callAutomationClient.RejectCall(incomingCallContext, reason);
159+
RejectCallOptions rejectOption = new RejectCallOptions(incomingCallContext);
160+
rejectOption.CallRejectReason = reason;
161+
162+
var response = callAutomationClient.RejectCall(rejectOption);
157163
Assert.NotNull(response);
158164
Assert.AreEqual((int)HttpStatusCode.NoContent, response.Status);
159165
}
@@ -163,7 +169,10 @@ public void RejectCallAsync_404NotFound(string incomingCallContext, CallRejectRe
163169
{
164170
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(404);
165171

166-
RequestFailedException? ex = Assert.ThrowsAsync<RequestFailedException>(async() => await callAutomationClient.RejectCallAsync(incomingCallContext, reason).ConfigureAwait(false));
172+
RejectCallOptions rejectOption = new RejectCallOptions(incomingCallContext);
173+
rejectOption.CallRejectReason = reason;
174+
175+
RequestFailedException? ex = Assert.ThrowsAsync<RequestFailedException>(async() => await callAutomationClient.RejectCallAsync(rejectOption).ConfigureAwait(false));
167176
Assert.NotNull(ex);
168177
Assert.AreEqual(ex?.Status, 404);
169178
}
@@ -173,7 +182,10 @@ public void RejectCall_404NotFound(string incomingCallContext, CallRejectReason
173182
{
174183
CallAutomationClient callAutomationClient = CreateMockCallAutomationClient(404);
175184

176-
RequestFailedException? ex = Assert.Throws<RequestFailedException>(() => callAutomationClient.RejectCall(incomingCallContext, reason));
185+
RejectCallOptions rejectOption = new RejectCallOptions(incomingCallContext);
186+
rejectOption.CallRejectReason = reason;
187+
188+
RequestFailedException? ex = Assert.Throws<RequestFailedException>(() => callAutomationClient.RejectCall(rejectOption));
177189
Assert.NotNull(ex);
178190
Assert.AreEqual(ex?.Status, 404);
179191
}

sdk/communication/Azure.Communication.CallAutomation/tests/Misc/RepeatabilityHeadersTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public void RepeatablityHeaders_IsSetByDefault_RedirectCallOptions()
7474
public void RepeatablityHeaders_IsSetByDefault_RejectCallOptions()
7575
{
7676
// arrange
77-
var options = new RejectCallOptions("context", CallRejectReason.Busy);
77+
var options = new RejectCallOptions("context");
78+
options.CallRejectReason = CallRejectReason.Busy;
7879

7980
// act & assert
8081
Assert.IsNotNull(options.RepeatabilityHeaders);

0 commit comments

Comments
 (0)