Skip to content
Merged
Changes from 1 commit
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: 5 additions & 3 deletions aspnetcore/fundamentals/minimal-apis/test-min-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ The [sample code on GitHub](https://github.com/dotnet/AspNetCore.Docs.Samples/tr

<a name="iit7"></a>

## IResult implementation types
## Unit test IResult implementation types

The following example shows how to unit test minimal route handlers that return <xref:Microsoft.AspNetCore.Http.IResult> using the [xUnit](https://github.com/xunit/xunit/) testing framework. The external database is replaced with an in-memory database during testing, the implementation of the `MockDb` can be found in the [sample code](https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/fundamentals/minimal-apis/samples/MinApiTestsSample/UnitTests/Helpers/MockDb.cs).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a same test in https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/responses?view=aspnetcore-9.0#typedresults-vs-results.
I can also add a note about the use of xUnit and the mockDb at that location.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, Thanks!!!! It could be a separate issue/PR if you like, or not, up to you.


Public <xref:Microsoft.AspNetCore.Http.IResult> implementation types in the <xref:Microsoft.AspNetCore.Http.HttpResults?displayProperty=fullName> namespace can be used to unit test minimal route handlers when using named methods instead of lambdas.

The following code uses the [`NotFound<TValue>`](/dotnet/api/microsoft.aspnetcore.http.httpresults.notfound-1) class:
The following code uses the <xref:Microsoft.AspNetCore.Http.HttpResults.NotFound%601> class:

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/minimal-apis/samples/MinApiTestsSample/UnitTests/TodoInMemoryTests.cs" id="snippet_" highlight="8":::

The following code uses the [`Ok<TValue>`](/dotnet/api/microsoft.aspnetcore.http.httpresults.ok-1) class:
The following code uses the <xref:Microsoft.AspNetCore.Http.HttpResults.Ok%601> class:

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/minimal-apis/samples/MinApiTestsSample/UnitTests/TodoInMemoryTests.cs" id="snippet_1" highlight="18":::

Expand Down