Skip to content

Commit 2e43bae

Browse files
committed
Updated hexagonal Architecture
1 parent c4143f5 commit 2e43bae

File tree

8 files changed

+56
-39
lines changed

8 files changed

+56
-39
lines changed

dotnet-test-samples/hexagonal-architecture/src/GetStock/Adapters/StockDynamoDb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task<StockData> GetStockValueAsync(string stockId)
2828
}
2929
var jsonString = document.ToJson();
3030

31-
return JsonSerializer.Deserialize<StockData>(jsonString);
31+
return JsonSerializer.Deserialize<StockData>(jsonString)!;
3232
}
3333

3434
}

dotnet-test-samples/hexagonal-architecture/src/GetStock/Functions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private static ServiceProvider InitializeServiceProvider()
4444

4545
public class Functions
4646
{
47-
private readonly IHttpHandler? _handler;
47+
private readonly IHttpHandler _handler;
4848

4949
public Functions()
5050
{

dotnet-test-samples/hexagonal-architecture/src/GetStock/GetStock.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFramework>net8.0</TargetFramework>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
@@ -11,13 +11,13 @@
1111
<PublishReadyToRun>true</PublishReadyToRun>
1212
</PropertyGroup>
1313
<ItemGroup>
14-
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.6.0" />
15-
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.8.6" />
16-
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
17-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
18-
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.0.1" />
19-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.102.22" />
20-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
14+
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
15+
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" />
16+
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
17+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
18+
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
19+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.400.2" />
20+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
2121
</ItemGroup>
2222
<ItemGroup>
2323
<Folder Include="Adapters\Exceptions\" />

dotnet-test-samples/hexagonal-architecture/template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Globals:
55
Function:
66
MemorySize: 1024
77
Architectures: [arm64]
8-
Runtime: dotnet6
8+
Runtime: dotnet8
99
Timeout: 30
1010
Tracing: Active
1111

dotnet-test-samples/hexagonal-architecture/tests/GetStock.IntegrationTest/Adapters/StockDynamoDbTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77

88
namespace GetStock.IntegrationTest.Adapters;
99

10-
public class StockDynamoDbTests : DynamoDbTestBase
10+
public class StockDynamoDbTests(DynamoDbFixture fixture) : DynamoDbTestBase(fixture)
1111
{
12-
public StockDynamoDbTests(DynamoDbFixture fixture)
13-
: base("test-stocks", fixture)
14-
{
15-
}
16-
1712
[Fact]
1813
public async Task GetStockValue_With_StockNotInDb_Should_ThrowStockNotFoundException()
1914
{

dotnet-test-samples/hexagonal-architecture/tests/GetStock.IntegrationTest/Fixtures/DynamoDbTestBase.cs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,49 @@ namespace GetStock.IntegrationTest.Fixtures
55
{
66
public class DynamoDbTestBase : IClassFixture<DynamoDbFixture>, IDisposable
77
{
8-
private const string _tableNamePrefix = "test-stocks";
8+
private const string TableNamePrefix = "test-stocks";
99
protected string TableName { get; }
1010
protected IAmazonDynamoDB Client { get; }
1111

12-
public DynamoDbTestBase(string tableNamePrefix, DynamoDbFixture fixture)
12+
protected DynamoDbTestBase(DynamoDbFixture fixture)
1313
{
14-
TableName = $"{_tableNamePrefix}{Guid.NewGuid()}";
14+
TableName = $"{TableNamePrefix}{Guid.NewGuid()}";
1515
Client = fixture.Client;
1616

1717
var request = new CreateTableRequest
1818
{
1919
TableName = TableName,
20-
AttributeDefinitions = new List<AttributeDefinition>
21-
{
22-
new("StockId", "S")
23-
},
24-
KeySchema = new List<KeySchemaElement> { new("StockId", Amazon.DynamoDBv2.KeyType.HASH) },
20+
AttributeDefinitions = [new AttributeDefinition("StockId", "S")],
21+
KeySchema = [new KeySchemaElement("StockId", KeyType.HASH)],
2522
ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 1, WriteCapacityUnits = 1 }
2623
};
2724

2825
Client.CreateTableAsync(request).Wait();
26+
27+
WaitUntilDynamoDbActive().Wait();
28+
}
29+
30+
private async Task WaitUntilDynamoDbActive()
31+
{
32+
int sleepDuration = 2000;
33+
34+
var describeTableRequest = new DescribeTableRequest
35+
{
36+
TableName = TableName
37+
};
38+
39+
TableStatus status;
40+
41+
do
42+
{
43+
Thread.Sleep(sleepDuration);
44+
45+
var describeTableResponse = await Client.DescribeTableAsync(describeTableRequest);
46+
status = describeTableResponse.Table.TableStatus;
47+
48+
Console.Write(".");
49+
}
50+
while (status != TableStatus.ACTIVE);
2951
}
3052

3153
public void Dispose()

dotnet-test-samples/hexagonal-architecture/tests/GetStock.IntegrationTest/GetStock.IntegrationTest.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

88
<IsPackable>false</IsPackable>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="FluentAssertions" Version="6.10.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
14-
<PackageReference Include="xunit" Version="2.4.2" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
12+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
14+
<PackageReference Include="xunit" Version="2.9.0" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>
19-
<PackageReference Include="coverlet.collector" Version="3.2.0">
19+
<PackageReference Include="coverlet.collector" Version="6.0.2">
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
<PrivateAssets>all</PrivateAssets>
2222
</PackageReference>
23-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.102.22" />
23+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.400.2" />
2424
</ItemGroup>
2525

2626
<ItemGroup>

dotnet-test-samples/hexagonal-architecture/tests/GetStock.UnitTest/GetStock.UnitTest.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

@@ -11,15 +11,15 @@
1111
<ItemGroup>
1212
<PackageReference Include="Amazon.Lambda.TestUtilities" Version="2.0.0" />
1313
<PackageReference Include="Autofac.Extras.FakeItEasy" Version="7.0.0" />
14-
<PackageReference Include="FakeItEasy" Version="7.3.1" />
15-
<PackageReference Include="FluentAssertions" Version="6.10.0" />
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
17-
<PackageReference Include="xunit" Version="2.4.2" />
18-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
14+
<PackageReference Include="FakeItEasy" Version="8.3.0" />
15+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
17+
<PackageReference Include="xunit" Version="2.9.0" />
18+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>
22-
<PackageReference Include="coverlet.collector" Version="3.2.0">
22+
<PackageReference Include="coverlet.collector" Version="6.0.2">
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
<PrivateAssets>all</PrivateAssets>
2525
</PackageReference>

0 commit comments

Comments
 (0)