Skip to content

Commit

Permalink
Fix unhandled ResultStatus.NoContent in MinimalApiResultExtensions.To…
Browse files Browse the repository at this point in the history
…MinimalApiResult (#192)

#191
  • Loading branch information
inghamc authored Jun 18, 2024
1 parent 43f0b4c commit bb930b3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using System.Text;

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

Expand Down Expand Up @@ -37,6 +36,7 @@ internal static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this IResul
{
ResultStatus.Ok => result is Result ? Results.Ok() : Results.Ok(result.GetValue()),
ResultStatus.Created => Results.Created("", result.GetValue()),
ResultStatus.NoContent => Results.NoContent(),
ResultStatus.NotFound => NotFoundEntity(result),
ResultStatus.Unauthorized => UnAuthorized(result),
ResultStatus.Forbidden => Forbidden(result),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#if NET7_0_OR_GREATER

using Ardalis.Result.AspNetCore;
using Xunit;
using Xunit.Abstractions;

namespace Ardalis.Result.AspNetCore.UnitTests;

public class MinimalApiResultExtensionsCoverage : BaseResultConventionTest
{
private readonly ITestOutputHelper _testOutputHelper;

public MinimalApiResultExtensionsCoverage(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}

private class TestResult(ResultStatus status) : Result(status);

[Fact]
public void ToMinimalApiResultHandlesAllResultStatusValues()
{
foreach (ResultStatus resultStatus in Enum.GetValues(typeof(ResultStatus)))
{
Result result = new TestResult(resultStatus);
try
{
Microsoft.AspNetCore.Http.IResult minimalApiResult = result.ToMinimalApiResult();
}
catch (NotSupportedException e)
{
Assert.Fail(
$"Unhandled ResultStatus {resultStatus} in MinimalApiResultExtensions.ToMinimalApiResult: {e}");
}
}
}
}
#endif

0 comments on commit bb930b3

Please sign in to comment.