diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e86434d..c79e440 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,9 @@ jobs: uses: actions/setup-dotnet@v2 with: dotnet-version: | - 6.0.421 - 7.0.408 8.0.415 9.0.306 + 10.0.101 - name: Build run: dotnet build -c $BUILD_CONFIG diff --git a/.github/workflows/nuget.yml b/.github/workflows/nuget.yml index 49c377d..b73a1d9 100644 --- a/.github/workflows/nuget.yml +++ b/.github/workflows/nuget.yml @@ -19,10 +19,9 @@ jobs: uses: actions/setup-dotnet@v2 with: dotnet-version: | - 6.0.421 - 7.0.408 8.0.415 9.0.306 + 10.0.101 - name: Build run: dotnet build -c $BUILD_CONFIG diff --git a/Directory.Build.props b/Directory.Build.props index 3b3adcf..0be2ead 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,12 +1,12 @@  - net6.0;net7.0;net8.0;net9.0 + net8.0;net9.0;net10.0 latest true - 4.1.0 + 5.0.0 Apache-2.0 http://github.com/xabaril/Acheve.TestHost diff --git a/Directory.Packages.props b/Directory.Packages.props index 3ebe986..51f564d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,23 +1,12 @@  - - 6.0.36 - 17.9.0 - 2.8.2 - - - 7.0.20 - 17.9.0 - 2.8.2 - - 8.0.21 - 18.0.0 - 3.1.5 + 8.0.22 - 9.0.10 - 18.0.0 - 3.1.5 + 9.0.11 + + + 10.0.1 @@ -27,10 +16,10 @@ - + - + diff --git a/global.json b/global.json index af57189..a9df7bb 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "projects": ["src", "test", "samples"], "sdk": { - "version": "9.0.0", + "version": "10.0.0", "rollForward": "latestMajor" } } diff --git a/samples/Sample.IntegrationTests/Infrastructure/TestHostFixture.cs b/samples/Sample.IntegrationTests/Infrastructure/TestHostFixture.cs index 45d913a..94392c8 100644 --- a/samples/Sample.IntegrationTests/Infrastructure/TestHostFixture.cs +++ b/samples/Sample.IntegrationTests/Infrastructure/TestHostFixture.cs @@ -1,14 +1,15 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; +using Microsoft.Extensions.Hosting; using System; using System.Threading.Tasks; using Xunit; namespace Sample.IntegrationTests.Infrastructure { - public class TestHostFixture : IDisposable, IAsyncLifetime + public sealed class TestHostFixture : IDisposable, IAsyncLifetime { - private IWebHost _host; + private IHost _host; public TestServer Server => _host.GetTestServer(); @@ -21,10 +22,13 @@ public void Dispose() /// public async Task InitializeAsync() { - _host = new WebHostBuilder() - .UseTestServer() - .UseStartup() - .Build(); + _host = Host.CreateDefaultBuilder() + .ConfigureWebHost(webHostBuilder => + { + webHostBuilder + .UseStartup() + .UseTestServer(); + }).Build(); await _host.StartAsync(); } diff --git a/samples/Sample.IntegrationTests/Infrastructure/WebApplicationFactoryFixture.cs b/samples/Sample.IntegrationTests/Infrastructure/WebApplicationFactoryFixture.cs index 3ef7461..775104f 100644 --- a/samples/Sample.IntegrationTests/Infrastructure/WebApplicationFactoryFixture.cs +++ b/samples/Sample.IntegrationTests/Infrastructure/WebApplicationFactoryFixture.cs @@ -1,20 +1,21 @@ -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; +using Microsoft.Extensions.Hosting; namespace Sample.IntegrationTests.Infrastructure { public class WebApplicationFactoryFixture : WebApplicationFactory { - protected override IWebHostBuilder CreateWebHostBuilder() + protected override IHostBuilder CreateHostBuilder() { - return WebHost.CreateDefaultBuilder(); + return Host.CreateDefaultBuilder(); } protected override void ConfigureWebHost(IWebHostBuilder builder) { - builder.UseStartup() + builder + .UseStartup() .UseSolutionRelativeContentRoot("samples") .UseTestServer(); } diff --git a/src/Acheve.TestHost/Routing/TestServerAction.cs b/src/Acheve.TestHost/Routing/TestServerAction.cs index 859a2b9..c836025 100644 --- a/src/Acheve.TestHost/Routing/TestServerAction.cs +++ b/src/Acheve.TestHost/Routing/TestServerAction.cs @@ -139,11 +139,7 @@ private void AddArgumentValues(int order, object value, string argumentName, bool canBeObjectWithMultipleFroms = false; if (hasNoAttributes && !isPrimitive) { -#if NET8_0_OR_GREATER canBeObjectWithMultipleFroms = MethodInfo.GetParameters().Length == 1; -#else - canBeObjectWithMultipleFroms = false; -#endif if (activeBodyApiController) { diff --git a/src/Acheve.TestHost/Security/TestServerHandler.cs b/src/Acheve.TestHost/Security/TestServerHandler.cs index 8759c9e..12801eb 100644 --- a/src/Acheve.TestHost/Security/TestServerHandler.cs +++ b/src/Acheve.TestHost/Security/TestServerHandler.cs @@ -13,22 +13,12 @@ namespace Acheve.TestHost { public class TestServerHandler : AuthenticationHandler { -#if NET8_0_OR_GREATER public TestServerHandler( IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder) : base(options, logger, encoder) { } -#else - public TestServerHandler( - IOptionsMonitor options, - ILoggerFactory logger, - UrlEncoder encoder, - ISystemClock clock) - : base(options, logger, encoder, clock) - { } -#endif protected new TestServerEvents Events { diff --git a/tests/UnitTests/Acheve.TestHost/Routing/Builders/TestServerBuilder.cs b/tests/UnitTests/Acheve.TestHost/Routing/Builders/TestServerBuilder.cs index 53635a4..d8ab2cb 100644 --- a/tests/UnitTests/Acheve.TestHost/Routing/Builders/TestServerBuilder.cs +++ b/tests/UnitTests/Acheve.TestHost/Routing/Builders/TestServerBuilder.cs @@ -1,25 +1,29 @@ -using System.Reflection; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using System.Reflection; namespace UnitTests.Acheve.TestHost.Builders { public class TestServerBuilder { - private readonly WebHostBuilder _webHostBuilder; + private readonly HostBuilder _hostBuilder; public TestServerBuilder() { - _webHostBuilder = new WebHostBuilder(); - + _hostBuilder = new HostBuilder(); } public TestServerBuilder UseDefaultStartup() { - _webHostBuilder.UseStartup(); + _hostBuilder.ConfigureWebHost(webHostBuilder => + { + webHostBuilder + .UseTestServer() + .UseStartup(); + }); return this; } @@ -27,7 +31,12 @@ public TestServerBuilder UseDefaultStartup() public TestServer Build() { - return new TestServer(_webHostBuilder); + var host = _hostBuilder + .Build(); + + host.Start(); + + return host.GetTestServer(); } class DefaultStartup diff --git a/tests/UnitTests/Acheve.TestHost/Routing/TestBuilders/TestServerBuilder.cs b/tests/UnitTests/Acheve.TestHost/Routing/TestBuilders/TestServerBuilder.cs deleted file mode 100644 index c2089c9..0000000 --- a/tests/UnitTests/Acheve.TestHost/Routing/TestBuilders/TestServerBuilder.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.DependencyInjection; - -namespace UnitTests.Acheve.TestHost.TestBuilders -{ - public class TestServerBuilder - { - private readonly IWebHostBuilder _webHost = new WebHostBuilder(); - - public TestServer Build() - { - return new TestServer(_webHost); - } - - public TestServerBuilder UseDefaultStartup() - { - _webHost.UseStartup(); - - return this; - } - - public class Startup - { - public void ConfigureServices(IServiceCollection services) - { - } - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - - } - } - } -}