update testing with IResult types
parent
7d51539aa5
commit
71542025b6
|
@ -15,9 +15,11 @@ 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 your minimal route handlers when using named methods instead of lambdas.
|
||||
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 [`Ok<TValue>`](/dotnet/api/microsoft.aspnetcore.http.httpresults.ok-1) class:
|
||||
|
||||
|
|
|
@ -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_" 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>
|
||||
|
|
Loading…
Reference in New Issue