Siemens.AspNet.Lambda.MsTest.Sdk 0.1.0-alpha.235

Prefix Reserved
This is a prerelease version of Siemens.AspNet.Lambda.MsTest.Sdk.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Siemens.AspNet.Lambda.MsTest.Sdk --version 0.1.0-alpha.235
                    
NuGet\Install-Package Siemens.AspNet.Lambda.MsTest.Sdk -Version 0.1.0-alpha.235
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Siemens.AspNet.Lambda.MsTest.Sdk" Version="0.1.0-alpha.235" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Siemens.AspNet.Lambda.MsTest.Sdk" Version="0.1.0-alpha.235" />
                    
Directory.Packages.props
<PackageReference Include="Siemens.AspNet.Lambda.MsTest.Sdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Siemens.AspNet.Lambda.MsTest.Sdk --version 0.1.0-alpha.235
                    
#r "nuget: Siemens.AspNet.Lambda.MsTest.Sdk, 0.1.0-alpha.235"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Siemens.AspNet.Lambda.MsTest.Sdk@0.1.0-alpha.235
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Siemens.AspNet.Lambda.MsTest.Sdk&version=0.1.0-alpha.235&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Siemens.AspNet.Lambda.MsTest.Sdk&version=0.1.0-alpha.235&prerelease
                    
Install as a Cake Tool

Siemens.AspNet.Lambda.MsTest.Sdk

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.


📖 Overview

This SDK eases the testing of business logic within AWS Lambda functions by offering mock helpers and logging infrastructure.

✅ Key Features

  • 🚀 Enable lambda context mocking for unit tests.
  • 🔍 Structured logging and log history collection for test review.
  • 🛠️ Customizable test initialization with dependency injection.

📦 Installation

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.


🧠 Key Components

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.

⚡ Quickstart Examples

Testing a Lambda Function with Logging

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);
    }
}

Mocking Lambda Context

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>();

Capturing and Reviewing Logs

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.");

📌 Error Handling and Logging

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"
      ]
    }
  }
]


📚 Documentation

Detailed documentation and further examples can be found within the codebase and will soon be available online.


📢 Contributing

Contributions and feedback are welcome! Please create issues or pull requests to suggest improvements.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-alpha.294 5 10/17/2025
0.1.0-alpha.293 179 10/8/2025
0.1.0-alpha.292 109 10/8/2025
0.1.0-alpha.290 121 10/8/2025
0.1.0-alpha.289 113 10/7/2025
0.1.0-alpha.284 126 10/7/2025
0.1.0-alpha.283 201 9/19/2025
0.1.0-alpha.282 611 9/19/2025
0.1.0-alpha.281 280 9/16/2025
0.1.0-alpha.280 255 9/16/2025
0.1.0-alpha.279 253 9/16/2025
0.1.0-alpha.278 254 9/16/2025
0.1.0-alpha.275 478 9/3/2025
0.1.0-alpha.274 315 9/2/2025
0.1.0-alpha.273 356 9/1/2025
0.1.0-alpha.272 118 9/1/2025
0.1.0-alpha.271 166 8/29/2025
0.1.0-alpha.270 155 8/29/2025
0.1.0-alpha.269 151 8/29/2025
0.1.0-alpha.268 160 8/29/2025
0.1.0-alpha.267 165 8/27/2025
0.1.0-alpha.266 166 8/27/2025
0.1.0-alpha.264 244 8/22/2025
0.1.0-alpha.263 69 8/22/2025
0.1.0-alpha.262 73 8/22/2025
0.1.0-alpha.261 86 8/22/2025
0.1.0-alpha.260 94 8/22/2025
0.1.0-alpha.259 97 8/22/2025
0.1.0-alpha.258 186 8/19/2025
0.1.0-alpha.257 192 8/18/2025
0.1.0-alpha.246 142 8/14/2025
0.1.0-alpha.245 119 8/14/2025
0.1.0-alpha.244 139 8/14/2025
0.1.0-alpha.243 118 8/14/2025
0.1.0-alpha.238 125 8/12/2025
0.1.0-alpha.237 387 8/6/2025
0.1.0-alpha.236 197 8/5/2025
0.1.0-alpha.235 201 8/5/2025
0.1.0-alpha.234 233 8/5/2025
0.1.0-alpha.233 166 8/4/2025
0.1.0-alpha.232 178 8/4/2025
0.1.0-alpha.231 78 8/1/2025
0.1.0-alpha.230 77 8/1/2025
0.1.0-alpha.229 95 7/31/2025
0.1.0-alpha.228 94 7/31/2025
0.1.0-alpha.227 95 7/31/2025
0.1.0-alpha.225 95 7/31/2025
0.1.0-alpha.224 95 7/30/2025
0.1.0-alpha.222 283 7/16/2025
0.1.0-alpha.219 162 7/14/2025
0.1.0-alpha.217 84 7/11/2025
0.1.0-alpha.212 158 7/8/2025
0.1.0-alpha.211 127 7/3/2025
0.1.0-alpha.207 120 7/3/2025
0.1.0-alpha.206 237 6/30/2025
0.1.0-alpha.205 109 6/27/2025
0.1.0-alpha.202 99 6/27/2025
0.1.0-alpha.200 99 6/27/2025
0.1.0-alpha.198 97 6/27/2025
0.1.0-alpha.196 104 6/27/2025
0.1.0-alpha.195 103 6/27/2025
0.1.0-alpha.194 97 6/27/2025
0.1.0-alpha.193 99 6/27/2025
0.1.0-alpha.192 98 6/27/2025
0.1.0-alpha.191 98 6/27/2025
0.1.0-alpha.189 119 6/26/2025
0.1.0-alpha.188 117 6/26/2025
0.1.0-alpha.187 115 6/26/2025
0.1.0-alpha.186 123 6/26/2025
0.1.0-alpha.185 123 6/26/2025
0.1.0-alpha.184 118 6/26/2025
0.1.0-alpha.183 115 6/26/2025
0.1.0-alpha.182 116 6/26/2025
0.1.0-alpha.181 123 6/25/2025
0.1.0-alpha.180 123 6/24/2025
0.1.0-alpha.179 122 6/23/2025
0.1.0-alpha.178 127 6/23/2025
0.1.0-alpha.176 127 6/23/2025
0.1.0-alpha.174 125 6/19/2025
0.1.0-alpha.173 126 6/19/2025
0.1.0-alpha.172 126 6/17/2025
0.1.0-alpha.171 124 6/16/2025
0.1.0-alpha.169 127 6/16/2025
0.1.0-alpha.165 232 6/13/2025
0.1.0-alpha.164 238 6/13/2025
0.1.0-alpha.163 236 6/13/2025