-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVX-6546 | [Video] Refactoring (#316)
* Remove duplication when creating WireMock requests/responses * Implement UseCaseHelper to reduce duplication * Code cleanup * Reduce duplication on property-based tests * Use generator for FsCheck, use HttpStatusCode instead of string for ErrorResponse * Create method for converting an ErrorReponse to HttpFailure * Implement ValueObject and StringIdentifier * Implement implicit operator for Identifier * Missing constant on Identifier * Address duplication in InputValidation
- Loading branch information
Showing
48 changed files
with
646 additions
and
480 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
4 changes: 2 additions & 2 deletions
4
Vonage.Video.Beta.Test/Common/MaybeTest.cs → ...ideo.Beta.Test/Common/Monads/MaybeTest.cs
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
4 changes: 2 additions & 2 deletions
4
Vonage.Video.Beta.Test/Common/ResultTest.cs → ...deo.Beta.Test/Common/Monads/ResultTest.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using Vonage.Video.Beta.Common; | ||
using Xunit; | ||
|
||
namespace Vonage.Video.Beta.Test.Common | ||
{ | ||
public class ValueObjectTest | ||
{ | ||
[Fact] | ||
public void Equals_ShouldReturnFalse_GivenValueAreDifferent() => | ||
FakeValueObject.Hello.Equals(FakeValueObject.World).Should().BeFalse(); | ||
|
||
[Fact] | ||
public void Equals_ShouldReturnTrue_GivenValueAreSame() => | ||
FakeValueObject.Hello.Equals(FakeValueObject.Hello).Should().BeTrue(); | ||
|
||
[Fact] | ||
public void EqualsOperator_ShouldReturnFalse_GivenValueAreDifferent() => | ||
(FakeValueObject.Hello == FakeValueObject.World).Should().BeFalse(); | ||
|
||
[Fact] | ||
public void EqualsOperator_ShouldReturnTrue_GivenValueAreSame() => | ||
(FakeValueObject.Hello == FakeValueObject.Hello).Should().BeTrue(); | ||
|
||
[Fact] | ||
public void DifferentOperator_ShouldReturnFalse_GivenValueAreSame() => | ||
(FakeValueObject.Hello != FakeValueObject.Hello).Should().BeFalse(); | ||
|
||
[Fact] | ||
public void DifferentOperator_ShouldReturnTrue_GivenValueAreDifferent() => | ||
(FakeValueObject.Hello != FakeValueObject.World).Should().BeTrue(); | ||
|
||
[Fact] | ||
public void GetHashCode_ShouldReturnSameValue_GivenValueAreSame() => | ||
FakeValueObject.Hello.GetHashCode().Should() | ||
.Be(FakeValueObject.Hello.GetHashCode()); | ||
|
||
[Fact] | ||
public void GetHashCode_ShouldReturnDifferent_GivenValueAreDifferent() => | ||
FakeValueObject.Hello.GetHashCode().Should() | ||
.NotBe(FakeValueObject.World.GetHashCode()); | ||
|
||
private class FakeValueObject : ValueObject<string> | ||
{ | ||
private readonly string value; | ||
|
||
private FakeValueObject(string value) | ||
{ | ||
this.value = value; | ||
} | ||
|
||
public static FakeValueObject Hello => new FakeValueObject("Hello"); | ||
public static FakeValueObject World => new FakeValueObject("World"); | ||
|
||
protected override IEnumerable<object> GetEqualityComponents() => new[] {this.value}; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
using System.Net; | ||
using FsCheck; | ||
using Vonage.Video.Beta.Video.Sessions; | ||
|
||
namespace Vonage.Video.Beta.Test.Extensions | ||
{ | ||
/// <summary> | ||
/// Extensions for FsCheck. | ||
/// </summary> | ||
public static class FsCheckExtensions | ||
{ | ||
public static Arbitrary<HttpStatusCode> GetInvalidStatusCodes() => Arb.From<HttpStatusCode>() | ||
/// <summary> | ||
/// Retrieves a HttpStatusCode generator that produces only invalid codes. | ||
/// </summary> | ||
/// <returns>An Arbitrary of status codes.</returns> | ||
public static Arbitrary<HttpStatusCode> GetInvalidStatusCodes() => GetAny<HttpStatusCode>() | ||
.MapFilter(_ => _, code => (int) code >= 400 && (int) code < 600); | ||
|
||
/// <summary> | ||
/// Retrieves a string generator that produces only non-null/non-empty string. | ||
/// </summary> | ||
/// <returns>An Arbitrary of strings.</returns> | ||
public static Arbitrary<string> GetNonEmptyStrings() => | ||
GetAny<string>().MapFilter(_ => _, value => !string.IsNullOrWhiteSpace(value)); | ||
|
||
/// <summary> | ||
/// Retrieves a generator that produces any value. | ||
/// </summary> | ||
/// <typeparam name="T">Type of the value.</typeparam> | ||
/// <returns>An Arbitrary.</returns> | ||
public static Arbitrary<T> GetAny<T>() => Arb.From<T>(); | ||
|
||
/// <summary> | ||
/// Retrieves a generator that produces error responses with invalid status codes. | ||
/// </summary> | ||
/// <returns>An Arbitrary of ErrorResponse.</returns> | ||
public static Arbitrary<ErrorResponse> GetErrorResponses() => | ||
Arb.From(from message in GetAny<string>().Generator | ||
from code in GetInvalidStatusCodes().Generator | ||
select new ErrorResponse(code, message)); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,15 +1,53 @@ | ||
using WireMock.RequestBuilders; | ||
using System.Net; | ||
using WireMock.RequestBuilders; | ||
using WireMock.ResponseBuilders; | ||
|
||
namespace Vonage.Video.Beta.Test.Extensions | ||
{ | ||
/// <summary> | ||
/// Extensions for WireMock.Net | ||
/// </summary> | ||
public static class WireMockExtensions | ||
{ | ||
public static IRequestBuilder BuildRequestWithAuthenticationHeader(string token) => | ||
/// <summary> | ||
/// Creates a response. | ||
/// </summary> | ||
/// <param name="code">The http status code</param> | ||
/// <param name="body">The response body.</param> | ||
/// <returns>The response.</returns> | ||
public static IResponseBuilder CreateResponse(HttpStatusCode code, string body) => | ||
body is null ? CreateResponse(code) : CreateResponse(code).WithBody(body); | ||
|
||
/// <summary> | ||
/// Creates a response without a body. | ||
/// </summary> | ||
/// <param name="code">The http status code</param> | ||
/// <returns>The response.</returns> | ||
public static IResponseBuilder CreateResponse(HttpStatusCode code) => | ||
Response.Create().WithStatusCode(code); | ||
|
||
/// <summary> | ||
/// Creates a request. | ||
/// </summary> | ||
/// <param name="token">The authentication token.</param> | ||
/// <param name="path">The endpoint path.</param> | ||
/// <param name="body">The body.</param> | ||
/// <returns>The request.</returns> | ||
public static IRequestBuilder CreateRequest(string token, string path, string body) => | ||
body is null ? CreateRequest(token, path) : CreateRequest(token, path).WithBody(body); | ||
|
||
/// <summary> | ||
/// Creates a request without a body. | ||
/// </summary> | ||
/// <param name="token">The authentication token.</param> | ||
/// <param name="path">The endpoint path.</param> | ||
/// <returns>The request.</returns> | ||
public static IRequestBuilder CreateRequest(string token, string path) => | ||
BuildRequestWithAuthenticationHeader(token).WithPath(path); | ||
|
||
private static IRequestBuilder BuildRequestWithAuthenticationHeader(string token) => | ||
WireMock.RequestBuilders.Request | ||
.Create() | ||
.WithAuthenticationHeader(token); | ||
|
||
public static IRequestBuilder WithAuthenticationHeader(this IRequestBuilder builder, string token) => | ||
builder.WithHeader("Authorization", $"Bearer {token}"); | ||
.WithHeader("Authorization", $"Bearer {token}"); | ||
} | ||
} |
Oops, something went wrong.