-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unhandled ResultStatus.NoContent in MinimalApiResultExtensions.To…
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
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
38 changes: 38 additions & 0 deletions
38
tests/Ardalis.Result.AspNetCore.UnitTests/MinimalApiResultExtensionsCoverage.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
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 |