![]() |
VOOZH | about |
dotnet add package Siemens.AspNet.Lambda.MsTest.Sdk --version 7.5.8
NuGet\Install-Package Siemens.AspNet.Lambda.MsTest.Sdk -Version 7.5.8
<PackageReference Include="Siemens.AspNet.Lambda.MsTest.Sdk" Version="7.5.8" />
<PackageVersion Include="Siemens.AspNet.Lambda.MsTest.Sdk" Version="7.5.8" />Directory.Packages.props
<PackageReference Include="Siemens.AspNet.Lambda.MsTest.Sdk" />Project file
paket add Siemens.AspNet.Lambda.MsTest.Sdk --version 7.5.8
#r "nuget: Siemens.AspNet.Lambda.MsTest.Sdk, 7.5.8"
#:package Siemens.AspNet.Lambda.MsTest.Sdk@7.5.8
#addin nuget:?package=Siemens.AspNet.Lambda.MsTest.Sdk&version=7.5.8Install as a Cake Addin
#tool nuget:?package=Siemens.AspNet.Lambda.MsTest.Sdk&version=7.5.8Install as a Cake Tool
The Siemens.AspNet.Lambda.MsTest.Sdk provides testing utilities specifically designed for AWS Lambda functions using MS Test framework, focusing on mocking and logging capabilities.
This SDK eases the testing of business logic within AWS Lambda functions by offering mock helpers and logging infrastructure.
To integrate this SDK into your test project, ensure you have the necessary dependencies such as Moq and MS Test SDK. You can manage these dependencies via your .csproj file or .NET CLI.
| Component | Description |
|---|---|
LambdaContextMockHelper |
Utility for creating mocked ILambdaContext instances. |
LambdaTestBase<TFunction> |
Base class to streamline Lambda function testing. |
LogEntry |
Record to capture structured log information. |
The LambdaTestBase<TFunction> class simplifies the setup of mock loggers and context for Lambda function tests:
[TestClass]
[TestCategory("Lambdas")]
[TestCategory("Lambdas Init Cognito User - Function - Ok")]
public class Function_Ok_Test : LambdaTestBase<Function>
{
[DataTestMethod]
// More infos about DynamicResource locator you find here: https://www.nuget.org/packages/AspNetCore.Simple.MsTest.Sdk
[DynamicRequestLocator]
public async Task Lambda_Should_Execute_Successfully(string useCase)
{
// 1. Get payload as JSON string from embedded file
var json = EmbeddedFile.GetFileContentFrom($"SiemensGPT.InitCognitoUser.Tests.Ok.Requests.{useCase}");
// 2. Setup cognito confirmation event
var cognitoPostConfirmationEvent = json.FromJsonStringAs<CognitoPostConfirmationEvent>();
// 3. Execute lambda function - test passes if no exception is thrown
var response = await Function.InvokeAsync(cognitoPostConfirmationEvent, LambdaContext).ConfigureAwait(false);
// 4. Evaluate function response
Assert.That.ObjectsAreEqual($"SiemensGPT.InitCognitoUser.Tests.Ok.Responses.{useCase}", response);
// 5. Evaluate logging
Assert.That.ObjectsAreEqual($"SiemensGPT.InitCognitoUser.Tests.Ok.Responses.LogHistory.json", LogHistory);
}
}
Use LambdaContextMockHelper to create a mocked Lambda context, providing realistic values for AWS Lambda environment variables. Is already setup with the LambdaTestBase
public class LambdaTestBase<TFunction> where TFunction : class, new()
{
protected TFunction Function { get; private set; } = null!;
protected Mock<ILogger> LoggerMock { get; private set; } = null!;
protected ILogger Logger { get; private set; } = null!;
protected ILambdaContext LambdaContext { get; private set; } = null!;
protected List<LogEntry> LogHistory { get; private set; } = new();
protected LambdaSettings LambdaSettings { get; private set; } = new();
}
To customize your ILambdaContext, you can use our LambdaMockHelper
var mockContext = LambdaContextMockHelper.CreateMockContext<ILambdaContext>();
LogHistory in LambdaTestBase allows inspection of all log entries recorded during the test:
var errors = LogHistory.Where(log => log.Level == LogLevel.Error);
Assert.IsTrue(errors.Any(), "Expected at least one error log entry.");
Structured logging within tests helps identify issues by logging exception details, error messages, and execution context. The logger is already set up and the logger mock provides access to the log data for detailed examination.
Customize logging as needed:
// The property LogHistory provides the collected log information from the lambda execution.
// in this sample we are asserting the whole LogHistory
Assert.That.ObjectsAreEqual($"SiemensGPT.InitCognitoUser.Tests.Ok.Responses.LogHistory.json", LogHistory);
Sample for LogHistory.json
[
{
"level": "Information",
"id": {
"id": 0,
"name": null
},
"entry": "FunctionTimeout - Started",
"errorLogInfo": null
},
{
"level": "Information",
"id": {
"id": 0,
"name": null
},
"entry": "FunctionTimeout - Step 1",
"errorLogInfo": null
},
{
"level": "Error",
"id": {
"id": 0,
"name": null
},
"entry": "[TaskCanceledException] TaskCanceledException was thrown. Details: {\u0022errorType\u0022:\u0022TaskCanceledException\u0022,\u0022title\u0022:\u0022TaskCanceledException was thrown.\u0022,\u0022message\u0022:\u0022A task was canceled.\u0022,\u0022statusCode\u0022:500,\u0022requestInfos\u0022:{\u0022remainingTime\u0022:\u002200:00:10.1200000\u0022,\u0022functionVersion\u0022:\u0022$LATEST\u0022,\u0022functionName\u0022:\u0022FunctionTimeout\u0022,\u0022awsRequestId\u0022:\u0022test-request-id-123\u0022,\u0022memoryLimitInMB\u0022:256,\u0022logStreamName\u0022:\u00222025.05.27/[$LATEST]123456789\u0022,\u0022logGroupName\u0022:\u0022/aws/lambda/FunctionTimeout\u0022},\u0022errorDetails\u0022:{},\u0022extensions\u0022:{},\u0022stackTrace\u0022:[\u0022 at SiemensGPT.InitCognitoUser.FunctionTimeout.HandleAsync(CognitoPostConfirmationEvent request, ILambdaContext context, CancellationToken cancellationToken) in /Users/z0052jaz/RiderProjects/siemens-aspnet-sdk/src/SiemensGPT.InitCognitoUser/Functions/Timeout/FunctionTimeout.cs:line 20\u0022,\u0022 at Siemens.AspNet.Lambda.Sdk.ErrorLogging.ErrorLogRequestResponseMiddleware\\u00602.InvokeAsync(TRequest request, ILambdaContext context, LambdaRequestDelegate\\u00602 requestDelegate, CancellationToken cancellationToken) in /Users/z0052jaz/RiderProjects/siemens-aspnet-sdk/src/Siemens.AspNet.Lambda.Sdk/ErrorLogging/ErrorLogMiddleware{TRequest, TResponse}.cs:line 26\u0022]}",
"errorLogInfo": {
"errorType": "TaskCanceledException",
"title": "TaskCanceledException was thrown.",
"message": "A task was canceled.",
"statusCode": 500,
"requestInfos": {
"logGroupName": "/aws/lambda/FunctionTimeout",
"memoryLimitInMB": 256,
"functionName": "FunctionTimeout",
"logStreamName": "2025.05.27/[$LATEST]123456789",
"remainingTime": "00:00:10.1200000",
"functionVersion": "$LATEST",
"awsRequestId": "test-request-id-123"
},
"errorDetails": {},
"extensions": {},
"stackTrace": [
" at SiemensGPT.InitCognitoUser.FunctionTimeout.HandleAsync(CognitoPostConfirmationEvent request, ILambdaContext context, CancellationToken cancellationToken) in /Users/z0052jaz/RiderProjects/siemens-aspnet-sdk/src/SiemensGPT.InitCognitoUser/Functions/Timeout/FunctionTimeout.cs:line 20",
" at Siemens.AspNet.Lambda.Sdk.ErrorLogging.ErrorLogRequestResponseMiddleware\u00602.InvokeAsync(TRequest request, ILambdaContext context, LambdaRequestDelegate\u00602 requestDelegate, CancellationToken cancellationToken) in /Users/z0052jaz/RiderProjects/siemens-aspnet-sdk/src/Siemens.AspNet.Lambda.Sdk/ErrorLogging/ErrorLogMiddleware{TRequest, TResponse}.cs:line 26"
]
}
}
]
Detailed documentation and further examples can be found within the codebase and will soon be available online.
Contributions and feedback are welcome! Please create issues or pull requests to suggest improvements.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 7.5.8 | 0 | 6/19/2026 |
| 7.5.7 | 0 | 6/19/2026 |
| 7.5.6 | 43 | 6/17/2026 |
| 7.5.5 | 25 | 6/17/2026 |
| 7.5.4 | 26 | 6/17/2026 |
| 7.5.3 | 123 | 6/17/2026 |
| 7.5.2 | 45 | 6/16/2026 |
| 7.5.1 | 1,045 | 6/2/2026 |
| 7.5.0 | 99 | 5/12/2026 |
| 7.5.0-alpha.16 | 58 | 5/18/2026 |
| 7.5.0-alpha.15 | 49 | 5/18/2026 |
| 7.5.0-alpha.12 | 55 | 5/12/2026 |
| 7.5.0-alpha.11 | 51 | 5/12/2026 |
| 7.5.0-alpha.10 | 49 | 5/12/2026 |
| 7.4.6 | 30 | 6/2/2026 |
| 7.4.5 | 531 | 5/24/2026 |
| 7.4.4 | 40 | 5/18/2026 |
| 7.4.3 | 32 | 5/18/2026 |
| 7.4.2 | 1,842 | 5/11/2026 |
| 7.4.1 | 30 | 5/11/2026 |