aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Add WebApplicationFactory for in-memory tests

Open Dreamescaper opened this issue 3 years ago • 3 comments

Issue #, if available: https://github.com/aws/aws-lambda-dotnet/issues/1151

Description of changes: I've created a type WebApplicationFactory, which parses serverless.template file, and creates HttpClient, which is able to invoke Http endpoints, defined in template file. It invokes handler functions directly, avoiding any network communications.

Inspired by WebApplicationFactory from AspNetCore.

You can take a look at ComplexCalculator.cs for the example of usage.

This PR is essentially a POC, to describe the idea, and discuss whether it makes sense to expand it further (e.g. add ability to replace services in the DI container).

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Dreamescaper avatar Apr 21 '22 21:04 Dreamescaper

@normj @ashishdhingra @ganeshnj Guys, what do you think? Is that something which would be appropriate for this repo? Does it make sense to work further on this thing?

Dreamescaper avatar Apr 21 '22 21:04 Dreamescaper

@Dreamescaper thanks for PR

I understand what the code does, but failing to understand the intent here. Is having a testable in-memory server intention here?

ganeshnj avatar May 12 '22 23:05 ganeshnj

@ganeshnj Basically yes. I want to be able to write tests in a similar way I would do with WebApplicationFactory for AspNetCore. https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-6.0

Dreamescaper avatar May 13 '22 08:05 Dreamescaper