Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Ardalis.Result.AspNetCore/MinimalApiResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public static partial class ResultExtensions
/// <returns></returns>
public static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this Result result) => ToMinimalApiResult((IResult)result);

internal static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this IResult result) =>
/// <summary>
/// Convert an Ardalis.Result <see cref="IResult"/> to a <see cref="Microsoft.AspNetCore.Http.IResult"/>.
/// Exposed so consumers can write a custom converter that handles selected statuses and delegates the
/// remaining statuses to the library's default mapping.
/// </summary>
/// <param name="result">The Ardalis.Result to convert.</param>
public static Microsoft.AspNetCore.Http.IResult ToMinimalApiResult(this IResult result) =>
result.Status switch
{
ResultStatus.Ok => result is Result ? Results.Ok() : Results.Ok(result.GetValue()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,19 @@ public void ToMinimalApiResultHandlesAllResultStatusValues()
}
}
}

[Fact]
public void IResultOverloadIsPubliclyCallableAndDelegatesToTypedOverload()
{
// Casting to the Ardalis.Result IResult interface and calling the (now public) overload directly
// must compile and behave the same as calling it on the concrete Result<T>.
Result<int> result = Result<int>.Success(42);
IResult asInterface = result;

Microsoft.AspNetCore.Http.IResult viaInterface = asInterface.ToMinimalApiResult();
Microsoft.AspNetCore.Http.IResult viaConcrete = result.ToMinimalApiResult();

Assert.Equal(viaConcrete.GetType(), viaInterface.GetType());
}
}
#endif
Loading