diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml
index d8579b763..61335dca3 100644
--- a/.github/workflows/cicd.yml
+++ b/.github/workflows/cicd.yml
@@ -58,7 +58,7 @@ jobs:
run: dotnet cake --target=Build
- name: Run Tests
- run: dotnet cake --target=Tests --test-filter=FullyQualifiedName~${{ startsWith(matrix.os, 'ubuntu') && 'Testcontainers' || 'DotNet.Testcontainers.Tests.Unit.Containers.Windows' }}
+ run: dotnet cake --target=Tests --test-filter=${{ startsWith(matrix.os, 'ubuntu') && 'FullyQualifiedName~Testcontainers' || 'DockerPlatform=Windows' }}
- name: Upload Test And Coverage Results
uses: actions/upload-artifact@v3
diff --git a/Packages.props b/Packages.props
index 58d6afd73..7de61f0bc 100644
--- a/Packages.props
+++ b/Packages.props
@@ -21,6 +21,5 @@
-
diff --git a/Testcontainers.sln b/Testcontainers.sln
index c94dc9b01..1adf99b68 100644
--- a/Testcontainers.sln
+++ b/Testcontainers.sln
@@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{673F23AE-769
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CosmosDb", "src\Testcontainers.CosmosDb\Testcontainers.CosmosDb.csproj", "{A724806F-8C94-4438-8011-04A9A1575318}"
+EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Couchbase", "src\Testcontainers.Couchbase\Testcontainers.Couchbase.csproj", "{58E94721-2681-4D82-8D94-0B2F9DB0D575}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CouchDb", "src\Testcontainers.CouchDb\Testcontainers.CouchDb.csproj", "{DCECB1F6-D9AA-431F-AE42-25D56B9E7DFC}"
@@ -59,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers", "src\Testc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Commons", "tests\Testcontainers.Commons\Testcontainers.Commons.csproj", "{2478673C-B063-469D-ABD1-0C3E0A25541B}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CosmosDb.Tests", "tests\Testcontainers.CosmosDb.Tests\Testcontainers.CosmosDb.Tests.csproj", "{BD445A54-F411-4758-955E-397A1E98680C}"
+EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Couchbase.Tests", "tests\Testcontainers.Couchbase.Tests\Testcontainers.Couchbase.Tests.csproj", "{809322BA-D690-4F2B-B884-23F895663963}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.CouchDb.Tests", "tests\Testcontainers.CouchDb.Tests\Testcontainers.CouchDb.Tests.csproj", "{E4520FB1-4466-4DCA-AD08-4075102C68D3}"
@@ -118,6 +122,10 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {A724806F-8C94-4438-8011-04A9A1575318}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A724806F-8C94-4438-8011-04A9A1575318}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A724806F-8C94-4438-8011-04A9A1575318}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A724806F-8C94-4438-8011-04A9A1575318}.Release|Any CPU.Build.0 = Release|Any CPU
{58E94721-2681-4D82-8D94-0B2F9DB0D575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58E94721-2681-4D82-8D94-0B2F9DB0D575}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58E94721-2681-4D82-8D94-0B2F9DB0D575}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -210,6 +218,10 @@ Global
{2478673C-B063-469D-ABD1-0C3E0A25541B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2478673C-B063-469D-ABD1-0C3E0A25541B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2478673C-B063-469D-ABD1-0C3E0A25541B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {BD445A54-F411-4758-955E-397A1E98680C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {BD445A54-F411-4758-955E-397A1E98680C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {BD445A54-F411-4758-955E-397A1E98680C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {BD445A54-F411-4758-955E-397A1E98680C}.Release|Any CPU.Build.0 = Release|Any CPU
{809322BA-D690-4F2B-B884-23F895663963}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{809322BA-D690-4F2B-B884-23F895663963}.Debug|Any CPU.Build.0 = Debug|Any CPU
{809322BA-D690-4F2B-B884-23F895663963}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -312,6 +324,7 @@ Global
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
+ {A724806F-8C94-4438-8011-04A9A1575318} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{58E94721-2681-4D82-8D94-0B2F9DB0D575} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{DCECB1F6-D9AA-431F-AE42-25D56B9E7DFC} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{2EAFA567-9F68-4C52-9DBC-8F3EC11BB2CE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
@@ -335,6 +348,7 @@ Global
{64A87DE5-29B0-4A54-9E74-560484D8C7C0} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{2478673C-B063-469D-ABD1-0C3E0A25541B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
+ {BD445A54-F411-4758-955E-397A1E98680C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{809322BA-D690-4F2B-B884-23F895663963} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{E4520FB1-4466-4DCA-AD08-4075102C68D3} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{101515E6-74C1-40F9-85C8-871F742A378D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
diff --git a/src/Testcontainers.CosmosDb/.editorconfig b/src/Testcontainers.CosmosDb/.editorconfig
new file mode 100644
index 000000000..6f066619d
--- /dev/null
+++ b/src/Testcontainers.CosmosDb/.editorconfig
@@ -0,0 +1 @@
+root = true
\ No newline at end of file
diff --git a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs
new file mode 100644
index 000000000..1b5838fd2
--- /dev/null
+++ b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs
@@ -0,0 +1,68 @@
+namespace Testcontainers.CosmosDb;
+
+///
+[PublicAPI]
+public sealed class CosmosDbBuilder : ContainerBuilder
+{
+ public const string CosmosDbImage = "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest";
+
+ public const ushort CosmosDbPort = 8081;
+
+ public const string DefaultAccountKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public CosmosDbBuilder()
+ : this(new CosmosDbConfiguration())
+ {
+ DockerResourceConfiguration = Init().DockerResourceConfiguration;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The Docker resource configuration.
+ private CosmosDbBuilder(CosmosDbConfiguration resourceConfiguration)
+ : base(resourceConfiguration)
+ {
+ DockerResourceConfiguration = resourceConfiguration;
+ }
+
+ ///
+ protected override CosmosDbConfiguration DockerResourceConfiguration { get; }
+
+ ///
+ public override CosmosDbContainer Build()
+ {
+ Validate();
+ return new CosmosDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
+ }
+
+ ///
+ protected override CosmosDbBuilder Init()
+ {
+ return base.Init()
+ .WithImage(CosmosDbImage)
+ .WithPortBinding(CosmosDbPort, true)
+ .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Started"));
+ }
+
+ ///
+ protected override CosmosDbBuilder Clone(IResourceConfiguration resourceConfiguration)
+ {
+ return Merge(DockerResourceConfiguration, new CosmosDbConfiguration(resourceConfiguration));
+ }
+
+ ///
+ protected override CosmosDbBuilder Clone(IContainerConfiguration resourceConfiguration)
+ {
+ return Merge(DockerResourceConfiguration, new CosmosDbConfiguration(resourceConfiguration));
+ }
+
+ ///
+ protected override CosmosDbBuilder Merge(CosmosDbConfiguration oldValue, CosmosDbConfiguration newValue)
+ {
+ return new CosmosDbBuilder(new CosmosDbConfiguration(oldValue, newValue));
+ }
+}
\ No newline at end of file
diff --git a/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs b/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs
new file mode 100644
index 000000000..c623b6aef
--- /dev/null
+++ b/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs
@@ -0,0 +1,53 @@
+namespace Testcontainers.CosmosDb;
+
+///
+[PublicAPI]
+public sealed class CosmosDbConfiguration : ContainerConfiguration
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public CosmosDbConfiguration()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The Docker resource configuration.
+ public CosmosDbConfiguration(IResourceConfiguration resourceConfiguration)
+ : base(resourceConfiguration)
+ {
+ // Passes the configuration upwards to the base implementations to create an updated immutable copy.
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The Docker resource configuration.
+ public CosmosDbConfiguration(IContainerConfiguration resourceConfiguration)
+ : base(resourceConfiguration)
+ {
+ // Passes the configuration upwards to the base implementations to create an updated immutable copy.
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The Docker resource configuration.
+ public CosmosDbConfiguration(CosmosDbConfiguration resourceConfiguration)
+ : this(new CosmosDbConfiguration(), resourceConfiguration)
+ {
+ // Passes the configuration upwards to the base implementations to create an updated immutable copy.
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The old Docker resource configuration.
+ /// The new Docker resource configuration.
+ public CosmosDbConfiguration(CosmosDbConfiguration oldValue, CosmosDbConfiguration newValue)
+ : base(oldValue, newValue)
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Testcontainers.CosmosDb/CosmosDbContainer.cs b/src/Testcontainers.CosmosDb/CosmosDbContainer.cs
new file mode 100644
index 000000000..15e4c2243
--- /dev/null
+++ b/src/Testcontainers.CosmosDb/CosmosDbContainer.cs
@@ -0,0 +1,61 @@
+namespace Testcontainers.CosmosDb;
+
+///
+[PublicAPI]
+public sealed class CosmosDbContainer : DockerContainer
+{
+ private readonly CosmosDbConfiguration _configuration;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The container configuration.
+ /// The logger.
+ public CosmosDbContainer(CosmosDbConfiguration configuration, ILogger logger)
+ : base(configuration, logger)
+ {
+ _configuration = configuration;
+ }
+
+ ///
+ /// Gets the CosmosDb connection string.
+ ///
+ /// The CosmosDb connection string.
+ public string GetConnectionString()
+ {
+ var properties = new Dictionary();
+ properties.Add("AccountEndpoint", new UriBuilder("https", Hostname, GetMappedPublicPort(CosmosDbBuilder.CosmosDbPort)).ToString());
+ properties.Add("AccountKey", CosmosDbBuilder.DefaultAccountKey);
+ return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value)));
+ }
+
+ ///
+ /// Gets a configured HTTP message handler that automatically trusts the CosmosDb Emulator's certificate.
+ ///
+ public HttpMessageHandler HttpMessageHandler => new UriRewriter(Hostname, GetMappedPublicPort(CosmosDbBuilder.CosmosDbPort));
+
+ ///
+ /// Gets a configured HTTP client that automatically trusts the CosmosDb Emulator's certificate.
+ ///
+ public HttpClient HttpClient => new HttpClient(HttpMessageHandler);
+
+ private sealed class UriRewriter : DelegatingHandler
+ {
+ private readonly string _hostname;
+
+ private readonly ushort _port;
+
+ public UriRewriter(string hostname, ushort port)
+ : base(new HttpClientHandler { ServerCertificateCustomValidationCallback = (_, _, _, _) => true })
+ {
+ _hostname = hostname;
+ _port = port;
+ }
+
+ protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ {
+ request.RequestUri = new UriBuilder("https", _hostname, _port, request.RequestUri.PathAndQuery).Uri;
+ return base.SendAsync(request, cancellationToken);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Testcontainers.CosmosDb/Testcontainers.CosmosDb.csproj b/src/Testcontainers.CosmosDb/Testcontainers.CosmosDb.csproj
new file mode 100644
index 000000000..37a1be0f7
--- /dev/null
+++ b/src/Testcontainers.CosmosDb/Testcontainers.CosmosDb.csproj
@@ -0,0 +1,12 @@
+
+
+ netstandard2.0;netstandard2.1
+ latest
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Testcontainers.CosmosDb/Usings.cs b/src/Testcontainers.CosmosDb/Usings.cs
new file mode 100644
index 000000000..fad310b40
--- /dev/null
+++ b/src/Testcontainers.CosmosDb/Usings.cs
@@ -0,0 +1,12 @@
+global using System;
+global using System.Collections.Generic;
+global using System.Linq;
+global using System.Net.Http;
+global using System.Threading;
+global using System.Threading.Tasks;
+global using Docker.DotNet.Models;
+global using DotNet.Testcontainers.Builders;
+global using DotNet.Testcontainers.Configurations;
+global using DotNet.Testcontainers.Containers;
+global using JetBrains.Annotations;
+global using Microsoft.Extensions.Logging;
\ No newline at end of file
diff --git a/src/Testcontainers.MongoDb/MongoDbContainer.cs b/src/Testcontainers.MongoDb/MongoDbContainer.cs
index 12aa06810..5271abba3 100644
--- a/src/Testcontainers.MongoDb/MongoDbContainer.cs
+++ b/src/Testcontainers.MongoDb/MongoDbContainer.cs
@@ -43,18 +43,7 @@ public async Task ExecScriptAsync(string scriptContent, Cancellation
await CopyFileAsync(scriptFilePath, Encoding.Default.GetBytes(scriptContent), 493, 0, 0, ct)
.ConfigureAwait(false);
-
- var mongoShellCommand = new MongoDbShellCommand($"load('{scriptFilePath}')", _configuration.Username, _configuration.Password);
-
- Logger.LogInformation(string.Format("{0}: {1}", Id, string.Join(" ", mongoShellCommand)));
-
- var result = await ExecAsync(mongoShellCommand, ct)
+ return await ExecAsync(new MongoDbShellCommand($"load('{scriptFilePath}')", _configuration.Username, _configuration.Password), ct)
.ConfigureAwait(false);
-
- Logger.LogInformation(string.Format("{0}: {1}", "ExitCode", result.ExitCode));
- Logger.LogInformation(string.Format("{0}: {1}", "Stdout", result.Stdout));
- Logger.LogInformation(string.Format("{0}: {1}", "Stderr", result.Stderr));
-
- return result;
}
}
\ No newline at end of file
diff --git a/src/Testcontainers.WebDriver/Usings.cs b/src/Testcontainers.WebDriver/Usings.cs
index 072176cc2..6b26f91d1 100644
--- a/src/Testcontainers.WebDriver/Usings.cs
+++ b/src/Testcontainers.WebDriver/Usings.cs
@@ -1,7 +1,4 @@
global using System;
-global using System.Collections.Generic;
-global using System.Collections.ObjectModel;
-global using System.Globalization;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
diff --git a/src/Testcontainers.WebDriver/WebDriverBrowser.cs b/src/Testcontainers.WebDriver/WebDriverBrowser.cs
index 14982e946..2d68dc881 100644
--- a/src/Testcontainers.WebDriver/WebDriverBrowser.cs
+++ b/src/Testcontainers.WebDriver/WebDriverBrowser.cs
@@ -9,17 +9,17 @@
///
/// Gets the Selenium standalone Chrome configuration.
///
- public static WebDriverBrowser Chrome = new WebDriverBrowser("selenium/standalone-chrome:110.0");
+ public static readonly WebDriverBrowser Chrome = new WebDriverBrowser("selenium/standalone-chrome:110.0");
///
/// Gets the Selenium standalone Firefox configuration.
///
- public static WebDriverBrowser Firefox = new WebDriverBrowser("selenium/standalone-firefox:110.0");
+ public static readonly WebDriverBrowser Firefox = new WebDriverBrowser("selenium/standalone-firefox:110.0");
///
/// Gets the Selenium standalone Edge configuration.
///
- public static WebDriverBrowser Edge = new WebDriverBrowser("selenium/standalone-edge:110.0");
+ public static readonly WebDriverBrowser Edge = new WebDriverBrowser("selenium/standalone-edge:110.0");
///
/// Initializes a new instance of the struct.
diff --git a/src/Testcontainers/Configurations/WaitStrategies/UntilWindowsPortIsAvailable.cs b/src/Testcontainers/Configurations/WaitStrategies/UntilWindowsPortIsAvailable.cs
index 1c74bc153..1d2c8e2c3 100644
--- a/src/Testcontainers/Configurations/WaitStrategies/UntilWindowsPortIsAvailable.cs
+++ b/src/Testcontainers/Configurations/WaitStrategies/UntilWindowsPortIsAvailable.cs
@@ -3,7 +3,7 @@ namespace DotNet.Testcontainers.Configurations
internal class UntilWindowsPortIsAvailable : UntilWindowsCommandIsCompleted
{
public UntilWindowsPortIsAvailable(int port)
- : base($"Exit !(Test-NetConnection -ComputerName 'localhost' -Port {port}).TcpTestSucceeded")
+ : base($"Exit(-Not((Test-NetConnection -ComputerName 'localhost' -Port {port}).TcpTestSucceeded))")
{
}
}
diff --git a/src/Testcontainers/_OBSOLETE_/Modules/Databases/CosmosDbTestcontainer.cs b/src/Testcontainers/_OBSOLETE_/Modules/Databases/CosmosDbTestcontainer.cs
deleted file mode 100644
index c563b99ca..000000000
--- a/src/Testcontainers/_OBSOLETE_/Modules/Databases/CosmosDbTestcontainer.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-namespace DotNet.Testcontainers.Containers
-{
- using System;
- using System.Net.Http;
- using System.Threading;
- using System.Threading.Tasks;
- using DotNet.Testcontainers.Configurations;
- using JetBrains.Annotations;
- using Microsoft.Extensions.Logging;
-
- ///
- [PublicAPI]
- public sealed class CosmosDbTestcontainer : TestcontainerDatabase
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The Testcontainers configuration.
- /// The logger.
- internal CosmosDbTestcontainer(IContainerConfiguration configuration, ILogger logger)
- : base(configuration, logger)
- {
- }
-
- ///
- public override string ConnectionString =>
- $"AccountEndpoint=https://{this.Hostname}:{this.Port};AccountKey={this.Password}";
-
- ///
- /// Gets a configured HTTP message handler.
- ///
- public HttpMessageHandler HttpMessageHandler => new UriRewriter(this.Hostname, this.Port);
-
- ///
- /// Gets a configured HTTP client.
- ///
- public HttpClient HttpClient => new HttpClient(this.HttpMessageHandler);
-
- private sealed class UriRewriter : DelegatingHandler
- {
- private readonly string hostname;
-
- private readonly int port;
-
-#pragma warning disable S4830
-
- public UriRewriter(string hostname, int port)
- : base(new HttpClientHandler { ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) => true })
- {
- this.hostname = hostname;
- this.port = port;
- }
-
-#pragma warning restore S4830
-
- protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
- {
- request.RequestUri = new UriBuilder("https", this.hostname, this.port, request.RequestUri.PathAndQuery).Uri;
- return base.SendAsync(request, cancellationToken);
- }
- }
- }
-}
diff --git a/src/Testcontainers/_OBSOLETE_/Modules/Databases/CosmosDbTestcontainerConfiguration.cs b/src/Testcontainers/_OBSOLETE_/Modules/Databases/CosmosDbTestcontainerConfiguration.cs
deleted file mode 100644
index 7499f593b..000000000
--- a/src/Testcontainers/_OBSOLETE_/Modules/Databases/CosmosDbTestcontainerConfiguration.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-namespace DotNet.Testcontainers.Configurations
-{
- using System;
- using System.Globalization;
- using System.IO;
- using DotNet.Testcontainers.Builders;
- using JetBrains.Annotations;
-
- ///
- [PublicAPI]
- public sealed class CosmosDbTestcontainerConfiguration : TestcontainerDatabaseConfiguration
- {
- public const string CosmosDbImage = "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest";
-
- private const int CosmosDbPort = 8081;
-
- ///
- /// Initializes a new instance of the class.
- ///
- public CosmosDbTestcontainerConfiguration()
- : this(CosmosDbImage)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The Docker image.
- public CosmosDbTestcontainerConfiguration(string image)
- : base(image, CosmosDbPort)
- {
- this.Database = "default";
- this.IpAddressOverride = "127.0.0.1";
- this.PartitionCount = 2;
- this.OutputConsumer = Consume.RedirectStdoutAndStderrToStream(new MemoryStream(), new MemoryStream());
- this.WaitStrategy = Wait.ForUnixContainer().UntilMessageIsLogged(this.OutputConsumer.Stdout, "Started|Shutting");
- }
-
- ///
- public override string Database
- {
- get => this.Environments["AZURE_COSMOS_EMULATOR_DATABASE"];
- set => this.Environments["AZURE_COSMOS_EMULATOR_DATABASE"] = value;
- }
-
- ///
- public override string Password
- {
- // Default Cosmos DB Emulator authentication key: https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator?tabs=ssl-netstd21#authenticate-requests.
- get => "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
- set => throw new NotImplementedException();
- }
-
- public bool EnableDataPersistence
- {
- get => bool.TryParse(this.Environments["AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE"], out var enableDataPersistence) && enableDataPersistence;
- set => this.Environments["AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE"] = value.ToString().ToLowerInvariant();
- }
-
- public string IpAddressOverride
- {
- get => this.Environments["AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE"];
- set => this.Environments["AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE"] = value;
- }
-
- public int PartitionCount
- {
- get => int.TryParse(this.Environments["AZURE_COSMOS_EMULATOR_PARTITION_COUNT"], NumberStyles.Integer, CultureInfo.InvariantCulture, out var partitionCount) ? partitionCount : 1;
- set => this.Environments["AZURE_COSMOS_EMULATOR_PARTITION_COUNT"] = value.ToString(CultureInfo.InvariantCulture);
- }
-
- ///
- public override IOutputConsumer OutputConsumer { get; }
-
- ///
- public override IWaitForContainerOS WaitStrategy { get; }
- }
-}
diff --git a/tests/Testcontainers.Commons/.editorconfig b/tests/Testcontainers.Commons/.editorconfig
new file mode 100644
index 000000000..6f066619d
--- /dev/null
+++ b/tests/Testcontainers.Commons/.editorconfig
@@ -0,0 +1 @@
+root = true
\ No newline at end of file
diff --git a/tests/Testcontainers.Commons/CommonCommands.cs b/tests/Testcontainers.Commons/CommonCommands.cs
index 3539fc26a..7ce8f64bf 100644
--- a/tests/Testcontainers.Commons/CommonCommands.cs
+++ b/tests/Testcontainers.Commons/CommonCommands.cs
@@ -1,10 +1,7 @@
-namespace DotNet.Testcontainers.Commons
-{
- using JetBrains.Annotations;
+namespace DotNet.Testcontainers.Commons;
- [PublicAPI]
- public static class CommonCommands
- {
+[PublicAPI]
+public static class CommonCommands
+{
public static readonly string[] SleepInfinity = { "/bin/sh", "-c", "trap : TERM INT; sleep infinity & wait" };
- }
-}
+}
\ No newline at end of file
diff --git a/tests/Testcontainers.Commons/CommonCredentials.cs b/tests/Testcontainers.Commons/CommonCredentials.cs
index a0be976b2..3e89feb4b 100644
--- a/tests/Testcontainers.Commons/CommonCredentials.cs
+++ b/tests/Testcontainers.Commons/CommonCredentials.cs
@@ -1,12 +1,9 @@
-namespace DotNet.Testcontainers.Commons
-{
- using JetBrains.Annotations;
+namespace DotNet.Testcontainers.Commons;
- [PublicAPI]
- public static class CommonCredentials
- {
+[PublicAPI]
+public static class CommonCredentials
+{
public const string AwsAccessKey = "AKIAIOSFODNN7EXAMPLE";
public const string AwsSecretKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
- }
-}
+}
\ No newline at end of file
diff --git a/tests/Testcontainers.Commons/CommonImages.cs b/tests/Testcontainers.Commons/CommonImages.cs
index 3028ea928..eb6de433a 100644
--- a/tests/Testcontainers.Commons/CommonImages.cs
+++ b/tests/Testcontainers.Commons/CommonImages.cs
@@ -1,15 +1,13 @@
-namespace DotNet.Testcontainers.Commons
-{
- using DotNet.Testcontainers.Images;
- using JetBrains.Annotations;
+namespace DotNet.Testcontainers.Commons;
- [PublicAPI]
- public static class CommonImages
- {
+[PublicAPI]
+public static class CommonImages
+{
public static readonly IImage Ryuk = new DockerImage("testcontainers/ryuk:0.3.4");
public static readonly IImage Alpine = new DockerImage("alpine:3.17");
public static readonly IImage Nginx = new DockerImage("nginx:1.22");
- }
-}
+
+ public static readonly IImage ServerCore = new DockerImage("mcr.microsoft.com/windows/servercore:ltsc2022");
+}
\ No newline at end of file
diff --git a/tests/Testcontainers.Commons/DockerCli.cs b/tests/Testcontainers.Commons/DockerCli.cs
index 10c78c6e5..0b6e94bc2 100644
--- a/tests/Testcontainers.Commons/DockerCli.cs
+++ b/tests/Testcontainers.Commons/DockerCli.cs
@@ -1,143 +1,137 @@
-namespace DotNet.Testcontainers.Commons
+namespace DotNet.Testcontainers.Commons;
+
+[PublicAPI]
+public static class DockerCli
{
- using System;
- using System.Diagnostics;
- using System.Text;
- using JetBrains.Annotations;
-
- [PublicAPI]
- public static class DockerCli
- {
[PublicAPI]
public enum DockerPlatform
{
- ///
- /// Docker Linux engine.
- ///
- Linux,
-
- ///
- /// Docker Windows engine.
- ///
- Windows,
+ ///
+ /// Docker Linux engine.
+ ///
+ Linux,
+
+ ///
+ /// Docker Windows engine.
+ ///
+ Windows,
}
[PublicAPI]
public enum DockerResource
{
- ///
- /// Docker container resource.
- ///
- Container,
-
- ///
- /// Docker image resource.
- ///
- Image,
-
- ///
- /// Docker network resource.
- ///
- Network,
-
- ///
- /// Docker volume resource.
- ///
- Volume,
+ ///
+ /// Docker container resource.
+ ///
+ Container,
+
+ ///
+ /// Docker image resource.
+ ///
+ Image,
+
+ ///
+ /// Docker network resource.
+ ///
+ Network,
+
+ ///
+ /// Docker volume resource.
+ ///
+ Volume,
}
public static bool PlatformIsEnabled(DockerPlatform platform)
{
- var commandResult = new Command("version", "--format '{{.Server.Os}}'").Execute();
- return 0.Equals(commandResult.ExitCode) && commandResult.Stdout.Contains(platform.ToString().ToLowerInvariant());
+ var commandResult = new Command("version", "--format '{{.Server.Os}}'").Execute();
+ return 0.Equals(commandResult.ExitCode) && commandResult.Stdout.Contains(platform.ToString().ToLowerInvariant());
}
public static bool ResourceExists(DockerResource resource, string id)
{
- var commandResult = new Command("inspect", "--type=" + resource.ToString().ToLowerInvariant(), id).Execute();
- return 0.Equals(commandResult.ExitCode);
+ var commandResult = new Command("inspect", "--type=" + resource.ToString().ToLowerInvariant(), id).Execute();
+ return 0.Equals(commandResult.ExitCode);
}
[PublicAPI]
private sealed class Command
{
- private readonly ProcessStartInfo processStartInfo = new ProcessStartInfo();
-
- private readonly StringBuilder stdout = new StringBuilder();
-
- private readonly StringBuilder stderr = new StringBuilder();
-
- public Command(params string[] arguments)
- {
- const string executable = "docker";
- this.processStartInfo.FileName = executable;
- this.processStartInfo.Arguments = string.Join(" ", arguments);
- this.processStartInfo.RedirectStandardOutput = true;
- this.processStartInfo.RedirectStandardError = true;
- this.processStartInfo.UseShellExecute = false;
- }
+ private readonly ProcessStartInfo _processStartInfo = new ProcessStartInfo();
- public CommandResult Execute()
- {
- DateTime startTime;
+ private readonly StringBuilder _stdout = new StringBuilder();
- DateTime exitTime;
+ private readonly StringBuilder _stderr = new StringBuilder();
- var process = new Process();
- process.StartInfo = this.processStartInfo;
- process.OutputDataReceived += this.AppendStdout;
- process.ErrorDataReceived += this.AppendStderr;
-
- try
+ public Command(params string[] arguments)
{
- startTime = DateTime.UtcNow;
- process.Start();
- process.BeginOutputReadLine();
- process.BeginErrorReadLine();
- process.WaitForExit();
+ const string executable = "docker";
+ _processStartInfo.FileName = executable;
+ _processStartInfo.Arguments = string.Join(" ", arguments);
+ _processStartInfo.RedirectStandardOutput = true;
+ _processStartInfo.RedirectStandardError = true;
+ _processStartInfo.UseShellExecute = false;
}
- finally
+
+ public CommandResult Execute()
{
- exitTime = DateTime.UtcNow;
- process.OutputDataReceived -= this.AppendStdout;
- process.ErrorDataReceived -= this.AppendStderr;
+ DateTime startTime;
+
+ DateTime exitTime;
+
+ var process = new Process();
+ process.StartInfo = _processStartInfo;
+ process.OutputDataReceived += AppendStdout;
+ process.ErrorDataReceived += AppendStderr;
+
+ try
+ {
+ startTime = DateTime.UtcNow;
+ process.Start();
+ process.BeginOutputReadLine();
+ process.BeginErrorReadLine();
+ process.WaitForExit();
+ }
+ finally
+ {
+ exitTime = DateTime.UtcNow;
+ process.OutputDataReceived -= AppendStdout;
+ process.ErrorDataReceived -= AppendStderr;
+ }
+
+ return new CommandResult(process.ExitCode, startTime, exitTime, _stdout.ToString(), _stderr.ToString());
}
- return new CommandResult(process.ExitCode, startTime, exitTime, this.stdout.ToString(), this.stderr.ToString());
- }
-
- private void AppendStdout(object sender, DataReceivedEventArgs e)
- {
- this.stdout.Append(e.Data);
- }
+ private void AppendStdout(object sender, DataReceivedEventArgs e)
+ {
+ _stdout.Append(e.Data);
+ }
- private void AppendStderr(object sender, DataReceivedEventArgs e)
- {
- this.stderr.Append(e.Data);
- }
+ private void AppendStderr(object sender, DataReceivedEventArgs e)
+ {
+ _stderr.Append(e.Data);
+ }
}
[PublicAPI]
private sealed class CommandResult
{
- public CommandResult(int exitCode, DateTime startTime, DateTime exitTime, string stdout, string stderr)
- {
- this.ExitCode = exitCode;
- this.StartTime = startTime;
- this.ExitTime = exitTime;
- this.Stdout = stdout;
- this.Stderr = stderr;
- }
+ public CommandResult(int exitCode, DateTime startTime, DateTime exitTime, string stdout, string stderr)
+ {
+ ExitCode = exitCode;
+ StartTime = startTime;
+ ExitTime = exitTime;
+ Stdout = stdout;
+ Stderr = stderr;
+ }
- public int ExitCode { get; }
+ public int ExitCode { get; }
- public DateTime StartTime { get; }
+ public DateTime StartTime { get; }
- public DateTime ExitTime { get; }
+ public DateTime ExitTime { get; }
- public string Stdout { get; }
+ public string Stdout { get; }
- public string Stderr { get; }
+ public string Stderr { get; }
}
- }
-}
+}
\ No newline at end of file
diff --git a/tests/Testcontainers.Commons/TestSession.cs b/tests/Testcontainers.Commons/TestSession.cs
index de1e708e5..832019245 100644
--- a/tests/Testcontainers.Commons/TestSession.cs
+++ b/tests/Testcontainers.Commons/TestSession.cs
@@ -1,17 +1,12 @@
-namespace DotNet.Testcontainers.Commons
-{
- using System;
- using System.IO;
- using JetBrains.Annotations;
+namespace DotNet.Testcontainers.Commons;
- [PublicAPI]
- public static class TestSession
- {
+[PublicAPI]
+public static class TestSession
+{
public static readonly string TempDirectoryPath = Path.Combine(Path.GetTempPath(), "testcontainers-tests", Guid.NewGuid().ToString("D"));
static TestSession()
{
- Directory.CreateDirectory(TempDirectoryPath);
+ Directory.CreateDirectory(TempDirectoryPath);
}
- }
-}
+}
\ No newline at end of file
diff --git a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj
index fb12c938b..254eef232 100644
--- a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj
+++ b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj
@@ -1,19 +1,15 @@
-
-
- netstandard2.0;netstandard2.1
- false
- false
- Debug;Release
- DotNet.Testcontainers.Commons
-
-
- true
-
-
-
-
-
-
-
-
+
+ netstandard2.0;netstandard2.1
+ false
+ false
+ true
+ latest
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/Testcontainers.Commons/Usings.cs b/tests/Testcontainers.Commons/Usings.cs
new file mode 100644
index 000000000..904e633f5
--- /dev/null
+++ b/tests/Testcontainers.Commons/Usings.cs
@@ -0,0 +1,6 @@
+global using System;
+global using System.Diagnostics;
+global using System.IO;
+global using System.Text;
+global using DotNet.Testcontainers.Images;
+global using JetBrains.Annotations;
\ No newline at end of file
diff --git a/tests/Testcontainers.CosmosDb.Tests/.editorconfig b/tests/Testcontainers.CosmosDb.Tests/.editorconfig
new file mode 100644
index 000000000..6f066619d
--- /dev/null
+++ b/tests/Testcontainers.CosmosDb.Tests/.editorconfig
@@ -0,0 +1 @@
+root = true
\ No newline at end of file
diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs
new file mode 100644
index 000000000..f5dcf9441
--- /dev/null
+++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs
@@ -0,0 +1,36 @@
+namespace Testcontainers.CosmosDb;
+
+public sealed class CosmosDbContainerTest : IAsyncLifetime
+{
+ private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder().Build();
+
+ public Task InitializeAsync()
+ {
+ return _cosmosDbContainer.StartAsync();
+ }
+
+ public Task DisposeAsync()
+ {
+ return _cosmosDbContainer.DisposeAsync().AsTask();
+ }
+
+ [Fact(Skip = "The Cosmos DB Linux Emulator Docker image does not run on Microsoft's CI environment (GitHub, Azure DevOps).")] // https://github.com/Azure/azure-cosmos-db-emulator-docker/issues/45.
+ public async Task AccountPropertiesIdReturnsLocalhost()
+ {
+ // Given
+ using var httpClient = _cosmosDbContainer.HttpClient;
+
+ var cosmosClientOptions = new CosmosClientOptions();
+ cosmosClientOptions.ConnectionMode = ConnectionMode.Gateway;
+ cosmosClientOptions.HttpClientFactory = () => httpClient;
+
+ using var cosmosClient = new CosmosClient(_cosmosDbContainer.GetConnectionString(), cosmosClientOptions);
+
+ // When
+ var accountProperties = await cosmosClient.ReadAccountAsync()
+ .ConfigureAwait(false);
+
+ // Then
+ Assert.Equal("localhost", accountProperties.Id);
+ }
+}
\ No newline at end of file
diff --git a/tests/Testcontainers.CosmosDb.Tests/Testcontainers.CosmosDb.Tests.csproj b/tests/Testcontainers.CosmosDb.Tests/Testcontainers.CosmosDb.Tests.csproj
new file mode 100644
index 000000000..914558fa3
--- /dev/null
+++ b/tests/Testcontainers.CosmosDb.Tests/Testcontainers.CosmosDb.Tests.csproj
@@ -0,0 +1,18 @@
+
+
+ net6.0
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/Testcontainers.CosmosDb.Tests/Usings.cs b/tests/Testcontainers.CosmosDb.Tests/Usings.cs
new file mode 100644
index 000000000..3f12d7755
--- /dev/null
+++ b/tests/Testcontainers.CosmosDb.Tests/Usings.cs
@@ -0,0 +1,4 @@
+global using System.Threading.Tasks;
+global using DotNet.Testcontainers.Commons;
+global using Microsoft.Azure.Cosmos;
+global using Xunit;
\ No newline at end of file
diff --git a/tests/Testcontainers.Platform.Linux.Tests/.editorconfig b/tests/Testcontainers.Platform.Linux.Tests/.editorconfig
new file mode 100644
index 000000000..6f066619d
--- /dev/null
+++ b/tests/Testcontainers.Platform.Linux.Tests/.editorconfig
@@ -0,0 +1 @@
+root = true
\ No newline at end of file
diff --git a/tests/Testcontainers.Platform.Linux.Tests/Testcontainers.Platform.Linux.Tests.csproj b/tests/Testcontainers.Platform.Linux.Tests/Testcontainers.Platform.Linux.Tests.csproj
index cf88fe3e8..e462071ca 100644
--- a/tests/Testcontainers.Platform.Linux.Tests/Testcontainers.Platform.Linux.Tests.csproj
+++ b/tests/Testcontainers.Platform.Linux.Tests/Testcontainers.Platform.Linux.Tests.csproj
@@ -1,18 +1,16 @@
-
-
- net6.0
- false
- false
- Debug;Release
-
-
-
-
-
-
-
-
-
-
-
+
+ net6.0
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/Testcontainers.Platform.Windows.Tests/.editorconfig b/tests/Testcontainers.Platform.Windows.Tests/.editorconfig
new file mode 100644
index 000000000..6f066619d
--- /dev/null
+++ b/tests/Testcontainers.Platform.Windows.Tests/.editorconfig
@@ -0,0 +1 @@
+root = true
\ No newline at end of file
diff --git a/tests/Testcontainers.Platform.Windows.Tests/SkipOnLinuxEngineAttribute.cs b/tests/Testcontainers.Platform.Windows.Tests/SkipOnLinuxEngineAttribute.cs
new file mode 100644
index 000000000..93cdd8888
--- /dev/null
+++ b/tests/Testcontainers.Platform.Windows.Tests/SkipOnLinuxEngineAttribute.cs
@@ -0,0 +1,15 @@
+namespace Testcontainers.Platform.Windows.Tests;
+
+[PublicAPI]
+public sealed class SkipOnLinuxEngineAttribute : FactAttribute
+{
+ private static readonly bool IsLinuxEngineEnabled = DockerCli.PlatformIsEnabled(DockerCli.DockerPlatform.Linux);
+
+ public SkipOnLinuxEngineAttribute()
+ {
+ if (IsLinuxEngineEnabled)
+ {
+ Skip = "Docker Windows engine is not available.";
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/Testcontainers.Platform.Windows.Tests/Testcontainers.Platform.Windows.Tests.csproj b/tests/Testcontainers.Platform.Windows.Tests/Testcontainers.Platform.Windows.Tests.csproj
index cf88fe3e8..e462071ca 100644
--- a/tests/Testcontainers.Platform.Windows.Tests/Testcontainers.Platform.Windows.Tests.csproj
+++ b/tests/Testcontainers.Platform.Windows.Tests/Testcontainers.Platform.Windows.Tests.csproj
@@ -1,18 +1,16 @@
-
-
- net6.0
- false
- false
- Debug;Release
-
-
-
-
-
-
-
-
-
-
-
+
+ net6.0
+ false
+ false
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/Testcontainers.Platform.Windows.Tests/Usings.cs b/tests/Testcontainers.Platform.Windows.Tests/Usings.cs
new file mode 100644
index 000000000..572db56a4
--- /dev/null
+++ b/tests/Testcontainers.Platform.Windows.Tests/Usings.cs
@@ -0,0 +1,6 @@
+global using DotNet.Testcontainers.Builders;
+global using DotNet.Testcontainers.Commons;
+global using DotNet.Testcontainers.Containers;
+global using JetBrains.Annotations;
+global using System.Threading.Tasks;
+global using Xunit;
\ No newline at end of file
diff --git a/tests/Testcontainers.Platform.Windows.Tests/WindowsContainerTest.cs b/tests/Testcontainers.Platform.Windows.Tests/WindowsContainerTest.cs
new file mode 100644
index 000000000..ba96292dd
--- /dev/null
+++ b/tests/Testcontainers.Platform.Windows.Tests/WindowsContainerTest.cs
@@ -0,0 +1,56 @@
+namespace Testcontainers.Platform.Windows.Tests;
+
+public abstract class WindowsContainerTest : IAsyncLifetime
+{
+ private readonly IContainer _container;
+
+ private WindowsContainerTest(IContainer container)
+ {
+ _container = container;
+ }
+
+ public Task InitializeAsync()
+ {
+ return _container.StartAsync();
+ }
+
+ public Task DisposeAsync()
+ {
+ return _container.DisposeAsync().AsTask();
+ }
+
+ [SkipOnLinuxEngine]
+ [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Windows))]
+ public void ContainerIsRunning()
+ {
+ Assert.Equal(TestcontainersStates.Running, _container.State);
+ }
+
+ [UsedImplicitly]
+ public sealed class UntilCommandIsCompleted : WindowsContainerTest
+ {
+ public UntilCommandIsCompleted()
+ : base(new ContainerBuilder()
+ .WithImage(CommonImages.ServerCore)
+ .WithEntrypoint("PowerShell", "-NoLogo", "-Command")
+ .WithCommand("Start-Sleep -Seconds 120")
+ .WithWaitStrategy(Wait.ForWindowsContainer().UntilCommandIsCompleted("Exit(-Not(Test-Path -Path 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'))"))
+ .Build())
+ {
+ }
+ }
+
+ [UsedImplicitly]
+ public sealed class UntilPortIsAvailable : WindowsContainerTest
+ {
+ public UntilPortIsAvailable()
+ : base(new ContainerBuilder()
+ .WithImage(CommonImages.ServerCore)
+ .WithEntrypoint("PowerShell", "-NoLogo", "-Command")
+ .WithCommand("$tcpListener = [System.Net.Sockets.TcpListener]80; $tcpListener.Start(); Start-Sleep -Seconds 120")
+ .WithWaitStrategy(Wait.ForWindowsContainer().UntilPortIsAvailable(80))
+ .Build())
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/Testcontainers.Tests/Fixtures/Containers/Unix/Modules/Databases/CosmosDbFixture.cs b/tests/Testcontainers.Tests/Fixtures/Containers/Unix/Modules/Databases/CosmosDbFixture.cs
deleted file mode 100644
index a671a8e0e..000000000
--- a/tests/Testcontainers.Tests/Fixtures/Containers/Unix/Modules/Databases/CosmosDbFixture.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-namespace DotNet.Testcontainers.Tests.Fixtures
-{
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- using DotNet.Testcontainers.Builders;
- using DotNet.Testcontainers.Configurations;
- using DotNet.Testcontainers.Containers;
- using JetBrains.Annotations;
- using Microsoft.Azure.Cosmos;
-
- [UsedImplicitly]
- public sealed class CosmosDbFixture : DatabaseFixture
- {
- private readonly CosmosDbTestcontainerConfiguration configuration = new CosmosDbTestcontainerConfiguration();
-
- private readonly CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
-
- public CosmosDbFixture()
- {
- this.Container = new TestcontainersBuilder()
- .WithDatabase(this.configuration)
- .Build();
- }
-
- public override Task InitializeAsync()
- {
- return this.Container.StartAsync(this.cts.Token);
- }
-
- public override Task DisposeAsync()
- {
- return this.Container.DisposeAsync().AsTask();
- }
-
- public override void Dispose()
- {
- this.configuration.Dispose();
- }
- }
-}
diff --git a/tests/Testcontainers.Tests/SkipOnLinuxEngineAttribute.cs b/tests/Testcontainers.Tests/SkipOnLinuxEngineAttribute.cs
deleted file mode 100644
index 6a82675a9..000000000
--- a/tests/Testcontainers.Tests/SkipOnLinuxEngineAttribute.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace DotNet.Testcontainers.Tests
-{
- using DotNet.Testcontainers.Commons;
- using Xunit;
-
- public sealed class SkipOnLinuxEngineAttribute : FactAttribute
- {
- private static readonly bool IsLinuxEngineEnabled = DockerCli.PlatformIsEnabled(DockerCli.DockerPlatform.Linux);
-
- public SkipOnLinuxEngineAttribute()
- {
- if (IsLinuxEngineEnabled)
- {
- this.Skip = "Docker Windows engine is not available.";
- }
- }
- }
-}
diff --git a/tests/Testcontainers.Tests/Testcontainers.Tests.csproj b/tests/Testcontainers.Tests/Testcontainers.Tests.csproj
index 0d285dc78..1956c7c3d 100644
--- a/tests/Testcontainers.Tests/Testcontainers.Tests.csproj
+++ b/tests/Testcontainers.Tests/Testcontainers.Tests.csproj
@@ -19,7 +19,6 @@
-
diff --git a/tests/Testcontainers.Tests/Unit/Containers/Unix/Modules/Databases/CosmosDbTestcontainerTest.cs b/tests/Testcontainers.Tests/Unit/Containers/Unix/Modules/Databases/CosmosDbTestcontainerTest.cs
deleted file mode 100644
index 75bdb8028..000000000
--- a/tests/Testcontainers.Tests/Unit/Containers/Unix/Modules/Databases/CosmosDbTestcontainerTest.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-namespace DotNet.Testcontainers.Tests.Unit
-{
- using System;
- using System.Net;
- using System.Net.Http;
- using System.Threading.Tasks;
- using DotNet.Testcontainers.Configurations;
- using DotNet.Testcontainers.Tests.Fixtures;
- using Microsoft.Azure.Cosmos;
- using Xunit;
-
- public static class CosmosDbTestcontainerTest
- {
- public sealed class ConnectionTests : IClassFixture, IDisposable
- {
- private const string SkipReason = "The Cosmos DB Linux Emulator Docker image does not run on every CI environment."; // https://github.com/Azure/azure-cosmos-db-emulator-docker/issues/45.
-
- private readonly HttpClient httpClient;
-
- private readonly CosmosClient cosmosClient;
-
- public ConnectionTests(CosmosDbFixture cosmosDbFixture)
- : this(cosmosDbFixture.Container.HttpClient, cosmosDbFixture.Container.ConnectionString)
- {
- }
-
- private ConnectionTests(HttpClient httpClient, string connectionString)
- {
- var cosmosClientOptions = new CosmosClientOptions();
- cosmosClientOptions.ConnectionMode = ConnectionMode.Gateway;
- cosmosClientOptions.HttpClientFactory = () => httpClient;
-
- this.httpClient = httpClient;
- this.cosmosClient = new CosmosClient(connectionString, cosmosClientOptions);
- }
-
-#pragma warning disable xUnit1004
-
- [Fact(Skip = SkipReason)]
- public async Task ConnectionEstablished()
- {
- var accountProperties = await this.cosmosClient.ReadAccountAsync()
- .ConfigureAwait(false);
-
- Assert.Equal("localhost", accountProperties.Id);
- }
-
- [Fact(Skip = SkipReason)]
- public async Task CreateDatabaseTest()
- {
- var databaseResponse = await this.cosmosClient.CreateDatabaseIfNotExistsAsync("db")
- .ConfigureAwait(false);
-
- Assert.Equal(HttpStatusCode.Created, databaseResponse.StatusCode);
- }
-
- [Fact(Skip = SkipReason)]
- public void CannotSetPassword()
- {
- var cosmosDb = new CosmosDbTestcontainerConfiguration();
- Assert.Throws(() => cosmosDb.Password = string.Empty);
- }
-
-#pragma warning restore xUnit1004
-
- public void Dispose()
- {
- this.cosmosClient.Dispose();
- this.httpClient.Dispose();
- }
- }
- }
-}
diff --git a/tests/Testcontainers.Tests/Unit/Containers/Windows/TestcontainersContainerTest.cs b/tests/Testcontainers.Tests/Unit/Containers/Windows/TestcontainersContainerTest.cs
deleted file mode 100644
index 0d913d73a..000000000
--- a/tests/Testcontainers.Tests/Unit/Containers/Windows/TestcontainersContainerTest.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-namespace DotNet.Testcontainers.Tests.Unit.Containers.Windows
-{
- using System.Threading.Tasks;
- using DotNet.Testcontainers.Builders;
- using DotNet.Testcontainers.Containers;
- using Xunit;
-
- public static class TestcontainersContainerTest
- {
- public sealed class WithConfiguration
- {
- [SkipOnLinuxEngine]
- public async Task UntilCommandIsCompleted()
- {
- // Given
- var testcontainersBuilder = new TestcontainersBuilder()
- .WithImage("mcr.microsoft.com/windows/servercore:ltsc2022")
- .WithEntrypoint("PowerShell", "-NoLogo", "-Command", "ping -t localhost | Out-Null")
- .WithWaitStrategy(Wait.ForWindowsContainer()
- .UntilCommandIsCompleted("Exit !(Test-Path -Path 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe')"));
-
- // When
- // Then
- await using (ITestcontainersContainer testcontainer = testcontainersBuilder.Build())
- {
- await testcontainer.StartAsync();
- Assert.True(true);
- }
- }
-
- [SkipOnLinuxEngine]
- public async Task UntilPortIsAvailable()
- {
- // Given
- var testcontainersBuilder = new TestcontainersBuilder()
- .WithImage("mcr.microsoft.com/windows/servercore:ltsc2022")
- .WithEntrypoint("PowerShell", "-NoLogo", "-Command", "$tcpListener = [System.Net.Sockets.TcpListener]1337; $tcpListener.Start(); ping -t localhost | Out-Null")
- .WithWaitStrategy(Wait.ForWindowsContainer()
- .UntilPortIsAvailable(1337));
-
- // When
- // Then
- await using (ITestcontainersContainer testcontainer = testcontainersBuilder.Build())
- {
- await testcontainer.StartAsync();
- Assert.True(true);
- }
- }
- }
- }
-}