From 45bba8d33b364af6b5f18db2820cd36c61e5ee8e Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Mon, 13 Mar 2023 16:19:53 +0000 Subject: [PATCH 01/13] feat: Introduce new CosmosDb module --- Testcontainers.sln | 14 ++ src/Testcontainers.CosmosDb/.editorconfig | 1 + .../CosmosDbBuilder.cs | 123 ++++++++++++++++++ .../CosmosDbConfiguration.cs | 71 ++++++++++ .../CosmosDbContainer.cs | 64 +++++++++ .../Testcontainers.CosmosDb.csproj | 12 ++ src/Testcontainers.CosmosDb/Usings.cs | 10 ++ .../.editorconfig | 1 + .../CosmosDbContainerTest.cs | 40 ++++++ .../Testcontainers.CosmosDb.Tests.csproj | 18 +++ tests/Testcontainers.CosmosDb.Tests/Usings.cs | 3 + 11 files changed, 357 insertions(+) create mode 100644 src/Testcontainers.CosmosDb/.editorconfig create mode 100644 src/Testcontainers.CosmosDb/CosmosDbBuilder.cs create mode 100644 src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs create mode 100644 src/Testcontainers.CosmosDb/CosmosDbContainer.cs create mode 100644 src/Testcontainers.CosmosDb/Testcontainers.CosmosDb.csproj create mode 100644 src/Testcontainers.CosmosDb/Usings.cs create mode 100644 tests/Testcontainers.CosmosDb.Tests/.editorconfig create mode 100644 tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs create mode 100644 tests/Testcontainers.CosmosDb.Tests/Testcontainers.CosmosDb.Tests.csproj create mode 100644 tests/Testcontainers.CosmosDb.Tests/Usings.cs diff --git a/Testcontainers.sln b/Testcontainers.sln index c94dc9b01..135744a5b 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -109,6 +109,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}" 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.CosmosDb.Tests", "tests\Testcontainers.CosmosDb.Tests\Testcontainers.CosmosDb.Tests.csproj", "{BD445A54-F411-4758-955E-397A1E98680C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -310,6 +314,14 @@ Global {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU + {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 + {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 EndGlobalSection GlobalSection(NestedProjects) = preSolution {58E94721-2681-4D82-8D94-0B2F9DB0D575} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -360,5 +372,7 @@ Global {1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {A724806F-8C94-4438-8011-04A9A1575318} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} + {BD445A54-F411-4758-955E-397A1E98680C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal 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..679b6bf8a --- /dev/null +++ b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs @@ -0,0 +1,123 @@ +using System.Net; + +namespace Testcontainers.CosmosDb; + +/// +[PublicAPI] +public sealed class CosmosDbBuilder : ContainerBuilder +{ + public const string CosmosDbEmulatorImage = "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest"; + + public const ushort CosmosDbPort = 8081; + + public const string DefaultAccountKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="; + + public const int DefaultPartitionCount = 2; + + public const string DefaultIpAddressOverride = "127.0.0.1"; + + /// + /// 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; } + + /// + /// Sets the partition count. + /// + /// The number of partitions. + /// A configured instance of . + public CosmosDbBuilder WithPartitionCount(int partitionCount) + { + return Merge(DockerResourceConfiguration, new CosmosDbConfiguration(partitionCount: partitionCount)) + .WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", partitionCount.ToString()); + } + + /// + /// Sets the overridden IP address. + /// + /// The overridden IP address. + /// A configured instance of . + public CosmosDbBuilder WithIpAddressOverride(string ipAddress) + { + return Merge(DockerResourceConfiguration, new CosmosDbConfiguration(ipAddressOverride: ipAddress)) + .WithEnvironment("AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE", ipAddress); + } + + /// + public override CosmosDbContainer Build() + { + Validate(); + return new CosmosDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); + } + + /// + protected override CosmosDbBuilder Init() + { + return base.Init() + .WithImage(CosmosDbEmulatorImage) + .WithPortBinding(CosmosDbPort, true) + .WithPartitionCount(DefaultPartitionCount) + .WithIpAddressOverride(DefaultIpAddressOverride) + .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Started|Shutting")); + } + + /// + protected override void Validate() + { + base.Validate(); + + if (!DockerResourceConfiguration.PartitionCount.HasValue) + { + throw new ArgumentException($"'{nameof(DockerResourceConfiguration.PartitionCount)}' cannot be null."); + } + + if (DockerResourceConfiguration.PartitionCount.Value < 1) + { + throw new ArgumentException($"'{nameof(DockerResourceConfiguration.PartitionCount)}' cannot be less than 1."); + } + + _ = Guard.Argument(DockerResourceConfiguration.IpAddressOverride, nameof(DockerResourceConfiguration.IpAddressOverride)) + .NotNull() + .NotEmpty(); + + if (!IPAddress.TryParse(DockerResourceConfiguration.IpAddressOverride, out _)) + { + throw new ArgumentException($"'{nameof(DockerResourceConfiguration.IpAddressOverride)}' must be a valid IP address."); + } + } + + /// + 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..eb1c9a6b0 --- /dev/null +++ b/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs @@ -0,0 +1,71 @@ +namespace Testcontainers.CosmosDb; + +/// +[PublicAPI] +public sealed class CosmosDbConfiguration : ContainerConfiguration +{ + /// + /// Initializes a new instance of the class. + /// + /// The number of partitions to create + /// The overridden IP address. + public CosmosDbConfiguration( + int? partitionCount = null, + string ipAddressOverride = null) + { + PartitionCount = partitionCount; + IpAddressOverride = ipAddressOverride; + } + + /// + /// 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) + { + PartitionCount = BuildConfiguration.Combine(oldValue.PartitionCount, newValue.PartitionCount); + IpAddressOverride = BuildConfiguration.Combine(oldValue.IpAddressOverride, newValue.IpAddressOverride); + } + + /// + /// Gets the partition count + /// + public int? PartitionCount { get; } + + /// + /// Gets the overridden IP address + /// + public string IpAddressOverride { get; } +} \ 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..7371d5514 --- /dev/null +++ b/src/Testcontainers.CosmosDb/CosmosDbContainer.cs @@ -0,0 +1,64 @@ +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +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 int _port; + + public UriRewriter(string hostname, int 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..f889bad0a --- /dev/null +++ b/src/Testcontainers.CosmosDb/Usings.cs @@ -0,0 +1,10 @@ +global using System; +global using System.Collections.Generic; +global using System.Linq; +global using Docker.DotNet.Models; +global using DotNet.Testcontainers; +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/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..30882ce53 --- /dev/null +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.Azure.Cosmos; + +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] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task ConnectionStateReturnsOpen() + { + // Given + var options = new CosmosClientOptions + { + ConnectionMode = ConnectionMode.Gateway, + HttpClientFactory = () => _cosmosDbContainer.HttpClient, + RequestTimeout = TimeSpan.FromMinutes(3) + }; + + var client = new CosmosClient(_cosmosDbContainer.GetConnectionString(), options); + + // When + var account = await client.ReadAccountAsync(); + + // Then + Assert.Equal("localhost", account.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..93b6a8dce --- /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..346085388 --- /dev/null +++ b/tests/Testcontainers.CosmosDb.Tests/Usings.cs @@ -0,0 +1,3 @@ +global using System.Threading.Tasks; +global using DotNet.Testcontainers.Commons; +global using Xunit; \ No newline at end of file From 65a8d655a0dc8fac8973a67918f345e80a34271d Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Mon, 13 Mar 2023 16:25:50 +0000 Subject: [PATCH 02/13] chore: Removed obsolete CosmosDb module --- .../Databases/CosmosDbTestcontainer.cs | 63 --------------- .../CosmosDbTestcontainerConfiguration.cs | 78 ------------------- .../Unix/Modules/Databases/CosmosDbFixture.cs | 41 ---------- .../Databases/CosmosDbTestcontainerTest.cs | 73 ----------------- 4 files changed, 255 deletions(-) delete mode 100644 src/Testcontainers/_OBSOLETE_/Modules/Databases/CosmosDbTestcontainer.cs delete mode 100644 src/Testcontainers/_OBSOLETE_/Modules/Databases/CosmosDbTestcontainerConfiguration.cs delete mode 100644 tests/Testcontainers.Tests/Fixtures/Containers/Unix/Modules/Databases/CosmosDbFixture.cs delete mode 100644 tests/Testcontainers.Tests/Unit/Containers/Unix/Modules/Databases/CosmosDbTestcontainerTest.cs 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.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/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(); - } - } - } -} From 2148b798bb09987307042441da060265dc785757 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:41:17 +0100 Subject: [PATCH 03/13] chore: Clean usings, whitespaces --- Testcontainers.sln | 28 +++++++++---------- .../CosmosDbBuilder.cs | 16 +++++------ .../CosmosDbConfiguration.cs | 2 +- .../CosmosDbContainer.cs | 11 +++----- src/Testcontainers.CosmosDb/Usings.cs | 4 +++ .../CosmosDbContainerTest.cs | 27 ++++++++---------- .../Testcontainers.CosmosDb.Tests.csproj | 14 +++++----- tests/Testcontainers.CosmosDb.Tests/Usings.cs | 2 ++ 8 files changed, 51 insertions(+), 53 deletions(-) diff --git a/Testcontainers.sln b/Testcontainers.sln index 135744a5b..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}" @@ -109,10 +113,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}" 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.CosmosDb.Tests", "tests\Testcontainers.CosmosDb.Tests\Testcontainers.CosmosDb.Tests.csproj", "{BD445A54-F411-4758-955E-397A1E98680C}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -122,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 @@ -214,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 @@ -314,16 +322,9 @@ Global {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU - {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 - {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 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} @@ -347,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} @@ -372,7 +374,5 @@ Global {1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} - {A724806F-8C94-4438-8011-04A9A1575318} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} - {BD445A54-F411-4758-955E-397A1E98680C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal diff --git a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs index 679b6bf8a..7d6031705 100644 --- a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs +++ b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs @@ -1,19 +1,17 @@ -using System.Net; - namespace Testcontainers.CosmosDb; /// [PublicAPI] public sealed class CosmosDbBuilder : ContainerBuilder { - public const string CosmosDbEmulatorImage = "mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest"; - + 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=="; - + public const int DefaultPartitionCount = 2; - + public const string DefaultIpAddressOverride = "127.0.0.1"; /// @@ -71,7 +69,7 @@ public override CosmosDbContainer Build() protected override CosmosDbBuilder Init() { return base.Init() - .WithImage(CosmosDbEmulatorImage) + .WithImage(CosmosDbImage) .WithPortBinding(CosmosDbPort, true) .WithPartitionCount(DefaultPartitionCount) .WithIpAddressOverride(DefaultIpAddressOverride) @@ -92,7 +90,7 @@ protected override void Validate() { throw new ArgumentException($"'{nameof(DockerResourceConfiguration.PartitionCount)}' cannot be less than 1."); } - + _ = Guard.Argument(DockerResourceConfiguration.IpAddressOverride, nameof(DockerResourceConfiguration.IpAddressOverride)) .NotNull() .NotEmpty(); diff --git a/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs b/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs index eb1c9a6b0..f88b482e2 100644 --- a/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs +++ b/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs @@ -65,7 +65,7 @@ public CosmosDbConfiguration(CosmosDbConfiguration oldValue, CosmosDbConfigurati public int? PartitionCount { get; } /// - /// Gets the overridden IP address + /// Gets the overridden IP address /// public string IpAddressOverride { get; } } \ No newline at end of file diff --git a/src/Testcontainers.CosmosDb/CosmosDbContainer.cs b/src/Testcontainers.CosmosDb/CosmosDbContainer.cs index 7371d5514..15e4c2243 100644 --- a/src/Testcontainers.CosmosDb/CosmosDbContainer.cs +++ b/src/Testcontainers.CosmosDb/CosmosDbContainer.cs @@ -1,7 +1,3 @@ -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - namespace Testcontainers.CosmosDb; /// @@ -32,7 +28,7 @@ public string GetConnectionString() 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. /// @@ -46,9 +42,10 @@ public string GetConnectionString() private sealed class UriRewriter : DelegatingHandler { private readonly string _hostname; - private readonly int _port; - public UriRewriter(string hostname, int port) + private readonly ushort _port; + + public UriRewriter(string hostname, ushort port) : base(new HttpClientHandler { ServerCertificateCustomValidationCallback = (_, _, _, _) => true }) { _hostname = hostname; diff --git a/src/Testcontainers.CosmosDb/Usings.cs b/src/Testcontainers.CosmosDb/Usings.cs index f889bad0a..82e1408e4 100644 --- a/src/Testcontainers.CosmosDb/Usings.cs +++ b/src/Testcontainers.CosmosDb/Usings.cs @@ -1,6 +1,10 @@ global using System; global using System.Collections.Generic; global using System.Linq; +global using System.Net; +global using System.Net.Http; +global using System.Threading; +global using System.Threading.Tasks; global using Docker.DotNet.Models; global using DotNet.Testcontainers; global using DotNet.Testcontainers.Builders; diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs index 30882ce53..e0714dd95 100644 --- a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -1,6 +1,3 @@ -using System; -using Microsoft.Azure.Cosmos; - namespace Testcontainers.CosmosDb; public sealed class CosmosDbContainerTest : IAsyncLifetime @@ -22,19 +19,19 @@ public Task DisposeAsync() public async Task ConnectionStateReturnsOpen() { // Given - var options = new CosmosClientOptions - { - ConnectionMode = ConnectionMode.Gateway, - HttpClientFactory = () => _cosmosDbContainer.HttpClient, - RequestTimeout = TimeSpan.FromMinutes(3) - }; - - var client = new CosmosClient(_cosmosDbContainer.GetConnectionString(), options); - + 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 account = await client.ReadAccountAsync(); - + var accountProperties = await cosmosClient.ReadAccountAsync() + .ConfigureAwait(false); + // Then - Assert.Equal("localhost", account.Id); + 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 index 93b6a8dce..914558fa3 100644 --- a/tests/Testcontainers.CosmosDb.Tests/Testcontainers.CosmosDb.Tests.csproj +++ b/tests/Testcontainers.CosmosDb.Tests/Testcontainers.CosmosDb.Tests.csproj @@ -5,14 +5,14 @@ false - - - - - + + + + + - - + + \ No newline at end of file diff --git a/tests/Testcontainers.CosmosDb.Tests/Usings.cs b/tests/Testcontainers.CosmosDb.Tests/Usings.cs index 346085388..e0463d5ee 100644 --- a/tests/Testcontainers.CosmosDb.Tests/Usings.cs +++ b/tests/Testcontainers.CosmosDb.Tests/Usings.cs @@ -1,3 +1,5 @@ +global using System; global using System.Threading.Tasks; global using DotNet.Testcontainers.Commons; +global using Microsoft.Azure.Cosmos; global using Xunit; \ No newline at end of file From d2ee73b77547cc1ca64a55f0f99ec7e0f972c706 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Tue, 14 Mar 2023 14:51:14 +0000 Subject: [PATCH 04/13] chore: Remove unnecessary properties --- .../CosmosDbBuilder.cs | 53 ------------------- .../CosmosDbConfiguration.cs | 20 +------ .../CosmosDbContainerTest.cs | 4 +- 3 files changed, 4 insertions(+), 73 deletions(-) diff --git a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs index 7d6031705..ea8ca5b76 100644 --- a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs +++ b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs @@ -10,10 +10,6 @@ public sealed class CosmosDbBuilder : ContainerBuilder /// Initializes a new instance of the class. /// @@ -36,28 +32,6 @@ private CosmosDbBuilder(CosmosDbConfiguration resourceConfiguration) /// protected override CosmosDbConfiguration DockerResourceConfiguration { get; } - /// - /// Sets the partition count. - /// - /// The number of partitions. - /// A configured instance of . - public CosmosDbBuilder WithPartitionCount(int partitionCount) - { - return Merge(DockerResourceConfiguration, new CosmosDbConfiguration(partitionCount: partitionCount)) - .WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", partitionCount.ToString()); - } - - /// - /// Sets the overridden IP address. - /// - /// The overridden IP address. - /// A configured instance of . - public CosmosDbBuilder WithIpAddressOverride(string ipAddress) - { - return Merge(DockerResourceConfiguration, new CosmosDbConfiguration(ipAddressOverride: ipAddress)) - .WithEnvironment("AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE", ipAddress); - } - /// public override CosmosDbContainer Build() { @@ -71,36 +45,9 @@ protected override CosmosDbBuilder Init() return base.Init() .WithImage(CosmosDbImage) .WithPortBinding(CosmosDbPort, true) - .WithPartitionCount(DefaultPartitionCount) - .WithIpAddressOverride(DefaultIpAddressOverride) .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Started|Shutting")); } - /// - protected override void Validate() - { - base.Validate(); - - if (!DockerResourceConfiguration.PartitionCount.HasValue) - { - throw new ArgumentException($"'{nameof(DockerResourceConfiguration.PartitionCount)}' cannot be null."); - } - - if (DockerResourceConfiguration.PartitionCount.Value < 1) - { - throw new ArgumentException($"'{nameof(DockerResourceConfiguration.PartitionCount)}' cannot be less than 1."); - } - - _ = Guard.Argument(DockerResourceConfiguration.IpAddressOverride, nameof(DockerResourceConfiguration.IpAddressOverride)) - .NotNull() - .NotEmpty(); - - if (!IPAddress.TryParse(DockerResourceConfiguration.IpAddressOverride, out _)) - { - throw new ArgumentException($"'{nameof(DockerResourceConfiguration.IpAddressOverride)}' must be a valid IP address."); - } - } - /// protected override CosmosDbBuilder Clone(IResourceConfiguration resourceConfiguration) { diff --git a/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs b/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs index f88b482e2..c623b6aef 100644 --- a/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs +++ b/src/Testcontainers.CosmosDb/CosmosDbConfiguration.cs @@ -7,14 +7,8 @@ public sealed class CosmosDbConfiguration : ContainerConfiguration /// /// Initializes a new instance of the class. /// - /// The number of partitions to create - /// The overridden IP address. - public CosmosDbConfiguration( - int? partitionCount = null, - string ipAddressOverride = null) + public CosmosDbConfiguration() { - PartitionCount = partitionCount; - IpAddressOverride = ipAddressOverride; } /// @@ -55,17 +49,5 @@ public CosmosDbConfiguration(CosmosDbConfiguration resourceConfiguration) public CosmosDbConfiguration(CosmosDbConfiguration oldValue, CosmosDbConfiguration newValue) : base(oldValue, newValue) { - PartitionCount = BuildConfiguration.Combine(oldValue.PartitionCount, newValue.PartitionCount); - IpAddressOverride = BuildConfiguration.Combine(oldValue.IpAddressOverride, newValue.IpAddressOverride); } - - /// - /// Gets the partition count - /// - public int? PartitionCount { get; } - - /// - /// Gets the overridden IP address - /// - public string IpAddressOverride { get; } } \ No newline at end of file diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs index e0714dd95..10d48c46c 100644 --- a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -2,7 +2,9 @@ namespace Testcontainers.CosmosDb; public sealed class CosmosDbContainerTest : IAsyncLifetime { - private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder().Build(); + private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder() + .WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", "2") + .Build(); public Task InitializeAsync() { From 4c27365d786231d03d0b6d01393f6f6c3d27f1d8 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Thu, 16 Mar 2023 18:53:22 +0100 Subject: [PATCH 05/13] debug: Add CosmosDB log messages --- build.cake | 2 +- .../Containers/DockerContainer.cs | 7 +++++++ .../CosmosDbContainerTest.cs | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 2d81d1fb0..2dd7975ab 100644 --- a/build.cake +++ b/build.cake @@ -73,7 +73,7 @@ Task("Build") Task("Tests") .Does(() => { - DotNetTest(param.Solution, new DotNetTestSettings + DotNetTest("tests/Testcontainers.CosmosDb.Tests/Testcontainers.CosmosDb.Tests.csproj", new DotNetTestSettings { Configuration = param.Configuration, Verbosity = param.Verbosity, diff --git a/src/Testcontainers/Containers/DockerContainer.cs b/src/Testcontainers/Containers/DockerContainer.cs index e125ad538..c65db4132 100644 --- a/src/Testcontainers/Containers/DockerContainer.cs +++ b/src/Testcontainers/Containers/DockerContainer.cs @@ -227,6 +227,13 @@ public ushort GetMappedPublicPort(string containerPort) { this.ThrowIfResourceNotFound(); + this.Logger.LogInformation(this.container.NetworkSettings.Ports.Count.ToString()); + + foreach (var port in this.container.NetworkSettings.Ports) + { + this.Logger.LogInformation(port.Value?.FirstOrDefault()?.HostPort); + } + if (this.container.NetworkSettings.Ports.TryGetValue($"{containerPort}/tcp", out var portBindings) && ushort.TryParse(portBindings.First().HostPort, out var publicPort)) { return publicPort; diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs index 10d48c46c..c1919bb49 100644 --- a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -1,3 +1,6 @@ +using DotNet.Testcontainers.Configurations; +using Microsoft.Extensions.Logging; + namespace Testcontainers.CosmosDb; public sealed class CosmosDbContainerTest : IAsyncLifetime @@ -20,6 +23,20 @@ public Task DisposeAsync() [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] public async Task ConnectionStateReturnsOpen() { + var (stdout, stderr) = await _cosmosDbContainer.GetLogs() + .ConfigureAwait(false); + + var exitCode = await _cosmosDbContainer.GetExitCode() + .ConfigureAwait(false); + + var state = _cosmosDbContainer.State; + + var logger = TestcontainersSettings.Logger; + logger.LogInformation(state.ToString()); + logger.LogInformation(exitCode.ToString()); + logger.LogInformation(stdout); + logger.LogInformation(stderr); + // Given using var httpClient = _cosmosDbContainer.HttpClient; From cffe3e1a453133782fee31ef10fc5dd2b756a297 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Sun, 19 Mar 2023 18:41:15 +0100 Subject: [PATCH 06/13] chore: Remove Cosmos DB logs --- build.cake | 2 +- .../Containers/DockerContainer.cs | 7 ------ .../CosmosDbContainerTest.cs | 25 +++---------------- 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/build.cake b/build.cake index 2dd7975ab..2d81d1fb0 100644 --- a/build.cake +++ b/build.cake @@ -73,7 +73,7 @@ Task("Build") Task("Tests") .Does(() => { - DotNetTest("tests/Testcontainers.CosmosDb.Tests/Testcontainers.CosmosDb.Tests.csproj", new DotNetTestSettings + DotNetTest(param.Solution, new DotNetTestSettings { Configuration = param.Configuration, Verbosity = param.Verbosity, diff --git a/src/Testcontainers/Containers/DockerContainer.cs b/src/Testcontainers/Containers/DockerContainer.cs index c65db4132..e125ad538 100644 --- a/src/Testcontainers/Containers/DockerContainer.cs +++ b/src/Testcontainers/Containers/DockerContainer.cs @@ -227,13 +227,6 @@ public ushort GetMappedPublicPort(string containerPort) { this.ThrowIfResourceNotFound(); - this.Logger.LogInformation(this.container.NetworkSettings.Ports.Count.ToString()); - - foreach (var port in this.container.NetworkSettings.Ports) - { - this.Logger.LogInformation(port.Value?.FirstOrDefault()?.HostPort); - } - if (this.container.NetworkSettings.Ports.TryGetValue($"{containerPort}/tcp", out var portBindings) && ushort.TryParse(portBindings.First().HostPort, out var publicPort)) { return publicPort; diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs index c1919bb49..82eea8a73 100644 --- a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -1,13 +1,8 @@ -using DotNet.Testcontainers.Configurations; -using Microsoft.Extensions.Logging; - namespace Testcontainers.CosmosDb; public sealed class CosmosDbContainerTest : IAsyncLifetime { - private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder() - .WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", "2") - .Build(); + private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder().Build(); public Task InitializeAsync() { @@ -19,24 +14,10 @@ public Task DisposeAsync() return _cosmosDbContainer.DisposeAsync().AsTask(); } - [Fact] + [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. [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] - public async Task ConnectionStateReturnsOpen() + public async Task ReadAccountIdReturnsLocalhost() { - var (stdout, stderr) = await _cosmosDbContainer.GetLogs() - .ConfigureAwait(false); - - var exitCode = await _cosmosDbContainer.GetExitCode() - .ConfigureAwait(false); - - var state = _cosmosDbContainer.State; - - var logger = TestcontainersSettings.Logger; - logger.LogInformation(state.ToString()); - logger.LogInformation(exitCode.ToString()); - logger.LogInformation(stdout); - logger.LogInformation(stderr); - // Given using var httpClient = _cosmosDbContainer.HttpClient; From 84ab8fb75ce0ca4f9a3e6aafc908264a8807589c Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 20 Mar 2023 14:03:13 +0100 Subject: [PATCH 07/13] chore: Prepare running CosmosDB tests on Windows runner --- Packages.props | 1 - tests/Testcontainers.Commons/.editorconfig | 1 + .../Testcontainers.Commons/CommonCommands.cs | 13 +- .../CommonCredentials.cs | 13 +- tests/Testcontainers.Commons/CommonImages.cs | 16 +- tests/Testcontainers.Commons/DockerCli.cs | 196 +++++++++--------- .../SkipOnLinuxEngineAttribute.cs | 15 ++ tests/Testcontainers.Commons/TestSession.cs | 17 +- .../Testcontainers.Commons.csproj | 33 ++- tests/Testcontainers.Commons/Usings.cs | 7 + .../CosmosDbContainerTest.cs | 4 +- .../.editorconfig | 1 + ...Testcontainers.Platform.Linux.Tests.csproj | 32 ++- .../.editorconfig | 1 + ...stcontainers.Platform.Windows.Tests.csproj | 32 ++- .../Usings.cs | 6 + .../WindowsContainerTest.cs | 56 +++++ .../SkipOnLinuxEngineAttribute.cs | 18 -- .../Testcontainers.Tests.csproj | 1 - .../Windows/TestcontainersContainerTest.cs | 51 ----- 20 files changed, 252 insertions(+), 262 deletions(-) create mode 100644 tests/Testcontainers.Commons/.editorconfig create mode 100644 tests/Testcontainers.Commons/SkipOnLinuxEngineAttribute.cs create mode 100644 tests/Testcontainers.Commons/Usings.cs create mode 100644 tests/Testcontainers.Platform.Linux.Tests/.editorconfig create mode 100644 tests/Testcontainers.Platform.Windows.Tests/.editorconfig create mode 100644 tests/Testcontainers.Platform.Windows.Tests/Usings.cs create mode 100644 tests/Testcontainers.Platform.Windows.Tests/WindowsContainerTest.cs delete mode 100644 tests/Testcontainers.Tests/SkipOnLinuxEngineAttribute.cs delete mode 100644 tests/Testcontainers.Tests/Unit/Containers/Windows/TestcontainersContainerTest.cs 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/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..811c6c203 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:ltsc2019"); +} \ 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/SkipOnLinuxEngineAttribute.cs b/tests/Testcontainers.Commons/SkipOnLinuxEngineAttribute.cs new file mode 100644 index 000000000..6f77484c1 --- /dev/null +++ b/tests/Testcontainers.Commons/SkipOnLinuxEngineAttribute.cs @@ -0,0 +1,15 @@ +namespace DotNet.Testcontainers.Commons; + +[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.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..0b832aaeb 100644 --- a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj +++ b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj @@ -1,19 +1,16 @@ - - - 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..2d5271806 --- /dev/null +++ b/tests/Testcontainers.Commons/Usings.cs @@ -0,0 +1,7 @@ +global using System; +global using System.Diagnostics; +global using System.IO; +global using System.Text; +global using DotNet.Testcontainers.Images; +global using JetBrains.Annotations; +global using Xunit; \ No newline at end of file diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs index 82eea8a73..90794884c 100644 --- a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -14,8 +14,8 @@ 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. - [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + [SkipOnLinuxEngine] // https://github.com/Azure/azure-cosmos-db-emulator-docker/issues/45. + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Windows))] public async Task ReadAccountIdReturnsLocalhost() { // Given 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/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/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/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); - } - } - } - } -} From 9933169df2d659fdc8dc50771684deea39d3051f Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 20 Mar 2023 14:46:20 +0100 Subject: [PATCH 08/13] chore: Add test filter DockerPlatform=Windows --- .github/workflows/cicd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 9674ac11061056549043e71db276e6287c2add97 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:00:41 +0100 Subject: [PATCH 09/13] chore: Use right Windows image version --- src/Testcontainers.CosmosDb/Usings.cs | 2 -- src/Testcontainers.MongoDb/MongoDbContainer.cs | 13 +------------ src/Testcontainers.WebDriver/Usings.cs | 3 --- src/Testcontainers.WebDriver/WebDriverBrowser.cs | 6 +++--- tests/Testcontainers.Commons/CommonImages.cs | 2 +- tests/Testcontainers.CosmosDb.Tests/Usings.cs | 1 - 6 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/Testcontainers.CosmosDb/Usings.cs b/src/Testcontainers.CosmosDb/Usings.cs index 82e1408e4..fad310b40 100644 --- a/src/Testcontainers.CosmosDb/Usings.cs +++ b/src/Testcontainers.CosmosDb/Usings.cs @@ -1,12 +1,10 @@ global using System; global using System.Collections.Generic; global using System.Linq; -global using System.Net; global using System.Net.Http; global using System.Threading; global using System.Threading.Tasks; global using Docker.DotNet.Models; -global using DotNet.Testcontainers; global using DotNet.Testcontainers.Builders; global using DotNet.Testcontainers.Configurations; global using DotNet.Testcontainers.Containers; 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/tests/Testcontainers.Commons/CommonImages.cs b/tests/Testcontainers.Commons/CommonImages.cs index 811c6c203..eb6de433a 100644 --- a/tests/Testcontainers.Commons/CommonImages.cs +++ b/tests/Testcontainers.Commons/CommonImages.cs @@ -9,5 +9,5 @@ public static class CommonImages public static readonly IImage Nginx = new DockerImage("nginx:1.22"); - public static readonly IImage ServerCore = new DockerImage("mcr.microsoft.com/windows/servercore:ltsc2019"); + public static readonly IImage ServerCore = new DockerImage("mcr.microsoft.com/windows/servercore:ltsc2022"); } \ No newline at end of file diff --git a/tests/Testcontainers.CosmosDb.Tests/Usings.cs b/tests/Testcontainers.CosmosDb.Tests/Usings.cs index e0463d5ee..3f12d7755 100644 --- a/tests/Testcontainers.CosmosDb.Tests/Usings.cs +++ b/tests/Testcontainers.CosmosDb.Tests/Usings.cs @@ -1,4 +1,3 @@ -global using System; global using System.Threading.Tasks; global using DotNet.Testcontainers.Commons; global using Microsoft.Azure.Cosmos; From 40d18a5d9bafd4af4c9491ac70eb37798f365d4a Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:56:26 +0100 Subject: [PATCH 10/13] chore: Use Windows image --- tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs index 90794884c..08f9ba9c1 100644 --- a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -2,7 +2,9 @@ namespace Testcontainers.CosmosDb; public sealed class CosmosDbContainerTest : IAsyncLifetime { - private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder().Build(); + private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder() + .WithImage("mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator:latest") + .Build(); public Task InitializeAsync() { From 0b73410a55e405e288cda8a3c5f550420b05a706 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 20 Mar 2023 16:21:08 +0100 Subject: [PATCH 11/13] chore: Skip CosmosDB test --- .../Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs index 08f9ba9c1..6f16b1e8c 100644 --- a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -2,9 +2,7 @@ namespace Testcontainers.CosmosDb; public sealed class CosmosDbContainerTest : IAsyncLifetime { - private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder() - .WithImage("mcr.microsoft.com/cosmosdb/windows/azure-cosmos-emulator:latest") - .Build(); + private readonly CosmosDbContainer _cosmosDbContainer = new CosmosDbBuilder().Build(); public Task InitializeAsync() { @@ -16,8 +14,7 @@ public Task DisposeAsync() return _cosmosDbContainer.DisposeAsync().AsTask(); } - [SkipOnLinuxEngine] // https://github.com/Azure/azure-cosmos-db-emulator-docker/issues/45. - [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Windows))] + [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 ReadAccountIdReturnsLocalhost() { // Given From edf4ee0b0c215263affa876d19711e9dc47f27a8 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 20 Mar 2023 17:09:16 +0100 Subject: [PATCH 12/13] chore: Move SkipOnLinuxEngineAttribute to Windows platform tests --- src/Testcontainers.CosmosDb/CosmosDbBuilder.cs | 2 +- tests/Testcontainers.Commons/Testcontainers.Commons.csproj | 3 +-- tests/Testcontainers.Commons/Usings.cs | 3 +-- tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs | 2 +- .../SkipOnLinuxEngineAttribute.cs | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) rename tests/{Testcontainers.Commons => Testcontainers.Platform.Windows.Tests}/SkipOnLinuxEngineAttribute.cs (87%) diff --git a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs index ea8ca5b76..1b5838fd2 100644 --- a/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs +++ b/src/Testcontainers.CosmosDb/CosmosDbBuilder.cs @@ -45,7 +45,7 @@ protected override CosmosDbBuilder Init() return base.Init() .WithImage(CosmosDbImage) .WithPortBinding(CosmosDbPort, true) - .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Started|Shutting")); + .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Started")); } /// diff --git a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj index 0b832aaeb..254eef232 100644 --- a/tests/Testcontainers.Commons/Testcontainers.Commons.csproj +++ b/tests/Testcontainers.Commons/Testcontainers.Commons.csproj @@ -8,9 +8,8 @@ - - + \ No newline at end of file diff --git a/tests/Testcontainers.Commons/Usings.cs b/tests/Testcontainers.Commons/Usings.cs index 2d5271806..904e633f5 100644 --- a/tests/Testcontainers.Commons/Usings.cs +++ b/tests/Testcontainers.Commons/Usings.cs @@ -3,5 +3,4 @@ global using System.IO; global using System.Text; global using DotNet.Testcontainers.Images; -global using JetBrains.Annotations; -global using Xunit; \ No newline at end of file +global using JetBrains.Annotations; \ No newline at end of file diff --git a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs index 6f16b1e8c..f5dcf9441 100644 --- a/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs +++ b/tests/Testcontainers.CosmosDb.Tests/CosmosDbContainerTest.cs @@ -15,7 +15,7 @@ public Task DisposeAsync() } [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 ReadAccountIdReturnsLocalhost() + public async Task AccountPropertiesIdReturnsLocalhost() { // Given using var httpClient = _cosmosDbContainer.HttpClient; diff --git a/tests/Testcontainers.Commons/SkipOnLinuxEngineAttribute.cs b/tests/Testcontainers.Platform.Windows.Tests/SkipOnLinuxEngineAttribute.cs similarity index 87% rename from tests/Testcontainers.Commons/SkipOnLinuxEngineAttribute.cs rename to tests/Testcontainers.Platform.Windows.Tests/SkipOnLinuxEngineAttribute.cs index 6f77484c1..93cdd8888 100644 --- a/tests/Testcontainers.Commons/SkipOnLinuxEngineAttribute.cs +++ b/tests/Testcontainers.Platform.Windows.Tests/SkipOnLinuxEngineAttribute.cs @@ -1,4 +1,4 @@ -namespace DotNet.Testcontainers.Commons; +namespace Testcontainers.Platform.Windows.Tests; [PublicAPI] public sealed class SkipOnLinuxEngineAttribute : FactAttribute From 08ef6d5182641a76f3ed265a6555a5df01d49a70 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Mon, 20 Mar 2023 17:53:03 +0100 Subject: [PATCH 13/13] chore: Replace ! with PS -Not operator --- .../WaitStrategies/UntilWindowsPortIsAvailable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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))") { } }