From 4e2e37fa3b7698faface62de5e234b1e1b026588 Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Wed, 12 Oct 2022 15:28:37 -1000 Subject: [PATCH 1/5] update testing with IResult types --- aspnetcore/fundamentals/minimal-apis/test-min-api.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aspnetcore/fundamentals/minimal-apis/test-min-api.md b/aspnetcore/fundamentals/minimal-apis/test-min-api.md index 2df59b56c38f..129a79baf98c 100644 --- a/aspnetcore/fundamentals/minimal-apis/test-min-api.md +++ b/aspnetcore/fundamentals/minimal-apis/test-min-api.md @@ -15,6 +15,14 @@ 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. +## IResult implementation types + +Public implementation types in the namespace can be used to unit test your minimal route handlers when using named methods instead of lambdas. + +The following code uses the [`Ok`](/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::: + ## 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. From 7d51539aa5f29022c41d792c5281390d678b1f83 Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Wed, 12 Oct 2022 15:44:56 -1000 Subject: [PATCH 2/5] update testing with IResult types --- aspnetcore/fundamentals/minimal-apis/test-min-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/minimal-apis/test-min-api.md b/aspnetcore/fundamentals/minimal-apis/test-min-api.md index 129a79baf98c..c8c34208ed97 100644 --- a/aspnetcore/fundamentals/minimal-apis/test-min-api.md +++ b/aspnetcore/fundamentals/minimal-apis/test-min-api.md @@ -21,7 +21,7 @@ Public implementation types in the `](/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::: +:::code language="csharp" source="~/../AspNetCore.Docs.Samples/fundamentals/minimal-apis/samples/MinApiTestsSample/UnitTests/TodoInMemoryTests.cs" id="snippet_" highlight="18"::: ## Additional Resources From 71542025b6e7e0cae8d68f8f8fb5f749a332dc1c Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Wed, 12 Oct 2022 15:56:23 -1000 Subject: [PATCH 3/5] update testing with IResult types --- aspnetcore/fundamentals/minimal-apis/test-min-api.md | 4 +++- aspnetcore/release-notes/aspnetcore-7.0.md | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/minimal-apis/test-min-api.md b/aspnetcore/fundamentals/minimal-apis/test-min-api.md index c8c34208ed97..b5ac22e9b74c 100644 --- a/aspnetcore/fundamentals/minimal-apis/test-min-api.md +++ b/aspnetcore/fundamentals/minimal-apis/test-min-api.md @@ -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. + + ## IResult implementation types -Public implementation types in the namespace can be used to unit test your minimal route handlers when using named methods instead of lambdas. +Public implementation types in the namespace can be used to unit test minimal route handlers when using named methods instead of lambdas. The following code uses the [`Ok`](/dotnet/api/microsoft.aspnetcore.http.httpresults.ok-1) class: diff --git a/aspnetcore/release-notes/aspnetcore-7.0.md b/aspnetcore/release-notes/aspnetcore-7.0.md index 6e29b26809e6..df844d0691f1 100644 --- a/aspnetcore/release-notes/aspnetcore-7.0.md +++ b/aspnetcore/release-notes/aspnetcore-7.0.md @@ -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 + + implementation types are now publicly available in the 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`](/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 From 9a5ca38e3b1d0724b3a1b41b6d2129ba21675e2e Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Wed, 12 Oct 2022 16:03:00 -1000 Subject: [PATCH 4/5] update testing with IResult types --- aspnetcore/fundamentals/minimal-apis/test-min-api.md | 6 +++++- aspnetcore/release-notes/aspnetcore-7.0.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/aspnetcore/fundamentals/minimal-apis/test-min-api.md b/aspnetcore/fundamentals/minimal-apis/test-min-api.md index b5ac22e9b74c..2de4d25d75cd 100644 --- a/aspnetcore/fundamentals/minimal-apis/test-min-api.md +++ b/aspnetcore/fundamentals/minimal-apis/test-min-api.md @@ -21,10 +21,14 @@ The [sample code on GitHub](https://github.com/dotnet/AspNetCore.Docs.Samples/tr Public implementation types in the namespace can be used to unit test minimal route handlers when using named methods instead of lambdas. -The following code uses the [`Ok`](/dotnet/api/microsoft.aspnetcore.http.httpresults.ok-1) class: +The following code uses the [`NotFound`](/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="18"::: +The following code uses the [`Ok`](/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. diff --git a/aspnetcore/release-notes/aspnetcore-7.0.md b/aspnetcore/release-notes/aspnetcore-7.0.md index df844d0691f1..b24e89566829 100644 --- a/aspnetcore/release-notes/aspnetcore-7.0.md +++ b/aspnetcore/release-notes/aspnetcore-7.0.md @@ -136,7 +136,7 @@ In .NET 7 the types implementing `IResult` are public, allowing for type asserti The following code uses the [`Ok`](/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"::: +:::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). From 9b347b42011e000ef56b3337322c1fb1e5a381f5 Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Wed, 12 Oct 2022 16:10:41 -1000 Subject: [PATCH 5/5] update testing with IResult types --- aspnetcore/fundamentals/minimal-apis/test-min-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/minimal-apis/test-min-api.md b/aspnetcore/fundamentals/minimal-apis/test-min-api.md index 2de4d25d75cd..71da08b37540 100644 --- a/aspnetcore/fundamentals/minimal-apis/test-min-api.md +++ b/aspnetcore/fundamentals/minimal-apis/test-min-api.md @@ -23,7 +23,7 @@ Public implementation types in the `](/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="18"::: +:::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`](/dotnet/api/microsoft.aspnetcore.http.httpresults.ok-1) class: