Skip to content

Commit

Permalink
Add new live tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FarhadJabiyev committed Nov 26, 2024
1 parent b5e3b86 commit d3f9ea8
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 49 deletions.
36 changes: 18 additions & 18 deletions sdk/communication/Azure.Communication.Sms/src/OptOutsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ protected OptOutsClient()
/// <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="from"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
public virtual async Task<Response<OptOutResponse>> CheckAsync(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
public virtual async Task<Response<IReadOnlyList<OptOutResponseItem>>> CheckAsync(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SmsClient)}.{nameof(OptOutsClient)}.{nameof(CheckAsync)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(OptOutsClient)}.{nameof(Check)}");
scope.Start();
try
{
Expand All @@ -58,7 +58,7 @@ public virtual async Task<Response<OptOutResponse>> CheckAsync(string from, IEnu
IEnumerable<OptOutRecipient> recipients = to.Select(x => new OptOutRecipient(Argument.CheckNotNullOrEmpty(x, nameof(to))));

Response<OptOutResponse> response = await OptOutsRestClient.CheckAsync(from, recipients, cancellationToken).ConfigureAwait(false);
return Response.FromValue(response.Value, response.GetRawResponse());
return Response.FromValue(response.Value.Value, response.GetRawResponse());
}
catch (Exception ex)
{
Expand All @@ -76,9 +76,9 @@ public virtual async Task<Response<OptOutResponse>> CheckAsync(string from, IEnu
/// <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="from"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
public virtual Response<OptOutResponse> Check(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
public virtual Response<IReadOnlyList<OptOutResponseItem>> Check(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SmsClient)}.{nameof(OptOutsClient)}.{nameof(Check)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(OptOutsClient)}.{nameof(Check)}");
scope.Start();
try
{
Expand All @@ -88,7 +88,7 @@ public virtual Response<OptOutResponse> Check(string from, IEnumerable<string> t
IEnumerable<OptOutRecipient> recipients = to.Select(x => new OptOutRecipient(Argument.CheckNotNullOrEmpty(x, nameof(to))));

Response<OptOutResponse> response = OptOutsRestClient.Check(from, recipients, cancellationToken);
return Response.FromValue(response.Value, response.GetRawResponse());
return Response.FromValue(response.Value.Value, response.GetRawResponse());
}
catch (Exception ex)
{
Expand All @@ -106,9 +106,9 @@ public virtual Response<OptOutResponse> Check(string from, IEnumerable<string> t
/// <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="from"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
public virtual async Task<Response<OptOutChangeResponse>> AddAsync(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
public virtual async Task<Response<IReadOnlyList<OptOutChangeResponseItem>>> AddAsync(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SmsClient)}.{nameof(OptOutsClient)}.{nameof(AddAsync)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(OptOutsClient)}.{nameof(Add)}");
scope.Start();
try
{
Expand All @@ -119,7 +119,7 @@ public virtual async Task<Response<OptOutChangeResponse>> AddAsync(string from,
Response<OptOutResponse> response = await OptOutsRestClient.AddAsync(from, recipients, cancellationToken).ConfigureAwait(false);
OptOutChangeResponse result = new OptOutChangeResponse(response.Value.Value.Select(r => new OptOutChangeResponseItem(r.To, r.HttpStatusCode, r.ErrorMessage)));

return Response.FromValue(result, response.GetRawResponse());
return Response.FromValue(result.Value, response.GetRawResponse());
}
catch (Exception ex)
{
Expand All @@ -137,9 +137,9 @@ public virtual async Task<Response<OptOutChangeResponse>> AddAsync(string from,
/// <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="from"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
public virtual Response<OptOutChangeResponse> Add(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
public virtual Response<IReadOnlyList<OptOutChangeResponseItem>> Add(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SmsClient)}.{nameof(OptOutsClient)}.{nameof(Add)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(OptOutsClient)}.{nameof(Add)}");
scope.Start();
try
{
Expand All @@ -150,7 +150,7 @@ public virtual Response<OptOutChangeResponse> Add(string from, IEnumerable<strin
Response<OptOutResponse> response = OptOutsRestClient.Add(from, recipients, cancellationToken);
OptOutChangeResponse result = new OptOutChangeResponse(response.Value.Value.Select(r => new OptOutChangeResponseItem(r.To, r.HttpStatusCode, r.ErrorMessage)));

return Response.FromValue(result, response.GetRawResponse());
return Response.FromValue(result.Value, response.GetRawResponse());
}
catch (Exception ex)
{
Expand All @@ -168,9 +168,9 @@ public virtual Response<OptOutChangeResponse> Add(string from, IEnumerable<strin
/// <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="from"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
public virtual async Task<Response<OptOutChangeResponse>> RemoveAsync(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
public virtual async Task<Response<IReadOnlyList<OptOutChangeResponseItem>>> RemoveAsync(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SmsClient)}.{nameof(OptOutsClient)}.{nameof(RemoveAsync)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(OptOutsClient)}.{nameof(Remove)}");
scope.Start();
try
{
Expand All @@ -181,7 +181,7 @@ public virtual async Task<Response<OptOutChangeResponse>> RemoveAsync(string fro
Response<OptOutResponse> response = await OptOutsRestClient.RemoveAsync(from, recipients, cancellationToken).ConfigureAwait(false);
OptOutChangeResponse result = new OptOutChangeResponse(response.Value.Value.Select(r => new OptOutChangeResponseItem(r.To, r.HttpStatusCode, r.ErrorMessage)));

return Response.FromValue(result, response.GetRawResponse());
return Response.FromValue(result.Value, response.GetRawResponse());
}
catch (Exception ex)
{
Expand All @@ -199,9 +199,9 @@ public virtual async Task<Response<OptOutChangeResponse>> RemoveAsync(string fro
/// <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="from"/> is null.</exception>
/// <exception cref="ArgumentNullException"><paramref name="to"/> is null.</exception>
public virtual Response<OptOutChangeResponse> Remove(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
public virtual Response<IReadOnlyList<OptOutChangeResponseItem>> Remove(string from, IEnumerable<string> to, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(SmsClient)}.{nameof(OptOutsClient)}.{nameof(Remove)}");
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(OptOutsClient)}.{nameof(Remove)}");
scope.Start();
try
{
Expand All @@ -212,7 +212,7 @@ public virtual Response<OptOutChangeResponse> Remove(string from, IEnumerable<st
Response<OptOutResponse> response = OptOutsRestClient.Remove(from, recipients, cancellationToken);
OptOutChangeResponse result = new OptOutChangeResponse(response.Value.Value.Select(r => new OptOutChangeResponseItem(r.To, r.HttpStatusCode, r.ErrorMessage)));

return Response.FromValue(result, response.GetRawResponse());
return Response.FromValue(result.Value, response.GetRawResponse());
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -47,7 +46,7 @@ public void OptOutsClient_ThrowsWithNullEndpoint()
public async Task CheckAsyncOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<string> expectedTo)
{
Mock<OptOutsClient> mockClient = new Mock<OptOutsClient>() { CallBase = true };
Response<OptOutResponse>? expectedResponse = default;
Response<IReadOnlyList<OptOutResponseItem>>? expectedResponse = default;
CancellationToken cancellationToken = new CancellationTokenSource().Token;
var callExpression = BuildExpression(x => x.CheckAsync(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<CancellationToken>()));

Expand All @@ -58,10 +57,10 @@ public async Task CheckAsyncOverload_PassesToGeneratedOne(string expectedFrom, I
Assert.AreEqual(expectedFrom, from);
Assert.AreEqual(expectedTo, to);
Assert.AreEqual(cancellationToken, token);
return expectedResponse = new Mock<Response<OptOutResponse>>().Object;
return expectedResponse = new Mock<Response<IReadOnlyList<OptOutResponseItem>>>().Object;
});

Response<OptOutResponse> actualResponse = await mockClient.Object.CheckAsync(expectedFrom, expectedTo, cancellationToken);
Response<IReadOnlyList<OptOutResponseItem>> actualResponse = await mockClient.Object.CheckAsync(expectedFrom, expectedTo, cancellationToken);

mockClient.Verify(callExpression, Times.Once());
Assert.AreEqual(expectedResponse, actualResponse);
Expand All @@ -71,7 +70,7 @@ public async Task CheckAsyncOverload_PassesToGeneratedOne(string expectedFrom, I
public void CheckOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<string> expectedTo)
{
Mock<OptOutsClient> mockClient = new Mock<OptOutsClient>() { CallBase = true };
Response<OptOutResponse>? expectedResponse = default;
Response<IReadOnlyList<OptOutResponseItem>>? expectedResponse = default;
CancellationToken cancellationToken = new CancellationTokenSource().Token;
var callExpression = BuildExpression(x => x.Check(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<CancellationToken>()));

Expand All @@ -82,10 +81,10 @@ public void CheckOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<
Assert.AreEqual(expectedFrom, from);
Assert.AreEqual(expectedTo, to);
Assert.AreEqual(cancellationToken, token);
return expectedResponse = new Mock<Response<OptOutResponse>>().Object;
return expectedResponse = new Mock<Response<IReadOnlyList<OptOutResponseItem>>>().Object;
});

Response<OptOutResponse> actualResponse = mockClient.Object.Check(expectedFrom, expectedTo, cancellationToken);
Response<IReadOnlyList<OptOutResponseItem>> actualResponse = mockClient.Object.Check(expectedFrom, expectedTo, cancellationToken);

mockClient.Verify(callExpression, Times.Once());
Assert.AreEqual(expectedResponse, actualResponse);
Expand All @@ -95,7 +94,7 @@ public void CheckOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<
public async Task AddAsyncOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<string> expectedTo)
{
Mock<OptOutsClient> mockClient = new Mock<OptOutsClient>() { CallBase = true };
Response<OptOutChangeResponse>? expectedResponse = default;
Response<IReadOnlyList<OptOutChangeResponseItem>>? expectedResponse = default;
CancellationToken cancellationToken = new CancellationTokenSource().Token;
var callExpression = BuildExpression(x => x.AddAsync(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<CancellationToken>()));

Expand All @@ -106,10 +105,10 @@ public async Task AddAsyncOverload_PassesToGeneratedOne(string expectedFrom, IEn
Assert.AreEqual(expectedFrom, from);
Assert.AreEqual(expectedTo, to);
Assert.AreEqual(cancellationToken, token);
return expectedResponse = new Mock<Response<OptOutChangeResponse>>().Object;
return expectedResponse = new Mock<Response<IReadOnlyList<OptOutChangeResponseItem>>>().Object;
});

Response<OptOutChangeResponse> actualResponse = await mockClient.Object.AddAsync(expectedFrom, expectedTo, cancellationToken);
Response<IReadOnlyList<OptOutChangeResponseItem>> actualResponse = await mockClient.Object.AddAsync(expectedFrom, expectedTo, cancellationToken);

mockClient.Verify(callExpression, Times.Once());
Assert.AreEqual(expectedResponse, actualResponse);
Expand All @@ -119,7 +118,7 @@ public async Task AddAsyncOverload_PassesToGeneratedOne(string expectedFrom, IEn
public void AddOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<string> expectedTo)
{
Mock<OptOutsClient> mockClient = new Mock<OptOutsClient>() { CallBase = true };
Response<OptOutChangeResponse>? expectedResponse = default;
Response<IReadOnlyList<OptOutChangeResponseItem>>? expectedResponse = default;
CancellationToken cancellationToken = new CancellationTokenSource().Token;
var callExpression = BuildExpression(x => x.Add(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<CancellationToken>()));

Expand All @@ -130,10 +129,10 @@ public void AddOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<st
Assert.AreEqual(expectedFrom, from);
Assert.AreEqual(expectedTo, to);
Assert.AreEqual(cancellationToken, token);
return expectedResponse = new Mock<Response<OptOutChangeResponse>>().Object;
return expectedResponse = new Mock<Response<IReadOnlyList<OptOutChangeResponseItem>>>().Object;
});

Response<OptOutChangeResponse> actualResponse = mockClient.Object.Add(expectedFrom, expectedTo, cancellationToken);
Response<IReadOnlyList<OptOutChangeResponseItem>> actualResponse = mockClient.Object.Add(expectedFrom, expectedTo, cancellationToken);

mockClient.Verify(callExpression, Times.Once());
Assert.AreEqual(expectedResponse, actualResponse);
Expand All @@ -143,7 +142,7 @@ public void AddOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<st
public async Task RemoveAsyncOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<string> expectedTo)
{
Mock<OptOutsClient> mockClient = new Mock<OptOutsClient>() { CallBase = true };
Response<OptOutChangeResponse>? expectedResponse = default;
Response<IReadOnlyList<OptOutChangeResponseItem>>? expectedResponse = default;
CancellationToken cancellationToken = new CancellationTokenSource().Token;
var callExpression = BuildExpression(x => x.RemoveAsync(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<CancellationToken>()));

Expand All @@ -154,10 +153,10 @@ public async Task RemoveAsyncOverload_PassesToGeneratedOne(string expectedFrom,
Assert.AreEqual(expectedFrom, from);
Assert.AreEqual(expectedTo, to);
Assert.AreEqual(cancellationToken, token);
return expectedResponse = new Mock<Response<OptOutChangeResponse>>().Object;
return expectedResponse = new Mock<Response<IReadOnlyList<OptOutChangeResponseItem>>>().Object;
});

Response<OptOutChangeResponse> actualResponse = await mockClient.Object.RemoveAsync(expectedFrom, expectedTo, cancellationToken);
Response<IReadOnlyList<OptOutChangeResponseItem>> actualResponse = await mockClient.Object.RemoveAsync(expectedFrom, expectedTo, cancellationToken);

mockClient.Verify(callExpression, Times.Once());
Assert.AreEqual(expectedResponse, actualResponse);
Expand All @@ -167,7 +166,7 @@ public async Task RemoveAsyncOverload_PassesToGeneratedOne(string expectedFrom,
public void RemoveOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable<string> expectedTo)
{
Mock<OptOutsClient> mockClient = new Mock<OptOutsClient>() { CallBase = true };
Response<OptOutChangeResponse>? expectedResponse = default;
Response<IReadOnlyList<OptOutChangeResponseItem>>? expectedResponse = default;
CancellationToken cancellationToken = new CancellationTokenSource().Token;
var callExpression = BuildExpression(x => x.Remove(It.IsAny<string>(), It.IsAny<IEnumerable<string>>(), It.IsAny<CancellationToken>()));

Expand All @@ -178,10 +177,10 @@ public void RemoveOverload_PassesToGeneratedOne(string expectedFrom, IEnumerable
Assert.AreEqual(expectedFrom, from);
Assert.AreEqual(expectedTo, to);
Assert.AreEqual(cancellationToken, token);
return expectedResponse = new Mock<Response<OptOutChangeResponse>>().Object;
return expectedResponse = new Mock<Response<IReadOnlyList<OptOutChangeResponseItem>>>().Object;
});

Response<OptOutChangeResponse> actualResponse = mockClient.Object.Remove(expectedFrom, expectedTo, cancellationToken);
Response<IReadOnlyList<OptOutChangeResponseItem>> actualResponse = mockClient.Object.Remove(expectedFrom, expectedTo, cancellationToken);

mockClient.Verify(callExpression, Times.Once());
Assert.AreEqual(expectedResponse, actualResponse);
Expand Down
Loading

0 comments on commit d3f9ea8

Please sign in to comment.