isen-ng/testcontainers-dotnet

Error when using TestContainers.Container.Database.MsSql together with core TestContainers

jorgeolive opened this issue · 2 comments

Hello,

When using TestContainers.Container.Database.MsSql in a simple XUnit test project that has TestContainers library installed, I am getting an error when trying to build the container:

csproj configuration:


 <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
		<PackageReference Include="Testcontainers" Version="2.3.0" />
		<PackageReference Include="TestContainers.Container.Database.MsSql" Version="1.5.4" />
		<PackageReference Include="xunit" Version="2.4.2" />
		<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
			<PrivateAssets>all</PrivateAssets>
		</PackageReference>
		<PackageReference Include="coverlet.collector" Version="3.1.2">
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
			<PrivateAssets>all</PrivateAssets>
		</PackageReference>
	</ItemGroup>

</Project>

Code:

public class MsSqlContainerTestError
    { 
        public MsSqlContainerTestError()
        {
        }

        [Fact]
        public async Task Error()
        {
            var container = new ContainerBuilder<MsSqlContainer>()
               .ConfigureDatabaseConfiguration("sa", "My_password@", "master")
               .Build();

            await container.StartAsync();
        }
    }

Error:

System.AggregateException : One or more errors occurred. (Method not found: 'Void Docker.DotNet.DockerClientConfiguration..ctor(System.Uri, Docker.DotNet.Credentials, System.TimeSpan)'.) (The following constructor parameters did not have matching fixture data: AuthAdminDbInfrastructure testInfrastructure)
---- System.MissingMethodException : Method not found: 'Void Docker.DotNet.DockerClientConfiguration..ctor(System.Uri, Docker.DotNet.Credentials, System.TimeSpan)'.
---- The following constructor parameters did not have matching fixture data: AuthAdminDbInfrastructure testInfrastructure

Windows 10, Docker Version:


docker version
Client:
 Cloud integration: v1.0.29
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:08:16 2022
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.14.1 (91661)
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 18:00:19 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.9
  GitCommit:        1c90a442489720eec95342e1789ee8a5e1b9536f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Hmm.. This looks weird.... if the constructor doesn't exist, the library wouldn't be able to even compile.
I'll investigate this over the weekend.

Ah ha. I see the problem now.

<PackageReference Include="Testcontainers" Version="2.3.0" />
<PackageReference Include="TestContainers.Container.Database.MsSql" Version="1.5.4" />

Apparently Testcontainers comes from the official testcontainer-dotnet repo. The underlying library version they use and what I use are incompatible.

Eg, to fix the problem, you should use libraries from a single repo and not mix them.

I would recommend you to use the official repo instead of mine as they are a lot more active in maintaining it. If they don't have a MsSql container, maybe you can contribute to them, and immortalizing your name in their repo