Skip to content

Commit c4143f5

Browse files
committed
Updated apig & testcontainers projects
1 parent 9bad085 commit c4143f5

File tree

31 files changed

+70
-79
lines changed

31 files changed

+70
-79
lines changed

dotnet-test-samples/apigw-lambda-ddb/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![.NET: 6.0](https://img.shields.io/badge/.NET-6.0-Green)]()
1+
[![.NET: 8.0](https://img.shields.io/badge/.NET-8.0-Green)]()
22
[![AWS: Lambda](https://img.shields.io/badge/AWS-Lambda-blueviolet)]()
33
[![Amazon: Api Gateway](https://img.shields.io/badge/Amazon-API%20Gateway-blueviolet)]()
44
[![Amazon: DynamoDB](https://img.shields.io/badge/Amazon-DynamoDB-blueviolet)]()
@@ -15,7 +15,7 @@ This pattern creates an Amazon API Gateway HTTP API, an AWS Lambda function, and
1515
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage. Please see the AWS Pricing page for details. You are responsible for any AWS costs incurred.
1616

1717
## Language
18-
.NET 6
18+
.NET 8
1919

2020
## Framework
2121
The framework used to deploy the infrastructure is SAM

dotnet-test-samples/apigw-lambda-ddb/src/DeleteProduct/DeleteProduct.csproj

+1-1
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
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
66
<PublishReadyToRun>true</PublishReadyToRun>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

dotnet-test-samples/apigw-lambda-ddb/src/DeleteProduct/Function.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ namespace DeleteProduct;
1919

2020
public class Function
2121
{
22-
private readonly IProductsDAO _dataAccess;
22+
private readonly IProductsDao _dataAccess;
2323
private readonly ILogger<Function> _logger;
2424

2525
public Function() : this(Startup.ServiceProvider) { }
2626

27-
public Function(IProductsDAO dataAccess, ILogger<Function> logger)
27+
public Function(IProductsDao dataAccess, ILogger<Function> logger)
2828
: this(NewServiceProvider(dataAccess, logger)) { }
2929

3030
private Function(IServiceProvider serviceProvider)
3131
{
32-
_dataAccess = serviceProvider.GetRequiredService<IProductsDAO>();
32+
_dataAccess = serviceProvider.GetRequiredService<IProductsDao>();
3333
_logger = serviceProvider.GetRequiredService<ILogger<Function>>();
3434
}
3535

36-
private static IServiceProvider NewServiceProvider(IProductsDAO dataAccess, ILogger<Function> logger)
36+
private static IServiceProvider NewServiceProvider(IProductsDao dataAccess, ILogger<Function> logger)
3737
{
3838
var container = new System.ComponentModel.Design.ServiceContainer();
3939

40-
container.AddService(typeof(IProductsDAO), dataAccess);
40+
container.AddService(typeof(IProductsDao), dataAccess);
4141
container.AddService(typeof(ILogger<Function>), logger);
4242

4343
return container;

dotnet-test-samples/apigw-lambda-ddb/src/GetProduct/Function.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@ namespace GetProduct;
1919

2020
public class Function
2121
{
22-
private readonly IProductsDAO _dataAccess;
22+
private readonly IProductsDao _dataAccess;
2323
private readonly IOptions<JsonSerializerOptions> _jsonOptions;
2424
private readonly ILogger<Function> _logger;
2525

2626
public Function() : this(Startup.ServiceProvider) { }
2727

2828
public Function(
29-
IProductsDAO dataAccess,
29+
IProductsDao dataAccess,
3030
ILogger<Function> logger,
3131
IOptions<JsonSerializerOptions> jsonOptions)
3232
: this(NewServiceProvider(dataAccess, logger, jsonOptions)) { }
3333

3434
private Function(IServiceProvider serviceProvider)
3535
{
36-
_dataAccess = serviceProvider.GetRequiredService<IProductsDAO>();
36+
_dataAccess = serviceProvider.GetRequiredService<IProductsDao>();
3737
_jsonOptions = serviceProvider.GetRequiredService<IOptions<JsonSerializerOptions>>();
3838
_logger = serviceProvider.GetRequiredService<ILogger<Function>>();
3939
}
4040

4141
private static IServiceProvider NewServiceProvider(
42-
IProductsDAO dataAccess,
42+
IProductsDao dataAccess,
4343
ILogger<Function> logger,
4444
IOptions<JsonSerializerOptions> jsonOptions)
4545
{
4646
var container = new System.ComponentModel.Design.ServiceContainer();
4747

48-
container.AddService(typeof(IProductsDAO), dataAccess);
48+
container.AddService(typeof(IProductsDao), dataAccess);
4949
container.AddService(typeof(IOptions<JsonSerializerOptions>), jsonOptions);
5050
container.AddService(typeof(ILogger<Function>), logger);
5151

dotnet-test-samples/apigw-lambda-ddb/src/GetProduct/GetProduct.csproj

+1-1
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
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
66
<PublishReadyToRun>true</PublishReadyToRun>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

dotnet-test-samples/apigw-lambda-ddb/src/GetProducts/Function.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@ namespace GetProducts;
1919

2020
public class Function
2121
{
22-
private readonly IProductsDAO _dataAccess;
22+
private readonly IProductsDao _dataAccess;
2323
private readonly IOptions<JsonSerializerOptions> _jsonOptions;
2424
private readonly ILogger<Function> _logger;
2525

2626
public Function() : this(Startup.ServiceProvider) { }
2727

2828
public Function(
29-
IProductsDAO dataAccess,
29+
IProductsDao dataAccess,
3030
ILogger<Function> logger,
3131
IOptions<JsonSerializerOptions> jsonOptions)
3232
: this(NewServiceProvider(dataAccess, logger, jsonOptions)) { }
3333

3434
private Function(IServiceProvider serviceProvider)
3535
{
36-
_dataAccess = serviceProvider.GetRequiredService<IProductsDAO>();
36+
_dataAccess = serviceProvider.GetRequiredService<IProductsDao>();
3737
_jsonOptions = serviceProvider.GetRequiredService<IOptions<JsonSerializerOptions>>();
3838
_logger = serviceProvider.GetRequiredService<ILogger<Function>>();
3939
}
4040

4141
private static IServiceProvider NewServiceProvider(
42-
IProductsDAO dataAccess,
42+
IProductsDao dataAccess,
4343
ILogger<Function> logger,
4444
IOptions<JsonSerializerOptions> jsonOptions)
4545
{
4646
var container = new System.ComponentModel.Design.ServiceContainer();
4747

48-
container.AddService(typeof(IProductsDAO), dataAccess);
48+
container.AddService(typeof(IProductsDao), dataAccess);
4949
container.AddService(typeof(IOptions<JsonSerializerOptions>), jsonOptions);
5050
container.AddService(typeof(ILogger<Function>), logger);
5151

dotnet-test-samples/apigw-lambda-ddb/src/GetProducts/GetProducts.csproj

+1-1
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
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
66
<PublishReadyToRun>true</PublishReadyToRun>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

dotnet-test-samples/apigw-lambda-ddb/src/PutProduct/Function.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@ namespace PutProduct
1919
{
2020
public class Function
2121
{
22-
private readonly IProductsDAO _dataAccess;
22+
private readonly IProductsDao _dataAccess;
2323
private readonly IOptions<JsonSerializerOptions> _jsonOptions;
2424
private readonly ILogger<Function> _logger;
2525

2626
public Function() : this(Startup.ServiceProvider) { }
2727

2828
public Function(
29-
IProductsDAO dataAccess,
29+
IProductsDao dataAccess,
3030
ILogger<Function> logger,
3131
IOptions<JsonSerializerOptions> jsonOptions)
3232
: this(NewServiceProvider(dataAccess, logger, jsonOptions)) { }
3333

3434
private Function(IServiceProvider serviceProvider)
3535
{
36-
_dataAccess = serviceProvider.GetRequiredService<IProductsDAO>();
36+
_dataAccess = serviceProvider.GetRequiredService<IProductsDao>();
3737
_jsonOptions = serviceProvider.GetRequiredService<IOptions<JsonSerializerOptions>>();
3838
_logger = serviceProvider.GetRequiredService<ILogger<Function>>();
3939
}
4040

4141
private static IServiceProvider NewServiceProvider(
42-
IProductsDAO dataAccess,
42+
IProductsDao dataAccess,
4343
ILogger<Function> logger,
4444
IOptions<JsonSerializerOptions> jsonOptions)
4545
{
4646
var container = new System.ComponentModel.Design.ServiceContainer();
4747

48-
container.AddService(typeof(IProductsDAO), dataAccess);
48+
container.AddService(typeof(IProductsDao), dataAccess);
4949
container.AddService(typeof(IOptions<JsonSerializerOptions>), jsonOptions);
5050
container.AddService(typeof(ILogger<Function>), logger);
5151

dotnet-test-samples/apigw-lambda-ddb/src/PutProduct/PutProduct.csproj

+1-1
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
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
66
<PublishReadyToRun>true</PublishReadyToRun>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

dotnet-test-samples/apigw-lambda-ddb/src/ServerlessTestApi.Core/DataAccess/IProductsDAO.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ServerlessTestApi.Core.DataAccess;
66

7-
public interface IProductsDAO
7+
public interface IProductsDao
88
{
99
Task<ProductDTO?> GetProduct(string id, CancellationToken cancellationToken);
1010

dotnet-test-samples/apigw-lambda-ddb/src/ServerlessTestApi.Core/ServerlessTestApi.Core.csproj

+1-1
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
<RootNamespace>ServerlessTestApi.Core</RootNamespace>
66
</PropertyGroup>
77

dotnet-test-samples/apigw-lambda-ddb/src/ServerlessTestApi.Infrastructure/DataAccess/DynamoDbProducts.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace ServerlessTestApi.Infrastructure.DataAccess;
88

9-
public class DynamoDbProducts : IProductsDAO
9+
public class DynamoDbProducts : IProductsDao
1010
{
1111
private readonly IAmazonDynamoDB _dynamoDbClient;
1212
private readonly IOptions<DynamoDbOptions> _options;

dotnet-test-samples/apigw-lambda-ddb/src/ServerlessTestApi.Infrastructure/ServerlessTestApi.Infrastructure.csproj

+1-1
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
</PropertyGroup>

dotnet-test-samples/apigw-lambda-ddb/src/ServerlessTestApi.Infrastructure/Startup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void AddDefaultServices(IServiceCollection services)
3939
services.TryAddTransient<IValidateOptions<DynamoDbOptions>, DynamoDbOptionsValidator>();
4040
services.AddLogging(builder => builder.AddSerilog(logger));
4141
services.TryAddSingleton<IAmazonDynamoDB>(static sp => new AmazonDynamoDBClient());
42-
services.TryAddSingleton<IProductsDAO, DynamoDbProducts>();
42+
services.TryAddSingleton<IProductsDao, DynamoDbProducts>();
4343
}
4444

4545
private static IServiceProvider InitializeServiceProvider()

dotnet-test-samples/apigw-lambda-ddb/template.yaml

+1-1
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
Environment:

dotnet-test-samples/apigw-lambda-ddb/tests/ApiTests.IntegrationTest/ApiTests.IntegrationTest.csproj

+1-1
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
<IsPackable>false</IsPackable>

dotnet-test-samples/apigw-lambda-ddb/tests/ApiTests.UnitTest/ApiTests.UnitTest.csproj

+1-1
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
<IsPackable>false</IsPackable>

dotnet-test-samples/apigw-lambda-ddb/tests/ApiTests.UnitTest/MockDeleteProductFunctionTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public async Task DeleteProduct_With_ProductInDb_Should_ReturnSuccess()
1919
.WithHttpMethod(HttpMethod.Delete)
2020
.Build();
2121

22-
var fakeProductDao = A.Fake<IProductsDAO>();
22+
var fakeProductDao = A.Fake<IProductsDao>();
2323

2424
A.CallTo(() => fakeProductDao.GetProduct(A<string>._, A<CancellationToken>._))
2525
.Returns(Task.FromResult<ProductDTO?>(new ProductDTO("123456", "Test Product", 10)));
@@ -48,7 +48,7 @@ public async Task TestLambdaHandler_With_NonDeleteRequests_Should_Return405(stri
4848
.WithHttpMethod(httpMethod)
4949
.Build();
5050

51-
var fakeProductDao = A.Fake<IProductsDAO>();
51+
var fakeProductDao = A.Fake<IProductsDao>();
5252
var function = new Function(fakeProductDao, Logger);
5353

5454
// act
@@ -67,7 +67,7 @@ public async Task DeleteProduct_With_ErrorInDeleteDataAccess_Should_Return500()
6767
.WithHttpMethod(HttpMethod.Delete)
6868
.Build();
6969

70-
var fakeProductDao = A.Fake<IProductsDAO>();
70+
var fakeProductDao = A.Fake<IProductsDao>();
7171
A.CallTo(() => fakeProductDao.DeleteProduct(A<string>._, A<CancellationToken>._))
7272
.Throws<NullReferenceException>();
7373

@@ -89,7 +89,7 @@ public async Task DeleteProduct_With_TimeOut_Should_Return503()
8989
.WithHttpMethod(HttpMethod.Delete)
9090
.Build();
9191

92-
var fakeProductDao = A.Fake<IProductsDAO>();
92+
var fakeProductDao = A.Fake<IProductsDao>();
9393

9494
A.CallTo(() => fakeProductDao.DeleteProduct(A<string>._, A<CancellationToken>._))
9595
.Throws<TaskCanceledException>();

dotnet-test-samples/apigw-lambda-ddb/tests/ApiTests.UnitTest/MockGetProductFunctionTests.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public async Task GetProduct_Should_ReturnSuccess()
2020
.Build();
2121

2222
var expected = new ProductDTO("testid", "test product", 10);
23-
var fakeProductDao = A.Fake<IProductsDAO>();
23+
var fakeProductDao = A.Fake<IProductsDao>();
2424

2525
A.CallTo(() => fakeProductDao.GetProduct(A<string>._, A<CancellationToken>._))
2626
.Returns(Task.FromResult<ProductDTO?>(expected));
@@ -50,7 +50,7 @@ public async Task TestLambdaHandler_WithNonGetRequests_Should_Return405(string h
5050
.WithHttpMethod(httpMethod)
5151
.Build();
5252

53-
var fakeProductDao = A.Fake<IProductsDAO>();
53+
var fakeProductDao = A.Fake<IProductsDao>();
5454
var function = new Function(fakeProductDao, Logger, JsonOptions);
5555

5656
// act
@@ -69,7 +69,7 @@ public async Task GetProduct_With_ErrorInDataAccess_Should_Return500()
6969
.WithHttpMethod(HttpMethod.Get)
7070
.Build();
7171

72-
var fakeProductDao = A.Fake<IProductsDAO>();
72+
var fakeProductDao = A.Fake<IProductsDao>();
7373

7474
A.CallTo(() => fakeProductDao.GetProduct(A<string>._, A<CancellationToken>._))
7575
.Throws<NullReferenceException>();
@@ -92,7 +92,7 @@ public async Task GetProduct_With_TimeOut_Should_Return503()
9292
.WithHttpMethod(HttpMethod.Get)
9393
.Build();
9494

95-
var fakeProductDao = A.Fake<IProductsDAO>();
95+
var fakeProductDao = A.Fake<IProductsDao>();
9696

9797
A.CallTo(() => fakeProductDao.GetProduct(A<string>._, A<CancellationToken>._))
9898
.Throws<TaskCanceledException>();
@@ -115,7 +115,7 @@ public async Task GetProduct_With_ProductNotFound_Should_Return404()
115115
.WithPathParameter("id", "123456")
116116
.Build();
117117

118-
var fakeProductDao = A.Fake<IProductsDAO>();
118+
var fakeProductDao = A.Fake<IProductsDao>();
119119

120120
A.CallTo(() => fakeProductDao.GetProduct(A<string>._, A<CancellationToken>._))
121121
.Returns(Task.FromResult<ProductDTO?>(null));

dotnet-test-samples/apigw-lambda-ddb/tests/ApiTests.UnitTest/MockGetProductsFunctionTests.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public async Task GetProducts_Should_ReturnSuccess()
1717
var request = new ApiRequestBuilder()
1818
.WithHttpMethod(HttpMethod.Get)
1919
.Build();
20-
var fakeProductDao = A.Fake<IProductsDAO>();
20+
var fakeProductDao = A.Fake<IProductsDao>();
2121

2222
A.CallTo(() => fakeProductDao.GetAllProducts(A<CancellationToken>._))
2323
.Returns(Task.FromResult(
@@ -49,7 +49,7 @@ public async Task GetProducts_With_DataAccessReturnsProducts_Should_ReturnInBody
4949
{
5050
new("testid", "test product", 10),
5151
});
52-
var fakeProductDao = A.Fake<IProductsDAO>();
52+
var fakeProductDao = A.Fake<IProductsDao>();
5353

5454
A.CallTo(() => fakeProductDao.GetAllProducts(A<CancellationToken>._))
5555
.Returns(Task.FromResult(expected));
@@ -78,7 +78,7 @@ public async Task TestLambdaHandler_With_NonGetRequests_Should_Return405(string
7878
.WithHttpMethod(httpMethod)
7979
.Build();
8080

81-
var fakeProductDao = A.Fake<IProductsDAO>();
81+
var fakeProductDao = A.Fake<IProductsDao>();
8282

8383
A.CallTo(() => fakeProductDao.GetAllProducts(A<CancellationToken>._))
8484
.Returns(Task.FromResult(new ProductWrapper(new List<ProductDTO>())));
@@ -100,7 +100,7 @@ public async Task GetProducts_With_ErrorInDataAccess_Should_Return500()
100100
.WithHttpMethod(HttpMethod.Get)
101101
.Build();
102102

103-
var fakeProductDao = A.Fake<IProductsDAO>();
103+
var fakeProductDao = A.Fake<IProductsDao>();
104104

105105
A.CallTo(() => fakeProductDao.GetAllProducts(A<CancellationToken>._))
106106
.Throws<NullReferenceException>();
@@ -122,7 +122,7 @@ public async Task GetProducts_With_TimeOut_Should_Return503()
122122
.WithHttpMethod(HttpMethod.Get)
123123
.Build();
124124

125-
var fakeProductDao = A.Fake<IProductsDAO>();
125+
var fakeProductDao = A.Fake<IProductsDao>();
126126

127127
A.CallTo(() => fakeProductDao.GetAllProducts(A<CancellationToken>._))
128128
.Throws<TaskCanceledException>();

0 commit comments

Comments
 (0)