Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alxandr committed Dec 17, 2024
1 parent 597fe9c commit fbe3bac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
namespace Altinn.Authorization.ProblemDetails;

/// <summary>
/// An exception that represents a <see cref="ProblemInstance"/>.
/// An exception that represents a <see cref="Problem"/>.
/// </summary>
public class ProblemInstanceException
: InvalidOperationException
{
/// <summary>
/// Initializes a new instance of the <see cref="ProblemInstanceException"/> class.
/// </summary>
/// <param name="problemInstance">The <see cref="ProblemInstance"/>.</param>
/// <param name="problemInstance">The <see cref="Problem"/>.</param>
public ProblemInstanceException(ProblemInstance problemInstance)
: base(problemInstance.Detail)
{
ProblemInstance = problemInstance;
Problem = problemInstance;
}

/// <summary>
/// Gets the <see cref="ProblemInstance"/>.
/// Gets the <see cref="Problem"/>.
/// </summary>
public ProblemInstance ProblemInstance { get; }
public ProblemInstance Problem { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,20 @@ static Result<int> TrySomething(bool fail)
return 42;
}
}

[Fact]
public void EnsureSuccess_ThrowsIfProblem()
{
Result<int> result = StdProblemDescriptors.ValidationError;
Action action = () => result.EnsureSuccess();
action.Should().Throw<ProblemInstanceException>()
.Which.Problem.ErrorCode.Should().Be(StdProblemDescriptors.ErrorCodes.ValidationError);
}

[Fact]
public void EnsureSuccess_DoesNotThrowIfSuccess()
{
Result<int> result = 42;
result.EnsureSuccess();
}
}

0 comments on commit fbe3bac

Please sign in to comment.