Skip to content

Commit 2424868

Browse files
committed
Refactor integration tests. Now all run in TestContainer
1 parent 62ed433 commit 2424868

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

libraries/tests/AWS.Lambda.Powertools.Idempotency.Tests/IdempotencyTest.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,28 @@
2121
using Amazon.Lambda.APIGatewayEvents;
2222
using Amazon.Lambda.TestUtilities;
2323
using AWS.Lambda.Powertools.Idempotency.Tests.Handlers;
24+
using AWS.Lambda.Powertools.Idempotency.Tests.Persistence;
2425
using FluentAssertions;
2526
using Xunit;
2627

2728
namespace AWS.Lambda.Powertools.Idempotency.Tests;
2829

29-
public class IdempotencyTest
30+
public class IdempotencyTest : IClassFixture<DynamoDbFixture>
3031
{
31-
private const string TableName = "idempotency_table";
32+
private readonly AmazonDynamoDBClient _client;
33+
private readonly string _tableName;
34+
35+
public IdempotencyTest(DynamoDbFixture fixture)
36+
{
37+
_client = fixture.Client;
38+
_tableName = fixture.TableName;
39+
}
3240

33-
[Fact(Skip = "Integration Tests - Require setup")]
41+
[Fact]
3442
[Trait("Category", "Integration")]
3543
public async Task EndToEndTest()
3644
{
37-
var client = new AmazonDynamoDBClient();
38-
39-
var function = new IdempotencyFunction(client);
45+
var function = new IdempotencyFunction(_client);
4046

4147
var options = new JsonSerializerOptions
4248
{
@@ -58,9 +64,9 @@ public async Task EndToEndTest()
5864
JsonSerializer.Serialize(response).Should().Be(JsonSerializer.Serialize(response));
5965
response2.Body.Should().Contain("hello world");
6066

61-
var scanResponse = await client.ScanAsync(new ScanRequest
67+
var scanResponse = await _client.ScanAsync(new ScanRequest
6268
{
63-
TableName = TableName
69+
TableName = _tableName
6470
});
6571
scanResponse.Count.Should().Be(1);
6672
}

libraries/tests/AWS.Lambda.Powertools.Idempotency.Tests/Persistence/DynamoDBFixture.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class DynamoDbFixture : IDisposable
2929
{
3030
private readonly IContainer _container;
3131
public AmazonDynamoDBClient Client { get; set; }
32-
public DynamoDBPersistenceStore DynamoDbPersistenceStore { get; set; }
3332
public string TableName { get; set; } = "idempotency_table";
3433

3534
public DynamoDbFixture()
@@ -85,12 +84,6 @@ public DynamoDbFixture()
8584
{
8685
Console.WriteLine(e.Message);
8786
}
88-
89-
DynamoDbPersistenceStore = new DynamoDBPersistenceStoreBuilder()
90-
.WithTableName(TableName)
91-
.WithDynamoDBClient(Client)
92-
.Build();
93-
DynamoDbPersistenceStore.Configure(new IdempotencyOptionsBuilder().Build(),functionName: null);
9487
}
9588

9689
public void Dispose()

libraries/tests/AWS.Lambda.Powertools.Idempotency.Tests/Persistence/DynamoDBPersistenceStoreTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ public class DynamoDbPersistenceStoreTests : IClassFixture<DynamoDbFixture>
3333
private readonly DynamoDBPersistenceStore _dynamoDbPersistenceStore;
3434
private readonly AmazonDynamoDBClient _client;
3535
private readonly string _tableName;
36-
36+
3737
public DynamoDbPersistenceStoreTests(DynamoDbFixture fixture)
3838
{
39-
_dynamoDbPersistenceStore = fixture.DynamoDbPersistenceStore;
4039
_client = fixture.Client;
4140
_tableName = fixture.TableName;
41+
_dynamoDbPersistenceStore = new DynamoDBPersistenceStoreBuilder()
42+
.WithTableName(_tableName)
43+
.WithDynamoDBClient(_client)
44+
.Build();
45+
_dynamoDbPersistenceStore.Configure(new IdempotencyOptionsBuilder().Build(),functionName: null);
4246
}
4347

4448
//putRecord

0 commit comments

Comments
 (0)