diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be21861..e86434d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,8 @@ jobs: dotnet-version: | 6.0.421 7.0.408 - 8.0.204 + 8.0.415 + 9.0.306 - name: Build run: dotnet build -c $BUILD_CONFIG diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml index f4455d7..49c377d 100644 --- a/.github/workflows/nuget.yml +++ b/.github/workflows/nuget.yml @@ -21,7 +21,8 @@ jobs: dotnet-version: | 6.0.421 7.0.408 - 8.0.204 + 8.0.415 + 9.0.306 - name: Build run: dotnet build -c $BUILD_CONFIG diff --git a/Directory.Build.props b/Directory.Build.props index b886dd6..3b3adcf 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,12 +1,12 @@  - net6.0;net7.0;net8.0 + net6.0;net7.0;net8.0;net9.0 latest true - 4.0.0 + 4.1.0 Apache-2.0 http://github.com/xabaril/Acheve.TestHost diff --git a/Directory.Packages.props b/Directory.Packages.props index 63bca32..3ebe986 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,15 +1,25 @@  - 6.0.29 + 6.0.36 + 17.9.0 + 2.8.2 - 7.0.18 + 7.0.20 + 17.9.0 + 2.8.2 - 8.0.4 + 8.0.21 + 18.0.0 + 3.1.5 + + + 9.0.10 + 18.0.0 + 3.1.5 - @@ -17,11 +27,11 @@ - - - - - + + + + + diff --git a/global.json b/global.json index e0311ae..af57189 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "projects": ["src", "test", "samples"], "sdk": { - "version": "8.0.000", + "version": "9.0.0", "rollForward": "latestMajor" } } diff --git a/samples/Sample.Api/ApiConfiguration.cs b/samples/Sample.Api/ApiConfiguration.cs index 43c0936..d152984 100644 --- a/samples/Sample.Api/ApiConfiguration.cs +++ b/samples/Sample.Api/ApiConfiguration.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.DependencyInjection; -//using Newtonsoft.Json; using System.Security.Claims; namespace Sample.Api diff --git a/src/Acheve.TestHost/Extensions/TypeExtensions.cs b/src/Acheve.TestHost/Extensions/TypeExtensions.cs index 6a29ed6..4bffff0 100644 --- a/src/Acheve.TestHost/Extensions/TypeExtensions.cs +++ b/src/Acheve.TestHost/Extensions/TypeExtensions.cs @@ -13,7 +13,8 @@ internal static bool IsPrimitiveType(this Type typeToInspect) || type == typeof(string) || type == typeof(decimal) || type == typeof(Guid) - || type.IsDateTime(); + || type.IsDateTime() + || type.IsEnum; } internal static bool IsDateTime(this Type typeToInspect) diff --git a/src/Acheve.TestHost/Routing/UriDiscover.cs b/src/Acheve.TestHost/Routing/UriDiscover.cs index f9d83db..2914d12 100644 --- a/src/Acheve.TestHost/Routing/UriDiscover.cs +++ b/src/Acheve.TestHost/Routing/UriDiscover.cs @@ -215,7 +215,9 @@ private static TestServerAction GetTestServerAction(LambdaExpressio throw new InvalidOperationException($"The action selector is not a valid lambda expression"); } - var methodCall = (MethodCallExpression)actionSelector.Body; + var methodCall = actionSelector.Body as MethodCallExpression; + if (methodCall is null) + methodCall = (actionSelector.Body as UnaryExpression).Operand as MethodCallExpression; var action = new TestServerAction(methodCall.Method); bool haveAttributeApiController = typeof(TController).GetTypeInfo().GetCustomAttribute(typeof(ApiControllerAttribute)) != null; diff --git a/tests/UnitTests/Acheve.TestHost/Routing/Builders/ValuesV5Controller.cs b/tests/UnitTests/Acheve.TestHost/Routing/Builders/ValuesV5Controller.cs index 05d3d09..b9412af 100644 --- a/tests/UnitTests/Acheve.TestHost/Routing/Builders/ValuesV5Controller.cs +++ b/tests/UnitTests/Acheve.TestHost/Routing/Builders/ValuesV5Controller.cs @@ -125,4 +125,12 @@ public ActionResult PostWithDifferentFroms(ParamWithDif [HttpPut($"{nameof(PutWithDifferentFroms)}/{{{nameof(ParamWithDifferentFroms.ParamFromRoute)}}}")] public ActionResult PutWithDifferentFroms(ParamWithDifferentFroms request) => Ok(request); + + [HttpGet($"{nameof(GetWithEnumInRoute)}/{{request}}")] + public string GetWithEnumInRoute([FromRoute] SampleEnumeration request) + => request.ToString(); + + [HttpGet($"{nameof(GetWithEnumInQuery)}")] + public string GetWithEnumInQuery([FromQuery] SampleEnumeration request) + => request.ToString(); } diff --git a/tests/UnitTests/Acheve.TestHost/Routing/Models/SampleEnumeration.cs b/tests/UnitTests/Acheve.TestHost/Routing/Models/SampleEnumeration.cs new file mode 100644 index 0000000..7de4b21 --- /dev/null +++ b/tests/UnitTests/Acheve.TestHost/Routing/Models/SampleEnumeration.cs @@ -0,0 +1,8 @@ +namespace UnitTests.Acheve.TestHost.Routing.Models; + +public enum SampleEnumeration +{ + Value1, + Value2, + Value3 +} diff --git a/tests/UnitTests/Acheve.TestHost/Routing/TestServerExtensionsTests.cs b/tests/UnitTests/Acheve.TestHost/Routing/TestServerExtensionsTests.cs index e319f82..e0987d7 100644 --- a/tests/UnitTests/Acheve.TestHost/Routing/TestServerExtensionsTests.cs +++ b/tests/UnitTests/Acheve.TestHost/Routing/TestServerExtensionsTests.cs @@ -1954,6 +1954,40 @@ public async Task Create_put_request_with_object_with_different_froms() content.ParamFromBody.Should().Be(model.ParamFromBody); } + [Fact] + public async Task Create_get_request_with_enum_from_query() + { + var server = new TestServerBuilder() + .UseDefaultStartup() + .Build(); + + var enumValue = SampleEnumeration.Value3; + + var request = server.CreateHttpApiRequest(controller => controller.GetWithEnumInQuery(enumValue)); + var responseMessage = await request.GetAsync(); + + await responseMessage.IsSuccessStatusCodeOrThrow(); + var response = await responseMessage.Content.ReadAsStringAsync(); + response.Should().Be(enumValue.ToString()); + } + + [Fact] + public async Task Create_get_request_with_enum_from_route() + { + var server = new TestServerBuilder() + .UseDefaultStartup() + .Build(); + + var enumValue = SampleEnumeration.Value3; + + var request = server.CreateHttpApiRequest(controller => controller.GetWithEnumInRoute(enumValue)); + var responseMessage = await request.GetAsync(); + + await responseMessage.IsSuccessStatusCodeOrThrow(); + var response = await responseMessage.Content.ReadAsStringAsync(); + response.Should().Be(enumValue.ToString()); + } + private class PrivateNonControllerClass { public int SomeAction()