-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using Vonage.Common.Failures; | ||
using Vonage.Common.Test.Extensions; | ||
using Vonage.VerifyV2.Cancel; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit.VerifyV2.Cancel | ||
{ | ||
public class RequestTest | ||
{ | ||
[Fact] | ||
public void Create_ShouldReturnFailure_GivenRequestIsEmpty() => | ||
CancelRequest.Parse(Guid.Empty) | ||
.Should() | ||
.BeFailure(ResultFailure.FromErrorMessage("RequestId cannot be empty.")); | ||
|
||
[Fact] | ||
public void Create_ShouldReturnSuccess() => | ||
CancelRequest.Parse(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287")) | ||
.Map(request => request.RequestId) | ||
.Should() | ||
.BeSuccess(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287")); | ||
|
||
[Fact] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint() => | ||
CancelRequest.Parse(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287")) | ||
.Map(request => request.GetEndpointPath()) | ||
.Should() | ||
.BeSuccess("/v2/verify/f3a065af-ac5a-47a4-8dfe-819561a7a287"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using AutoFixture.Kernel; | ||
using FsCheck; | ||
using FsCheck.Xunit; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Monads; | ||
using Vonage.Common.Test; | ||
using Vonage.Common.Test.TestHelpers; | ||
using Vonage.VerifyV2; | ||
using Vonage.VerifyV2.Cancel; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Unit.VerifyV2.Cancel | ||
{ | ||
public class UseCaseTest : BaseUseCase, IUseCase | ||
{ | ||
private Func<VonageHttpClientConfiguration, Task<Result<Common.Monads.Unit>>> Operation => | ||
configuration => new VerifyV2Client(configuration).CancelAsync(this.request); | ||
|
||
private readonly Result<CancelRequest> request; | ||
|
||
public UseCaseTest() => this.request = BuildRequest(this.helper.Fixture); | ||
|
||
[Property] | ||
public Property ShouldReturnFailure_GivenApiErrorCannotBeParsed() => | ||
this.helper.VerifyReturnsFailureGivenErrorCannotBeParsed(this.BuildExpectedRequest(), this.Operation); | ||
|
||
[Property] | ||
public Property ShouldReturnFailure_GivenApiResponseIsError() => | ||
this.helper.VerifyReturnsFailureGivenApiResponseIsError(this.BuildExpectedRequest(), this.Operation); | ||
|
||
[Fact] | ||
public async Task ShouldReturnFailure_GivenRequestIsFailure() => | ||
await this.helper.VerifyReturnsFailureGivenRequestIsFailure<CancelRequest, Common.Monads.Unit>( | ||
(configuration, failureRequest) => new VerifyV2Client(configuration).CancelAsync(failureRequest)); | ||
|
||
[Fact] | ||
public async Task ShouldReturnFailure_GivenTokenGenerationFailed() => | ||
await this.helper.VerifyReturnsFailureGivenTokenGenerationFails(this.Operation); | ||
|
||
[Fact] | ||
public async Task ShouldReturnSuccess_GivenApiResponseIsSuccess() => | ||
await this.helper.VerifyReturnsExpectedValueGivenApiResponseIsSuccess(this.BuildExpectedRequest(), | ||
this.Operation); | ||
|
||
private ExpectedRequest BuildExpectedRequest() => | ||
new ExpectedRequest | ||
{ | ||
Method = HttpMethod.Delete, | ||
RequestUri = new Uri(UseCaseHelper.GetPathFromRequest(this.request), UriKind.Relative), | ||
}; | ||
|
||
private static Result<CancelRequest> BuildRequest( | ||
ISpecimenBuilder fixture) => | ||
CancelRequest.Parse(fixture.Create<Guid>()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Net.Http; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Monads; | ||
using Vonage.Common.Validation; | ||
|
||
namespace Vonage.VerifyV2.Cancel; | ||
|
||
/// <inheritdoc /> | ||
public readonly struct CancelRequest : IVonageRequest | ||
{ | ||
private CancelRequest(Guid requestId) => this.RequestId = requestId; | ||
|
||
/// <summary> | ||
/// ID of the verify request. | ||
/// </summary> | ||
public Guid RequestId { get; internal init; } | ||
|
||
/// <inheritdoc /> | ||
public HttpRequestMessage BuildRequestMessage() => VonageRequestBuilder | ||
.Initialize(HttpMethod.Delete, this.GetEndpointPath()) | ||
.Build(); | ||
|
||
/// <inheritdoc /> | ||
public string GetEndpointPath() => $"/v2/verify/{this.RequestId}"; | ||
|
||
/// <summary> | ||
/// Parses the input into a CancelRequest. | ||
/// </summary> | ||
/// <param name="requestId">The verify request identifier.</param> | ||
/// <returns>A success state with the request if the parsing succeeded. A failure state with an error if it failed.</returns> | ||
public static Result<CancelRequest> Parse(Guid requestId) => | ||
Result<CancelRequest> | ||
.FromSuccess(new CancelRequest(requestId)) | ||
.Bind(VerifyRoomId); | ||
|
||
private static Result<CancelRequest> VerifyRoomId(CancelRequest request) => | ||
InputValidation.VerifyNotEmpty(request, request.RequestId, nameof(RequestId)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters