Skip to content

Commit

Permalink
Merge pull request #348 from aws-samples/dotnet-upgrade-to-net8
Browse files Browse the repository at this point in the history
Upgrade to net8
  • Loading branch information
dhelper authored Aug 15, 2024
2 parents 6ecbbbf + 50a36d1 commit b4b9c4a
Show file tree
Hide file tree
Showing 101 changed files with 407 additions and 446 deletions.
4 changes: 2 additions & 2 deletions dotnet-test-samples/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![.NET: 6.0](https://img.shields.io/badge/.NET-6.0-Green)](https://img.shields.io/badge/.NET-6.0-Green)
[![.NET: 8.0](https://img.shields.io/badge/.NET-8.0-Green)](https://img.shields.io/badge/.NET-6.0-Green)

# .NET Test Samples

Expand All @@ -12,7 +12,7 @@ This portion of the repository contains code samples for testing serverless appl
|[Hexagonal Architecture](./hexagonal-architecture)|An example of hexagonal architecture implemented using AWS Lambda with tests.|
|[Kinesis Data Streams](./kinesis-lambda-dynamodb/)|This project contains unit and integration tests for a pattern using Kinesis Data Streams, AWS Lambda and Amazon DynamoDB.|
|[SQS with AWS Lambda and DynamoDb](./sqs-lambda)|This project contains unit and integration tests for AWS Lambda that is invoked by Amazon Simple Queue Service (SQS)|
|[Local testing using containers](./test-containers)|This pattern creates an Amazon API Gateway HTTP API, an AWS Lambda function, and a DynamoDB Table using SAM and .NET 6. It also demonstrates how you can use a local emulated version of DynamoDB to increase the speed of feedback loops as you make changes to your application code.|
|[Local testing using containers](./test-containers)|This pattern creates an Amazon API Gateway HTTP API, an AWS Lambda function, and a DynamoDB Table using SAM and .NET 8. It also demonstrates how you can use a local emulated version of DynamoDB to increase the speed of feedback loops as you make changes to your application code.|
|[Load Testing](./load-testing)|A description of how load testing can be carried out before deploying to production |

## Test Asynchronous Architectures
Expand Down
8 changes: 4 additions & 4 deletions dotnet-test-samples/apigw-lambda-ddb/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![.NET: 6.0](https://img.shields.io/badge/.NET-6.0-Green)]()
[![.NET: 8.0](https://img.shields.io/badge/.NET-8.0-Green)]()
[![AWS: Lambda](https://img.shields.io/badge/AWS-Lambda-blueviolet)]()
[![Amazon: Api Gateway](https://img.shields.io/badge/Amazon-API%20Gateway-blueviolet)]()
[![Amazon: DynamoDB](https://img.shields.io/badge/Amazon-DynamoDB-blueviolet)]()
Expand All @@ -10,12 +10,12 @@

### Description

This pattern creates an Amazon API Gateway HTTP API, an AWS Lambda function, and a DynamoDB Table using SAM and .NET 6.
This pattern creates an Amazon API Gateway HTTP API, an AWS Lambda function, and a DynamoDB Table using SAM and .NET 8.

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.

## Language
.NET 6
.NET 8

## Framework
The framework used to deploy the infrastructure is SAM
Expand Down Expand Up @@ -199,7 +199,7 @@ sam delete
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
* [.NET 6](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) installed
* [.NET 8](https://dotnet.microsoft.com/en-us/download/dotnet) installed

## Video Walkthroughs

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PublishReadyToRun>true</PublishReadyToRun>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ namespace DeleteProduct;

public class Function
{
private readonly IProductsDAO _dataAccess;
private readonly IProductsDao _dataAccess;
private readonly ILogger<Function> _logger;

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

public Function(IProductsDAO dataAccess, ILogger<Function> logger)
public Function(IProductsDao dataAccess, ILogger<Function> logger)
: this(NewServiceProvider(dataAccess, logger)) { }

private Function(IServiceProvider serviceProvider)
{
_dataAccess = serviceProvider.GetRequiredService<IProductsDAO>();
_dataAccess = serviceProvider.GetRequiredService<IProductsDao>();
_logger = serviceProvider.GetRequiredService<ILogger<Function>>();
}

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

container.AddService(typeof(IProductsDAO), dataAccess);
container.AddService(typeof(IProductsDao), dataAccess);
container.AddService(typeof(ILogger<Function>), logger);

return container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"region": "",
"configuration": "Release",
"function-architecture": "x86_64",
"function-runtime": "dotnet6",
"function-runtime": "dotnet8",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "DeleteProduct::DeleteProduct.Function::FunctionHandler"
Expand Down
10 changes: 5 additions & 5 deletions dotnet-test-samples/apigw-lambda-ddb/src/GetProduct/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ namespace GetProduct;

public class Function
{
private readonly IProductsDAO _dataAccess;
private readonly IProductsDao _dataAccess;
private readonly IOptions<JsonSerializerOptions> _jsonOptions;
private readonly ILogger<Function> _logger;

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

public Function(
IProductsDAO dataAccess,
IProductsDao dataAccess,
ILogger<Function> logger,
IOptions<JsonSerializerOptions> jsonOptions)
: this(NewServiceProvider(dataAccess, logger, jsonOptions)) { }

private Function(IServiceProvider serviceProvider)
{
_dataAccess = serviceProvider.GetRequiredService<IProductsDAO>();
_dataAccess = serviceProvider.GetRequiredService<IProductsDao>();
_jsonOptions = serviceProvider.GetRequiredService<IOptions<JsonSerializerOptions>>();
_logger = serviceProvider.GetRequiredService<ILogger<Function>>();
}

private static IServiceProvider NewServiceProvider(
IProductsDAO dataAccess,
IProductsDao dataAccess,
ILogger<Function> logger,
IOptions<JsonSerializerOptions> jsonOptions)
{
var container = new System.ComponentModel.Design.ServiceContainer();

container.AddService(typeof(IProductsDAO), dataAccess);
container.AddService(typeof(IProductsDao), dataAccess);
container.AddService(typeof(IOptions<JsonSerializerOptions>), jsonOptions);
container.AddService(typeof(ILogger<Function>), logger);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PublishReadyToRun>true</PublishReadyToRun>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"region": "",
"configuration": "Release",
"function-architecture": "x86_64",
"function-runtime": "dotnet6",
"function-runtime": "dotnet8",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "GetProduct::GetProduct.Function::FunctionHandler"
Expand Down
10 changes: 5 additions & 5 deletions dotnet-test-samples/apigw-lambda-ddb/src/GetProducts/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ namespace GetProducts;

public class Function
{
private readonly IProductsDAO _dataAccess;
private readonly IProductsDao _dataAccess;
private readonly IOptions<JsonSerializerOptions> _jsonOptions;
private readonly ILogger<Function> _logger;

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

public Function(
IProductsDAO dataAccess,
IProductsDao dataAccess,
ILogger<Function> logger,
IOptions<JsonSerializerOptions> jsonOptions)
: this(NewServiceProvider(dataAccess, logger, jsonOptions)) { }

private Function(IServiceProvider serviceProvider)
{
_dataAccess = serviceProvider.GetRequiredService<IProductsDAO>();
_dataAccess = serviceProvider.GetRequiredService<IProductsDao>();
_jsonOptions = serviceProvider.GetRequiredService<IOptions<JsonSerializerOptions>>();
_logger = serviceProvider.GetRequiredService<ILogger<Function>>();
}

private static IServiceProvider NewServiceProvider(
IProductsDAO dataAccess,
IProductsDao dataAccess,
ILogger<Function> logger,
IOptions<JsonSerializerOptions> jsonOptions)
{
var container = new System.ComponentModel.Design.ServiceContainer();

container.AddService(typeof(IProductsDAO), dataAccess);
container.AddService(typeof(IProductsDao), dataAccess);
container.AddService(typeof(IOptions<JsonSerializerOptions>), jsonOptions);
container.AddService(typeof(ILogger<Function>), logger);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PublishReadyToRun>true</PublishReadyToRun>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"region": "",
"configuration": "Release",
"function-architecture": "x86_64",
"function-runtime": "dotnet6",
"function-runtime": "dotnet8",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "GetProducts::GetProducts.Function::FunctionHandler"
Expand Down
10 changes: 5 additions & 5 deletions dotnet-test-samples/apigw-lambda-ddb/src/PutProduct/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ namespace PutProduct
{
public class Function
{
private readonly IProductsDAO _dataAccess;
private readonly IProductsDao _dataAccess;
private readonly IOptions<JsonSerializerOptions> _jsonOptions;
private readonly ILogger<Function> _logger;

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

public Function(
IProductsDAO dataAccess,
IProductsDao dataAccess,
ILogger<Function> logger,
IOptions<JsonSerializerOptions> jsonOptions)
: this(NewServiceProvider(dataAccess, logger, jsonOptions)) { }

private Function(IServiceProvider serviceProvider)
{
_dataAccess = serviceProvider.GetRequiredService<IProductsDAO>();
_dataAccess = serviceProvider.GetRequiredService<IProductsDao>();
_jsonOptions = serviceProvider.GetRequiredService<IOptions<JsonSerializerOptions>>();
_logger = serviceProvider.GetRequiredService<ILogger<Function>>();
}

private static IServiceProvider NewServiceProvider(
IProductsDAO dataAccess,
IProductsDao dataAccess,
ILogger<Function> logger,
IOptions<JsonSerializerOptions> jsonOptions)
{
var container = new System.ComponentModel.Design.ServiceContainer();

container.AddService(typeof(IProductsDAO), dataAccess);
container.AddService(typeof(IProductsDao), dataAccess);
container.AddService(typeof(IOptions<JsonSerializerOptions>), jsonOptions);
container.AddService(typeof(ILogger<Function>), logger);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PublishReadyToRun>true</PublishReadyToRun>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"region": "",
"configuration": "Release",
"function-architecture": "x86_64",
"function-runtime": "dotnet6",
"function-runtime": "dotnet8",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "PutProduct::PutProduct.Function::FunctionHandler"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ServerlessTestApi.Core.DataAccess;

public interface IProductsDAO
public interface IProductsDao
{
Task<ProductDTO?> GetProduct(string id, CancellationToken cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>ServerlessTestApi.Core</RootNamespace>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ServerlessTestApi.Infrastructure.DataAccess;

public class DynamoDbProducts : IProductsDAO
public class DynamoDbProducts : IProductsDao
{
private readonly IAmazonDynamoDB _dynamoDbClient;
private readonly IOptions<DynamoDbOptions> _options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void AddDefaultServices(IServiceCollection services)
services.TryAddTransient<IValidateOptions<DynamoDbOptions>, DynamoDbOptionsValidator>();
services.AddLogging(builder => builder.AddSerilog(logger));
services.TryAddSingleton<IAmazonDynamoDB>(static sp => new AmazonDynamoDBClient());
services.TryAddSingleton<IProductsDAO, DynamoDbProducts>();
services.TryAddSingleton<IProductsDao, DynamoDbProducts>();
}

private static IServiceProvider InitializeServiceProvider()
Expand Down
2 changes: 1 addition & 1 deletion dotnet-test-samples/apigw-lambda-ddb/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Globals:
Function:
MemorySize: 1024
Architectures: [arm64]
Runtime: dotnet6
Runtime: dotnet8
Timeout: 30
Tracing: Active
Environment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task DeleteProduct_With_ProductInDb_Should_ReturnSuccess()
.WithHttpMethod(HttpMethod.Delete)
.Build();

var fakeProductDao = A.Fake<IProductsDAO>();
var fakeProductDao = A.Fake<IProductsDao>();

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

var fakeProductDao = A.Fake<IProductsDAO>();
var fakeProductDao = A.Fake<IProductsDao>();
var function = new Function(fakeProductDao, Logger);

// act
Expand All @@ -67,7 +67,7 @@ public async Task DeleteProduct_With_ErrorInDeleteDataAccess_Should_Return500()
.WithHttpMethod(HttpMethod.Delete)
.Build();

var fakeProductDao = A.Fake<IProductsDAO>();
var fakeProductDao = A.Fake<IProductsDao>();
A.CallTo(() => fakeProductDao.DeleteProduct(A<string>._, A<CancellationToken>._))
.Throws<NullReferenceException>();

Expand All @@ -89,7 +89,7 @@ public async Task DeleteProduct_With_TimeOut_Should_Return503()
.WithHttpMethod(HttpMethod.Delete)
.Build();

var fakeProductDao = A.Fake<IProductsDAO>();
var fakeProductDao = A.Fake<IProductsDao>();

A.CallTo(() => fakeProductDao.DeleteProduct(A<string>._, A<CancellationToken>._))
.Throws<TaskCanceledException>();
Expand Down
Loading

0 comments on commit b4b9c4a

Please sign in to comment.