From 9a89f7ec78ef5d426c01c7ea319950ff9e238b0d Mon Sep 17 00:00:00 2001 From: aestene Date: Mon, 22 Apr 2024 10:20:49 +0200 Subject: [PATCH] WIP --- .../MissionSchedulingControllerTests.cs | 15 +++++++++++---- .../EventHandlers/TestMissionEventHandler.cs | 12 ++++++++---- backend/api.test/TestWebApplicationFactory.cs | 10 +++++++++- backend/api.test/api.test.csproj | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/backend/api.test/Controllers/MissionSchedulingControllerTests.cs b/backend/api.test/Controllers/MissionSchedulingControllerTests.cs index ab9aeb3c7..a4da53e1b 100644 --- a/backend/api.test/Controllers/MissionSchedulingControllerTests.cs +++ b/backend/api.test/Controllers/MissionSchedulingControllerTests.cs @@ -15,9 +15,11 @@ using Microsoft.Extensions.DependencyInjection; using Testcontainers.PostgreSql; using Xunit; +using Xunit.Abstractions; + namespace Api.Test.Controllers; -public class MissionSchedulingControllerTests : IAsyncLifetime +public class MissionSchedulingControllerTests(ITestOutputHelper outputHelper) : IAsyncLifetime { private FlotillaDbContext Context => CreateContext(); private TestWebApplicationFactory _factory; @@ -39,6 +41,8 @@ public async Task InitializeAsync() _connectionString = connectionString; _connection = connection; + outputHelper.WriteLine($"Connection string is {connectionString}"); + _databaseUtilities = new DatabaseUtilities(Context); _factory = TestSetupHelpers.ConfigureWebApplicationFactory(_connectionString); @@ -53,10 +57,13 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - await Context.DisposeAsync(); - await _connection.CloseAsync(); - await _container.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 c6279f94a..7ee642c36 100644 --- a/backend/api.test/EventHandlers/TestMissionEventHandler.cs +++ b/backend/api.test/EventHandlers/TestMissionEventHandler.cs @@ -21,10 +21,11 @@ using Moq; using Testcontainers.PostgreSql; using Xunit; +using Xunit.Abstractions; namespace Api.Test.EventHandlers { - public class TestMissionEventHandler : IAsyncLifetime + public class TestMissionEventHandler(ITestOutputHelper outputHelper) : IAsyncLifetime { private FlotillaDbContext Context => CreateContext(); private TestWebApplicationFactory _factory; @@ -49,6 +50,8 @@ public async Task InitializeAsync() { (var container, string connectionString, var connection) = await TestSetupHelpers.ConfigurePostgreSqlContainer(); + outputHelper.WriteLine($"Connection string is {connectionString}"); + _container = container; _connectionString = connectionString; _connection = connection; @@ -75,10 +78,11 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - await Context.DisposeAsync(); - await _connection.CloseAsync(); - await _container.DisposeAsync(); + await Task.CompletedTask; + //await Context.DisposeAsync(); + //await _connection.CloseAsync(); await _factory.DisposeAsync(); + await _container.DisposeAsync(); } private FlotillaDbContext CreateContext() diff --git a/backend/api.test/TestWebApplicationFactory.cs b/backend/api.test/TestWebApplicationFactory.cs index 813d4e798..d1cce9212 100644 --- a/backend/api.test/TestWebApplicationFactory.cs +++ b/backend/api.test/TestWebApplicationFactory.cs @@ -1,5 +1,7 @@ -using System.IO; +using System; +using System.IO; using System.Linq; +using System.Threading.Tasks; using Api.Database.Context; using Api.Services; using Api.Test.Mocks; @@ -81,5 +83,11 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) } ); } + + public override async ValueTask DisposeAsync() + { + Console.WriteLine("Test"); + await base.DisposeAsync(); + } } } diff --git a/backend/api.test/api.test.csproj b/backend/api.test/api.test.csproj index a6fa51e5e..8613e2ebd 100644 --- a/backend/api.test/api.test.csproj +++ b/backend/api.test/api.test.csproj @@ -14,7 +14,7 @@ - + all