Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To include the Lambda Context when testing Lambda with AWS .NET Core 6.0 Mock Lambda Test Tool, you should follow these steps:

  1. Import the Amazon.Lambda.Core namespace in your test file.
  2. Create an instance of TestLambdaContext class and pass any desired values in its constructor (such as function name, request ID, and log group name).
  3. Call the Lambda function passing the input and the instance of TestLambdaContext as parameters.

Example:

using Amazon.Lambda.Core;
using Xunit;

namespace MyLambda.Tests
{
    public class MyLambdaTests
    {
        [Fact]
        public void TestLambda()
        {
            // Arrange
            var lambda = new MyLambda();
            var input = new MyInput { };
            var context = new TestLambdaContext { FunctionName = "my-function", RequestId = "123456", LogGroupName = "/aws/lambda/my-function" };

            // Act
            var result = lambda.FunctionHandler(input, context);

            // Assert
            Assert.NotNull(result);
            Assert.IsType<MyOutput>(result);
        }
    }
}