Skip to content

Commit

Permalink
feat: add Type property on Failures (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d authored Jun 28, 2023
1 parent 13bf2c3 commit 58355a5
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Vonage.Common.Test/Failures/AuthenticationFailureTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using FluentAssertions;
using Vonage.Common.Failures;

namespace Vonage.Common.Test.Failures;

public class AuthenticationFailureTest
{
[Fact]
public void Type_ShouldReturnAuthenticationFailure() => new AuthenticationFailure()
.Type
.Should()
.Be(typeof(AuthenticationFailure));
}
7 changes: 7 additions & 0 deletions Vonage.Common.Test/Failures/DeserializationFailureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ public void ToException_ShouldReturnVonageException()
exception.Message.Should().Be("Unable to deserialize 'serialized text' into 'DeserializationFailureTest'.");
exception.Json.Should().Be("serialized text");
}

[Fact]
public void Type_ShouldReturnDeserializationFailure() => DeserializationFailure
.From(typeof(DeserializationFailureTest), "serialized text")
.Type
.Should()
.Be(typeof(DeserializationFailure));
}
6 changes: 6 additions & 0 deletions Vonage.Common.Test/Failures/HttpFailureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ public void ToException_ShouldReturnVonageException()
exception.HttpStatusCode.Should().Be(HttpStatusCode.NotFound);
exception.Json.Should().Be("json data");
}

[Fact]
public void Type_ShouldReturnHttpFailure() => HttpFailure.From(HttpStatusCode.NotFound)
.Type
.Should()
.Be(typeof(HttpFailure));
}
}
6 changes: 6 additions & 0 deletions Vonage.Common.Test/Failures/ResultFailureTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ public void ToException_ShouldReturnVonageException() =>
public void ToResult_ShouldReturnFailure() =>
ResultFailure.FromErrorMessage("Some error.").ToResult<int>().Should()
.BeFailure(ResultFailure.FromErrorMessage("Some error."));

[Fact]
public void Type_ShouldReturnResultFailure() => ResultFailure.FromErrorMessage("Some error.")
.Type
.Should()
.Be(typeof(ResultFailure));
}
}
3 changes: 3 additions & 0 deletions Vonage.Common/Failures/AuthenticationFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace Vonage.Common.Failures;
/// <inheritdoc />
public struct AuthenticationFailure : IResultFailure
{
/// <inheritdoc />
public Type Type => typeof(AuthenticationFailure);

/// <inheritdoc />
public string GetFailureMessage() => VonageAuthenticationException.FromMissingApplicationIdOrPrivateKey().Message;

Expand Down
3 changes: 3 additions & 0 deletions Vonage.Common/Failures/DeserializationFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace Vonage.Common.Failures;
/// </summary>
public string SerializedContent { get; }

/// <inheritdoc />
public Type Type => typeof(DeserializationFailure);

/// <summary>
/// Creates a DeserializationFailure.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Vonage.Common/Failures/HttpFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Vonage.Common.Failures;
/// <remarks>Mandatory for deserialization.</remarks>
public string Message { get; }

/// <inheritdoc />
public Type Type => typeof(HttpFailure);

/// <summary>
/// Create a HttpFailure.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Vonage.Common/Failures/IResultFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Vonage.Common.Failures;
/// </summary>
public interface IResultFailure
{
/// <summary>
/// The type of failure.
/// </summary>
Type Type { get; }

/// <summary>
/// Returns the error message defined in the failure.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Vonage.Common/Failures/ResultFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace Vonage.Common.Failures;
private readonly string error;
private ResultFailure(string error) => this.error = error;

/// <inheritdoc />
public Type Type => typeof(ResultFailure);

/// <summary>
/// Creates a failure from an error message.
/// </summary>
Expand Down

0 comments on commit 58355a5

Please sign in to comment.