Skip to content
Merged
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
14 changes: 14 additions & 0 deletions aspnetcore/fundamentals/minimal-apis/test-min-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ By [Fiyaz Bin Hasan](https://github.com/fiyazbinhasan), and [Rick Anderson](http

The [sample code on GitHub](https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/MinApiTestsSample) provides an example of unit and integration tests on a Minimal API app.

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

## IResult implementation types

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:

:::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:

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

## Additional Resources

* [Basic authentication tests](https://github.com/blowdart/idunno.Authentication/tree/dev/test/idunno.Authentication.Basic.Test) is not a .NET repository but was written by a member of the .NET team. It provides examples of basic authentication testing.
Expand Down
10 changes: 10 additions & 0 deletions aspnetcore/release-notes/aspnetcore-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ In .NET 7 the types implementing `IResult` are public, allowing for type asserti

[!code-csharp[](~/fundamentals/minimal-apis/misc-samples/typedResults/TypedResultsApiWithTest/Test/WeatherApiTest.cs?name=snippet_1&highlight=7-8)]

### Improved unit testability for minimal route handlers

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

The following code uses the [`Ok<TValue>`](/dotnet/api/microsoft.aspnetcore.http.httpresults.ok-1) class:

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

For more information, see [`IResult` implementation types](xref:fundamentals/minimal-apis/test-min-api#iit7).

### OpenAPI improvements for minimal APIs

<a name="openapinuget"></a>
Expand Down