From 6b53b47713df2acaca1e53d3dc27080c007600b2 Mon Sep 17 00:00:00 2001 From: Mohammad Moattar Date: Tue, 13 Feb 2024 00:12:08 +0000 Subject: [PATCH] Fix the remaining tests --- .../IntegrationTestApplicationFactory.cs | 23 +++++++++++++------ .../IntegrationTestFixture.cs | 15 +++--------- .../ValidationControllerTests.cs | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/LittleBlocks.Testing.Integration/IntegrationTestApplicationFactory.cs b/src/LittleBlocks.Testing.Integration/IntegrationTestApplicationFactory.cs index c28709f..7d66573 100644 --- a/src/LittleBlocks.Testing.Integration/IntegrationTestApplicationFactory.cs +++ b/src/LittleBlocks.Testing.Integration/IntegrationTestApplicationFactory.cs @@ -14,18 +14,27 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +using Microsoft.AspNetCore; + namespace LittleBlocks.Testing.Integration; public class IntegrationTestApplicationFactory : WebApplicationFactory where TStartup : class { - protected override IHostBuilder CreateHostBuilder() + + protected override IWebHostBuilder CreateWebHostBuilder() { - var builder = Host - .CreateDefaultBuilder() - .ConfigureWebHostDefaults(host => + var hostBuilder = WebHost.CreateDefaultBuilder() + .ConfigureAppConfiguration((context, builder) => { - host.UseStartup().UseTestServer(); - }); - return builder; + var env = context.HostingEnvironment; + env.EnvironmentName = "Development"; + + builder.SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", false, true); + }) + .UseStartup() + .UseTestServer(); + + return hostBuilder; } } diff --git a/src/LittleBlocks.Testing.Integration/IntegrationTestFixture.cs b/src/LittleBlocks.Testing.Integration/IntegrationTestFixture.cs index 1587320..4d4a92d 100644 --- a/src/LittleBlocks.Testing.Integration/IntegrationTestFixture.cs +++ b/src/LittleBlocks.Testing.Integration/IntegrationTestFixture.cs @@ -45,20 +45,11 @@ public ClientAppPair CreateClientFromServer(Action(); return new ClientAppPair(client, server); } + + protected virtual WebApplicationFactory CreateApplicationFactory() { - return new IntegrationTestApplicationFactory() - .WithWebHostBuilder(builder => - { - builder.ConfigureAppConfiguration((hostingContext, config) => - { - var env = hostingContext.HostingEnvironment; - env.EnvironmentName = "Development"; - - config.SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", false, true); - }); - }); + return new IntegrationTestApplicationFactory(); } } diff --git a/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/ValidationControllerTests.cs b/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/ValidationControllerTests.cs index 71313b5..076b7c5 100644 --- a/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/ValidationControllerTests.cs +++ b/src/Samples/LittleBlocks.Sample.WebAPI.IntegrationTests/ValidationControllerTests.cs @@ -40,7 +40,7 @@ public async Task ForPostShouldReturn200Ok(string operation) new Document() } }; - using var fixture = TestApplicationFactory.Create(); + await using var fixture = TestApplicationFactory.Create(); // Act var response = await fixture.CreateClient().PostAsync("api/Validation", new JsonContent(request)); @@ -53,7 +53,7 @@ public async Task ForPostShouldReturn200Ok(string operation) public async Task ForPostShouldReturnErrorWithMissingArguments() { // Arrange - using var fixture = TestApplicationFactory.Create(); + await using var fixture = TestApplicationFactory.Create(); // Act var response = await fixture.CreateClient().PostAsync("api/Validation",