Skip to content

Commit

Permalink
refactor: [breaking] remove sync methods from RedactClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Mar 14, 2024
1 parent fe7a4c1 commit 6e07991
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 72 deletions.
63 changes: 15 additions & 48 deletions Vonage.Test/RedactTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,6 @@ namespace Vonage.Test;
[Trait("Category", "Legacy")]
public class RedactTests : TestBase
{
[Theory]
[InlineData(true, RedactionProduct.Sms, RedactionType.Inbound)]
[InlineData(false, RedactionProduct.Sms, RedactionType.Inbound)]
[InlineData(false, RedactionProduct.Sms, RedactionType.Outbound)]
[InlineData(false, RedactionProduct.Messages, RedactionType.Inbound)]
[InlineData(false, RedactionProduct.Messages, RedactionType.Outbound)]
[InlineData(false, RedactionProduct.NumberInsight, RedactionType.Inbound)]
[InlineData(false, RedactionProduct.NumberInsight, RedactionType.Outbound)]
[InlineData(false, RedactionProduct.Verify, RedactionType.Inbound)]
[InlineData(false, RedactionProduct.Verify, RedactionType.Outbound)]
[InlineData(false, RedactionProduct.VerifySdk, RedactionType.Inbound)]
[InlineData(false, RedactionProduct.VerifySdk, RedactionType.Outbound)]
[InlineData(false, RedactionProduct.Voice, RedactionType.Inbound)]
[InlineData(false, RedactionProduct.Voice, RedactionType.Outbound)]
public void Redact(bool passCredentials, RedactionProduct product, RedactionType type)
{
//ARRANGE
var request = new RedactRequest
{
Id = "test",
Product = product,
Type = type,
};
var expectedResponseContent = this.GetResponseJson();
var expectedUri = $"{this.ApiUrl}/v1/redact/transaction";
this.Setup(expectedUri, expectedResponseContent);

//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var response = client.RedactClient.Redact(request, passCredentials ? creds : null);

//ASSERT
Assert.True(response);
}

[Theory]
[InlineData(true, RedactionProduct.Sms, RedactionType.Inbound)]
[InlineData(false, RedactionProduct.Sms, RedactionType.Inbound)]
Expand Down Expand Up @@ -83,7 +47,7 @@ public async Task RedactAsync(bool passCredentials, RedactionProduct product, Re
}

[Fact]
public void RedactReturns401()
public async Task RedactReturns401()
{
//ARRANGE
var request = new RedactRequest
Expand All @@ -99,15 +63,16 @@ public void RedactReturns401()
//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var exception = Assert.Throws<VonageHttpRequestException>(() => client.RedactClient.Redact(request));
var exception =
await Assert.ThrowsAsync<VonageHttpRequestException>(() => client.RedactClient.RedactAsync(request));

//ASSERT
Assert.NotNull(exception);
Assert.Equal(expectedResponseContent, exception.Json);
}

[Fact]
public void RedactReturns403()
public async Task RedactReturns403()
{
//ARRANGE
var request = new RedactRequest
Expand All @@ -123,15 +88,16 @@ public void RedactReturns403()
//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var exception = Assert.Throws<VonageHttpRequestException>(() => client.RedactClient.Redact(request));
var exception =
await Assert.ThrowsAsync<VonageHttpRequestException>(() => client.RedactClient.RedactAsync(request));

//ASSERT
Assert.NotNull(exception);
Assert.Equal(expectedResponseContent, exception.Json);
}

[Fact]
public void RedactReturns404()
public async Task RedactReturns404()
{
//ARRANGE
var request = new RedactRequest
Expand All @@ -147,16 +113,16 @@ public void RedactReturns404()
//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var exception = Assert.Throws<VonageHttpRequestException>(() => client.RedactClient.Redact(request));
var exception =
await Assert.ThrowsAsync<VonageHttpRequestException>(() => client.RedactClient.RedactAsync(request));

//ASSERT
Assert.NotNull(exception);
Assert.Equal(expectedResponseContent, exception.Json);
}

#if (NETCOREAPP2_1_OR_GREATER)
[Fact]
public void RedactReturns422()
public async Task RedactReturns422()
{
//ARRANGE
var request = new RedactRequest
Expand All @@ -172,15 +138,16 @@ public void RedactReturns422()
//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var exception = Assert.Throws<VonageHttpRequestException>(() => client.RedactClient.Redact(request));
var exception =
await Assert.ThrowsAsync<VonageHttpRequestException>(() => client.RedactClient.RedactAsync(request));

//ASSERT
Assert.NotNull(exception);
Assert.Equal(expectedResponseContent, exception.Json);
}

[Fact]
public void RedactReturns429()
public async Task RedactReturns429()
{
//ARRANGE
var request = new RedactRequest
Expand All @@ -196,11 +163,11 @@ public void RedactReturns429()
//ACT
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
var client = this.BuildVonageClient(creds);
var exception = Assert.Throws<VonageHttpRequestException>(() => client.RedactClient.Redact(request));
var exception =
await Assert.ThrowsAsync<VonageHttpRequestException>(() => client.RedactClient.RedactAsync(request));

//ASSERT
Assert.NotNull(exception);
Assert.Equal(expectedResponseContent, exception.Json);
}
#endif
}
8 changes: 0 additions & 8 deletions Vonage/Redaction/IRedactClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,4 @@ public interface IRedactClient
/// <param name="creds"></param>
/// <returns></returns>
Task<bool> RedactAsync(RedactRequest request, Credentials creds = null);

/// <summary>
/// Redact a specific message
/// </summary>
/// <param name="request"></param>
/// <param name="creds"></param>
/// <returns></returns>
bool Redact(RedactRequest request, Credentials creds = null);
}
16 changes: 0 additions & 16 deletions Vonage/Redaction/RedactClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Vonage.Common;
Expand Down Expand Up @@ -26,21 +25,6 @@ internal RedactClient(Credentials credentials, Configuration configuration, ITim

public Credentials Credentials { get; set; }

/// <inheritdoc/>
[Obsolete("Favor asynchronous version instead.")]
public bool Redact(RedactRequest request, Credentials creds = null)
{
ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider)
.DoRequestWithJsonContent<object>
(
HttpMethod.Post,
ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, "/v1/redact/transaction"),
request,
AuthType.Basic
);
return true;
}

/// <inheritdoc/>
public async Task<bool> RedactAsync(RedactRequest request, Credentials creds = null)
{
Expand Down

0 comments on commit 6e07991

Please sign in to comment.