From 1c46749d4a4bff86ddc8654ea1954ae34ccbb423 Mon Sep 17 00:00:00 2001 From: aestene Date: Tue, 23 Apr 2024 13:06:44 +0200 Subject: [PATCH] WIP --- .../Controllers/MissionSchedulingControllerTests.cs | 11 +++-------- .../api.test/EventHandlers/TestMissionEventHandler.cs | 8 ++------ backend/api.test/TestWebApplicationFactory.cs | 10 ++++++++++ backend/api.test/Utilities/DbContextTestSetup.cs | 8 +------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/backend/api.test/Controllers/MissionSchedulingControllerTests.cs b/backend/api.test/Controllers/MissionSchedulingControllerTests.cs index a4da53e1b..b3d86458c 100644 --- a/backend/api.test/Controllers/MissionSchedulingControllerTests.cs +++ b/backend/api.test/Controllers/MissionSchedulingControllerTests.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Net.Http.Json; using System.Text.Json; +using System.Threading; using System.Threading.Tasks; using Api.Controllers.Models; using Api.Database.Context; @@ -35,13 +36,10 @@ public class MissionSchedulingControllerTests(ITestOutputHelper outputHelper) : public async Task InitializeAsync() { - (var container, string connectionString, var connection) = + (_container, _connectionString, _connection) = await TestSetupHelpers.ConfigurePostgreSqlContainer(); - _container = container; - _connectionString = connectionString; - _connection = connection; - outputHelper.WriteLine($"Connection string is {connectionString}"); + outputHelper.WriteLine($"Connection string is {_connectionString}"); _databaseUtilities = new DatabaseUtilities(Context); @@ -57,13 +55,10 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - //await Task.CompletedTask; //await Context.DisposeAsync(); //await _connection.CloseAsync(); await _factory.DisposeAsync(); await _container.DisposeAsync(); - - //await Task.Delay(5000); } private FlotillaDbContext CreateContext() diff --git a/backend/api.test/EventHandlers/TestMissionEventHandler.cs b/backend/api.test/EventHandlers/TestMissionEventHandler.cs index 7ee642c36..ffae3c7f3 100644 --- a/backend/api.test/EventHandlers/TestMissionEventHandler.cs +++ b/backend/api.test/EventHandlers/TestMissionEventHandler.cs @@ -48,13 +48,9 @@ public class TestMissionEventHandler(ITestOutputHelper outputHelper) : IAsyncLif public async Task InitializeAsync() { - (var container, string connectionString, var connection) = + (_container, _connectionString, _connection) = await TestSetupHelpers.ConfigurePostgreSqlContainer(); - outputHelper.WriteLine($"Connection string is {connectionString}"); - - _container = container; - _connectionString = connectionString; - _connection = connection; + outputHelper.WriteLine($"Connection string is {_connectionString}"); _databaseUtilities = new DatabaseUtilities(Context); diff --git a/backend/api.test/TestWebApplicationFactory.cs b/backend/api.test/TestWebApplicationFactory.cs index d1cce9212..163b673ac 100644 --- a/backend/api.test/TestWebApplicationFactory.cs +++ b/backend/api.test/TestWebApplicationFactory.cs @@ -1,8 +1,11 @@ using System; using System.IO; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Api.Database.Context; +using Api.EventHandlers; +using Api.Mqtt; using Api.Services; using Api.Test.Mocks; using Api.Test.Utilities; @@ -87,6 +90,13 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) public override async ValueTask DisposeAsync() { Console.WriteLine("Test"); + //var token = new CancellationToken(true); + //await this.Services.GetRequiredService().StopAsync(token); + //await this.Services.GetRequiredService().StopAsync(token); + //await this.Services.GetRequiredService().StopAsync(token); + //await this.Services.GetRequiredService().StopAsync(token); + //await this.Services.GetRequiredService().StopAsync(token); + await base.DisposeAsync(); } } diff --git a/backend/api.test/Utilities/DbContextTestSetup.cs b/backend/api.test/Utilities/DbContextTestSetup.cs index 154775677..6485f939a 100644 --- a/backend/api.test/Utilities/DbContextTestSetup.cs +++ b/backend/api.test/Utilities/DbContextTestSetup.cs @@ -37,18 +37,12 @@ public class DatabaseFixture : IAsyncLifetime public async Task InitializeAsync() { - (var container, string connectionString, var connection) = + (Container, ConnectionString, Connection) = await TestSetupHelpers.ConfigurePostgreSqlContainer(); - Container = container; - ConnectionString = connectionString; - Connection = connection; - Respawner = await TestSetupHelpers.ConfigureDatabaseRespawner(Connection); - Factory = TestSetupHelpers.ConfigureWebApplicationFactory(ConnectionString); Client = TestSetupHelpers.ConfigureHttpClient(Factory); ServiceProvider = TestSetupHelpers.ConfigureServiceProvider(Factory); - SerializerOptions = TestSetupHelpers.ConfigureJsonSerializerOptions(); }