From 7ab19226d834eeb8efaee91e06547100674b51cd Mon Sep 17 00:00:00 2001 From: K-Dud Date: Fri, 15 Nov 2024 13:35:51 +0100 Subject: [PATCH] upgrade testcontainers --- .../Contexture.Api.Tests.fsproj | 3 ++- backend/Contexture.Api.Tests/EventStore.Tests.fs | 2 +- .../Contexture.Api.Tests/PositionStorage.Tests.fs | 10 +++++----- backend/Contexture.Api.Tests/SqlServerFixture.fs | 15 ++++----------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/backend/Contexture.Api.Tests/Contexture.Api.Tests.fsproj b/backend/Contexture.Api.Tests/Contexture.Api.Tests.fsproj index ff8ca034..0309b544 100644 --- a/backend/Contexture.Api.Tests/Contexture.Api.Tests.fsproj +++ b/backend/Contexture.Api.Tests/Contexture.Api.Tests.fsproj @@ -39,7 +39,8 @@ - + + diff --git a/backend/Contexture.Api.Tests/EventStore.Tests.fs b/backend/Contexture.Api.Tests/EventStore.Tests.fs index 90f73a37..5cb347ba 100644 --- a/backend/Contexture.Api.Tests/EventStore.Tests.fs +++ b/backend/Contexture.Api.Tests/EventStore.Tests.fs @@ -264,7 +264,7 @@ type MsSqlBackedEventStore(msSql: MsSqlFixture) = let config = MsSqlPersistenceOptions( loggerFactory, - ConnectionString = msSql.Container.ConnectionString, + ConnectionString = msSql.Container.GetConnectionString(), StreamsTableName = $"streams_{Interlocked.Increment(counter)}_{this.GetType().Name}", Serializer = NStoreBased.JsonMsSqlSerializer.Default ) diff --git a/backend/Contexture.Api.Tests/PositionStorage.Tests.fs b/backend/Contexture.Api.Tests/PositionStorage.Tests.fs index 6ea6b454..c40aff34 100644 --- a/backend/Contexture.Api.Tests/PositionStorage.Tests.fs +++ b/backend/Contexture.Api.Tests/PositionStorage.Tests.fs @@ -81,10 +81,10 @@ type SqlServerPositionStorage(msSql: MsSqlFixture) = inherit PositionStorageBehavior() override this.EmptyStorage() = - SqlServer.PositionStorage(msSql.Container.ConnectionString) + SqlServer.PositionStorage(msSql.Container.GetConnectionString()) override this.StorageWith items = task { - use client = new SqlConnection(msSql.Container.ConnectionString) + use client = new SqlConnection(msSql.Container.GetConnectionString()) do! client.OpenAsync() // using string concatenation over parameters here is OK because it's just (unit) test code @@ -98,15 +98,15 @@ type SqlServerPositionStorage(msSql: MsSqlFixture) = let! result = command.ExecuteNonQueryAsync() Assert.Equal(items |> List.length, result) - return SqlServer.PositionStorage(msSql.Container.ConnectionString) :> IStorePositions + return SqlServer.PositionStorage(msSql.Container.GetConnectionString()) :> IStorePositions } interface IAsyncLifetime with member this.DisposeAsync() = - SqlServer.PositionStorage.RemoveSchema(msSql.Container.ConnectionString) + SqlServer.PositionStorage.RemoveSchema(msSql.Container.GetConnectionString()) member this.InitializeAsync() = - SqlServer.PositionStorage.CreateSchema(msSql.Container.ConnectionString) + SqlServer.PositionStorage.CreateSchema(msSql.Container.GetConnectionString()) interface IClassFixture with diff --git a/backend/Contexture.Api.Tests/SqlServerFixture.fs b/backend/Contexture.Api.Tests/SqlServerFixture.fs index 11d95a58..a793eb28 100644 --- a/backend/Contexture.Api.Tests/SqlServerFixture.fs +++ b/backend/Contexture.Api.Tests/SqlServerFixture.fs @@ -1,27 +1,20 @@ namespace Contexture.Api.Tests -#nowarn "44" // ContainerBuilder() is deprecated but does not provide a clear guidance yet - open System open System.Threading -open DotNet.Testcontainers.Builders -open DotNet.Testcontainers.Configurations -open DotNet.Testcontainers.Containers +open Testcontainers.MsSql open Xunit type MsSqlFixture() = static let mutable counter = ref 0 - let container = + let container = let containerConfiguration = - ContainerBuilder() - .WithDatabase(new MsSqlTestcontainerConfiguration(Password = "localdevpassword#123")) - .WithImage("mcr.microsoft.com/mssql/server:2019-latest") + MsSqlBuilder() .WithName($"MS-SQL-Integration-Tests-{Interlocked.Increment counter}") .WithCleanUp(false) .WithAutoRemove(true) - let instance = containerConfiguration.Build() - instance + containerConfiguration.Build() member _.Container = container