diff --git a/src/Testcontainers.DynamoDb/DynamoDbBuilder.cs b/src/Testcontainers.DynamoDb/DynamoDbBuilder.cs index f0297c252..c5e2e5267 100644 --- a/src/Testcontainers.DynamoDb/DynamoDbBuilder.cs +++ b/src/Testcontainers.DynamoDb/DynamoDbBuilder.cs @@ -30,7 +30,6 @@ private DynamoDbBuilder(DynamoDbConfiguration dockerResourceConfiguration) /// protected override DynamoDbConfiguration DockerResourceConfiguration { get; } - /// public override DynamoDbContainer Build() { @@ -44,11 +43,8 @@ protected override DynamoDbBuilder Init() return base.Init() .WithImage(DynamoDbImage) .WithPortBinding(DynamoDbPort, true) - .WithWaitStrategy(Wait.ForUnixContainer() - .UntilHttpRequestIsSucceeded(request: req => - req.ForPath("/") - .ForStatusCode(HttpStatusCode.BadRequest) - .ForPort(DynamoDbPort))); + .WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => + request.ForPath("/").ForPort(DynamoDbPort).ForStatusCode(HttpStatusCode.BadRequest))); } /// diff --git a/src/Testcontainers.DynamoDb/DynamoDbContainer.cs b/src/Testcontainers.DynamoDb/DynamoDbContainer.cs index fefeec03e..1bec94cdd 100644 --- a/src/Testcontainers.DynamoDb/DynamoDbContainer.cs +++ b/src/Testcontainers.DynamoDb/DynamoDbContainer.cs @@ -13,11 +13,11 @@ public DynamoDbContainer(DynamoDbConfiguration configuration, ILogger logger) : base(configuration, logger) { } - + /// - /// Gets the DynamoDB endpoint. + /// Gets the DynamoDb endpoint. /// - /// The DynamoDB endpoint. + /// The DynamoDb endpoint. public string GetEndpoint() { return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(DynamoDbBuilder.DynamoDbPort)).ToString(); diff --git a/src/Testcontainers.DynamoDb/Testcontainers.DynamoDb.csproj b/src/Testcontainers.DynamoDb/Testcontainers.DynamoDb.csproj index 3c65943dd..37a1be0f7 100644 --- a/src/Testcontainers.DynamoDb/Testcontainers.DynamoDb.csproj +++ b/src/Testcontainers.DynamoDb/Testcontainers.DynamoDb.csproj @@ -1,12 +1,12 @@ - - netstandard2.0;netstandard2.1 - latest - - - - - - - - + + netstandard2.0;netstandard2.1 + latest + + + + + + + + \ No newline at end of file diff --git a/src/Testcontainers.DynamoDb/Usings.cs b/src/Testcontainers.DynamoDb/Usings.cs index a6c15d240..49507dd3e 100644 --- a/src/Testcontainers.DynamoDb/Usings.cs +++ b/src/Testcontainers.DynamoDb/Usings.cs @@ -1,11 +1,8 @@ global using System; +global using System.Net; 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; -global using System.Threading.Tasks; -global using System.Collections.Generic; -global using System.Net; \ No newline at end of file +global using Microsoft.Extensions.Logging; \ No newline at end of file diff --git a/src/Testcontainers.Minio/MinioBuilder.cs b/src/Testcontainers.Minio/MinioBuilder.cs index bacc1a695..7fda230a1 100644 --- a/src/Testcontainers.Minio/MinioBuilder.cs +++ b/src/Testcontainers.Minio/MinioBuilder.cs @@ -68,7 +68,8 @@ protected override MinioBuilder Init() .WithCommand("server", "/data") .WithUsername("minio") .WithPassword(Guid.NewGuid().ToString("D")) - .WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => request.ForPath("/minio/health/ready").ForPort(MinioPort))); + .WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => + request.ForPath("/minio/health/ready").ForPort(MinioPort))); } /// diff --git a/tests/Testcontainers.DynamoDb.Tests/.editorconfig b/tests/Testcontainers.DynamoDb.Tests/.editorconfig new file mode 100644 index 000000000..6f066619d --- /dev/null +++ b/tests/Testcontainers.DynamoDb.Tests/.editorconfig @@ -0,0 +1 @@ +root = true \ No newline at end of file diff --git a/tests/Testcontainers.DynamoDb.Tests/DynamoDbContainerTest.cs b/tests/Testcontainers.DynamoDb.Tests/DynamoDbContainerTest.cs new file mode 100644 index 000000000..d8c43d12c --- /dev/null +++ b/tests/Testcontainers.DynamoDb.Tests/DynamoDbContainerTest.cs @@ -0,0 +1,82 @@ +namespace Testcontainers.DynamoDb; + +public sealed class DynamoDbContainerTest : IAsyncLifetime +{ + private readonly DynamoDbContainer _dynamoDbContainer = new DynamoDbBuilder().Build(); + + static DynamoDbContainerTest() + { + Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", "AKIAIOSFODNN7EXAMPLE"); + Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"); + } + + public Task InitializeAsync() + { + return _dynamoDbContainer.StartAsync(); + } + + public Task DisposeAsync() + { + return _dynamoDbContainer.DisposeAsync().AsTask(); + } + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task ListBucketsReturnsHttpStatusCodeOk() + { + // Given + var config = new AmazonDynamoDBConfig(); + config.ServiceURL = _dynamoDbContainer.GetEndpoint(); + + var client = new AmazonDynamoDBClient(config); + + // When + var tables = await client.ListTablesAsync() + .ConfigureAwait(false); + + // Then + Assert.Equal(HttpStatusCode.OK, tables.HttpStatusCode); + } + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task GetItemReturnsPutItem() + { + // Given + var id = Guid.NewGuid().ToString("D"); + + var tableName = Guid.NewGuid().ToString("D"); + + var config = new AmazonDynamoDBConfig(); + config.ServiceURL = _dynamoDbContainer.GetEndpoint(); + + var client = new AmazonDynamoDBClient(config); + + var tableRequest = new CreateTableRequest(); + tableRequest.TableName = tableName; + tableRequest.AttributeDefinitions = new List { new AttributeDefinition("Id", ScalarAttributeType.S) }; + tableRequest.KeySchema = new List { new KeySchemaElement("Id", KeyType.HASH) }; + tableRequest.ProvisionedThroughput = new ProvisionedThroughput(10, 5); + + var putItemRequest = new PutItemRequest(); + putItemRequest.TableName = tableName; + putItemRequest.Item = new Dictionary { { "Id", new AttributeValue { S = id } } }; + + var getItemRequest = new GetItemRequest(); + getItemRequest.TableName = tableName; + getItemRequest.Key = new Dictionary { { "Id", new AttributeValue { S = id } } }; + + // When + _ = await client.CreateTableAsync(tableRequest) + .ConfigureAwait(false); + + _ = await client.PutItemAsync(putItemRequest) + .ConfigureAwait(false); + + var itemResponse = await client.GetItemAsync(getItemRequest) + .ConfigureAwait(false); + + // Then + Assert.Equal(id, itemResponse.Item.Values.Single().S); + } +} \ No newline at end of file diff --git a/tests/Testcontainers.DynamoDb.Tests/DynamoDbContainerTests.cs b/tests/Testcontainers.DynamoDb.Tests/DynamoDbContainerTests.cs deleted file mode 100644 index e3e292634..000000000 --- a/tests/Testcontainers.DynamoDb.Tests/DynamoDbContainerTests.cs +++ /dev/null @@ -1,81 +0,0 @@ -namespace Testcontainers.DynamoDb; - -public sealed class DynamoDbContainerTest : IAsyncLifetime -{ - private readonly DynamoDbContainer dynamoDbContainer = new DynamoDbBuilder().Build(); - - public Task InitializeAsync() - { - return this.dynamoDbContainer.StartAsync(); - } - - public Task DisposeAsync() - { - return this.dynamoDbContainer.DisposeAsync().AsTask(); - } - - [Fact] - [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] - public async Task CreateTableReturnsCorrectTableDescription() - { - // Given - const string tableName = "TestDynamoDbTable"; - var clientConfig = new AmazonDynamoDBConfig(); - clientConfig.ServiceURL = this.dynamoDbContainer.GetEndpoint(); - clientConfig.UseHttp = true; - using var client = new AmazonDynamoDBClient(new BasicAWSCredentials("dummy", "dummy"), clientConfig); - - // When - _ = await client.CreateTableAsync(new CreateTableRequest() - { - TableName = tableName, - AttributeDefinitions = new List() { new AttributeDefinition("Id", ScalarAttributeType.S), new AttributeDefinition("Name", ScalarAttributeType.S), }, - KeySchema = new List() { new KeySchemaElement("Id", KeyType.HASH), new KeySchemaElement("Name", KeyType.RANGE), }, - ProvisionedThroughput = new ProvisionedThroughput(1, 1), - TableClass = TableClass.STANDARD, - }) - .ConfigureAwait(false); - - var tableDescription = await client.DescribeTableAsync(tableName).ConfigureAwait(false); - - // Then - Assert.NotNull(tableDescription); - Assert.Equal(HttpStatusCode.OK, tableDescription.HttpStatusCode); - Assert.Equal(tableName, tableDescription.Table.TableName); - Assert.Equal("Id", tableDescription.Table.KeySchema[0].AttributeName); - } - - [Fact] - [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] - public async Task InsertElementToTableReturnsHttpStatusCodeOk() - { - // Given - var tableName = $"TestDynamoDbTable-{Guid.NewGuid():D}"; - var itemId = Guid.NewGuid().ToString("D"); - var itemName = Guid.NewGuid().ToString("D"); - - var clientConfig = new AmazonDynamoDBConfig(); - clientConfig.ServiceURL = this.dynamoDbContainer.GetEndpoint(); - clientConfig.UseHttp = true; - using var client = new AmazonDynamoDBClient(new BasicAWSCredentials("dummy", "dummy"), clientConfig); - - // When - _ = await client.CreateTableAsync(new CreateTableRequest() - { - TableName = tableName, - AttributeDefinitions = new List() { new AttributeDefinition("Id", ScalarAttributeType.S), new AttributeDefinition("Name", ScalarAttributeType.S), }, - KeySchema = new List() { new KeySchemaElement("Id", KeyType.HASH), new KeySchemaElement("Name", KeyType.RANGE), }, - ProvisionedThroughput = new ProvisionedThroughput(1, 1), - TableClass = TableClass.STANDARD, - }) - .ConfigureAwait(false); - - _ = await client.PutItemAsync(new PutItemRequest(tableName, new Dictionary() { { "Id", new AttributeValue() { S = itemId } }, { "Name", new AttributeValue() { S = itemName } } })).ConfigureAwait(false); - - var getItemResponse = await client.GetItemAsync(new GetItemRequest(tableName, new Dictionary() { { "Id", new AttributeValue() { S = itemId } }, { "Name", new AttributeValue() { S = itemName } } })) - .ConfigureAwait(false); - - // Then - Assert.Equal(HttpStatusCode.OK, getItemResponse.HttpStatusCode); - } -} diff --git a/tests/Testcontainers.DynamoDb.Tests/Testcontainers.DynamoDb.Tests.csproj b/tests/Testcontainers.DynamoDb.Tests/Testcontainers.DynamoDb.Tests.csproj index d54ee95af..91e0518e9 100644 --- a/tests/Testcontainers.DynamoDb.Tests/Testcontainers.DynamoDb.Tests.csproj +++ b/tests/Testcontainers.DynamoDb.Tests/Testcontainers.DynamoDb.Tests.csproj @@ -1,18 +1,18 @@ - - net6.0 - false - false - - - - - - - - - - - - - + + net6.0 + false + false + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Testcontainers.DynamoDb.Tests/Usings.cs b/tests/Testcontainers.DynamoDb.Tests/Usings.cs index a9a7a8c09..1629ce9dd 100644 --- a/tests/Testcontainers.DynamoDb.Tests/Usings.cs +++ b/tests/Testcontainers.DynamoDb.Tests/Usings.cs @@ -1,10 +1,9 @@ global using System; global using System.Collections.Generic; -global using System.IO; +global using System.Linq; global using System.Net; global using System.Threading.Tasks; global using Amazon.DynamoDBv2; global using Amazon.DynamoDBv2.Model; -global using Amazon.Runtime; global using DotNet.Testcontainers.Commons; -global using Xunit; +global using Xunit; \ No newline at end of file diff --git a/tests/Testcontainers.Minio.Tests/MinioContainerTests.cs b/tests/Testcontainers.Minio.Tests/MinioContainerTest.cs similarity index 100% rename from tests/Testcontainers.Minio.Tests/MinioContainerTests.cs rename to tests/Testcontainers.Minio.Tests/MinioContainerTest.cs