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

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.273
                    
NuGet\Install-Package Siemens.AspNet.Lambda.MsTest.Sdk -Version 0.1.0-alpha.273
                    
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.273" />
                    
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.273" />
                    
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.273
                    
#r "nuget: Siemens.AspNet.Lambda.MsTest.Sdk, 0.1.0-alpha.273"
                    
#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.273
                    
#: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.273&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Siemens.AspNet.Lambda.MsTest.Sdk&version=0.1.0-alpha.273&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.275 130 9/3/2025
0.1.0-alpha.274 208 9/2/2025
0.1.0-alpha.273 193 9/1/2025
0.1.0-alpha.272 111 9/1/2025
0.1.0-alpha.271 161 8/29/2025
0.1.0-alpha.270 150 8/29/2025
0.1.0-alpha.269 146 8/29/2025
0.1.0-alpha.268 155 8/29/2025
0.1.0-alpha.267 160 8/27/2025
0.1.0-alpha.266 161 8/27/2025
0.1.0-alpha.264 241 8/22/2025
0.1.0-alpha.263 66 8/22/2025
0.1.0-alpha.262 70 8/22/2025
0.1.0-alpha.261 83 8/22/2025
0.1.0-alpha.260 91 8/22/2025
0.1.0-alpha.259 94 8/22/2025
0.1.0-alpha.258 183 8/19/2025
0.1.0-alpha.257 189 8/18/2025
0.1.0-alpha.246 139 8/14/2025
0.1.0-alpha.245 116 8/14/2025
0.1.0-alpha.244 135 8/14/2025
0.1.0-alpha.243 115 8/14/2025
0.1.0-alpha.238 121 8/12/2025
0.1.0-alpha.237 382 8/6/2025
0.1.0-alpha.236 193 8/5/2025
0.1.0-alpha.235 196 8/5/2025
0.1.0-alpha.234 228 8/5/2025
0.1.0-alpha.233 161 8/4/2025
0.1.0-alpha.232 174 8/4/2025
0.1.0-alpha.231 71 8/1/2025
0.1.0-alpha.230 73 8/1/2025
0.1.0-alpha.229 91 7/31/2025
0.1.0-alpha.228 91 7/31/2025
0.1.0-alpha.227 92 7/31/2025
0.1.0-alpha.225 91 7/31/2025
0.1.0-alpha.224 93 7/30/2025
0.1.0-alpha.222 223 7/16/2025
0.1.0-alpha.219 159 7/14/2025
0.1.0-alpha.217 82 7/11/2025
0.1.0-alpha.212 156 7/8/2025
0.1.0-alpha.211 125 7/3/2025
0.1.0-alpha.207 116 7/3/2025
0.1.0-alpha.206 234 6/30/2025
0.1.0-alpha.205 99 6/27/2025
0.1.0-alpha.202 97 6/27/2025
0.1.0-alpha.200 97 6/27/2025
0.1.0-alpha.198 95 6/27/2025
0.1.0-alpha.196 102 6/27/2025
0.1.0-alpha.195 98 6/27/2025
0.1.0-alpha.194 94 6/27/2025
0.1.0-alpha.193 96 6/27/2025
0.1.0-alpha.192 96 6/27/2025
0.1.0-alpha.191 96 6/27/2025
0.1.0-alpha.189 117 6/26/2025
0.1.0-alpha.188 115 6/26/2025
0.1.0-alpha.187 112 6/26/2025
0.1.0-alpha.186 119 6/26/2025
0.1.0-alpha.185 120 6/26/2025
0.1.0-alpha.184 114 6/26/2025
0.1.0-alpha.183 112 6/26/2025
0.1.0-alpha.182 114 6/26/2025
0.1.0-alpha.181 118 6/25/2025
0.1.0-alpha.180 119 6/24/2025
0.1.0-alpha.179 120 6/23/2025
0.1.0-alpha.178 124 6/23/2025
0.1.0-alpha.176 121 6/23/2025
0.1.0-alpha.174 122 6/19/2025
0.1.0-alpha.173 122 6/19/2025
0.1.0-alpha.172 123 6/17/2025
0.1.0-alpha.171 120 6/16/2025
0.1.0-alpha.169 122 6/16/2025
0.1.0-alpha.165 230 6/13/2025
0.1.0-alpha.164 235 6/13/2025
0.1.0-alpha.163 233 6/13/2025