agentleFS
LeanMeanCleanAppsLeanMeanCleanApps/CleanLambdaFunction/.agents/skills/presentation-integration-tests/SKILL.md

presentation-integration-tests

Skill0 starsChanged 10 days agoMITView on GitHub

How this Lambda function is tested end to end - calling Handler methods with a TestLambdaContext, services from Startup with a private in-memory database per test class, the generated handler classes, the HTTP API functions, and asserting exceptions. Use when writing or fixing a test in tests/Presentation.Tests.Integration.

4 other projects use a version of this, 2 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use the class's handler and context fields.

    line 30
  2. Very specific:

    Call the function, then assert the result: counts, NextOffset, and that every item matches the filter.

    line 31
  3. Very specific:

    Write one test per success and per failure the function can return (test-design).

    line 36
  4. Distinctive:

    Leave an environment variable set after a test.

    line 64

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Presentation integration tests (Lambda function)

The rule

tests/Presentation.Tests.Integration tests the whole function in memory by calling Handler methods the way Lambda does. Each test class creates one Handler from the services Startup registers, with its own shared-cache in-memory SQLite database and the sample data on, and a TestLambdaContext (from Amazon.Lambda.TestUtilities) with time remaining.

FileTests
HandlerTests.csEvery function's results, paging, search and filters, the validation failures, and how the handler reads its settings
HttpApiTests.csThe Http* functions: the 200 page, each 400 with its problem details and content type, and the generated classes binding an APIGatewayHttpApiV2ProxyRequest query string

The serializer is tested on its own in tests/Presentation.Tests.Unit (unit-tests, json-serialization).

There are two ways in, and tests use whichever the case needs:

Way inUse it to
CreateHandler(settings)Most tests. It builds new Startup(settings) with scope validation on and resolves Handler, so settings such as ConnectionStrings:MovieReviews and Database:SeedSampleData override the environment
new Handler_<Method>_Generated()The environment variable test, which calls each generated class exactly as Lambda does, then clears the variables

Steps

  1. Use the class's handler and context fields. Create a second handler with CreateHandler only when the test needs other settings.
  2. Call the function, then assert the result: counts, NextOffset, and that every item matches the filter.
  3. Failures: await Should.ThrowAsync<ValidationException>(...) and check the property name in the errors, or NotFoundException and its message.
  4. Find the rows you need through another function (list, then pick one), not by hard-coded ids. Sample data ids are random.
  5. For an Http* function, turn the IHttpResult into the API Gateway response with Read, then read the body with Body<T>. Check the content type with ContentType, which reads the raw JSON: Lambda Annotations writes header names in lower case and the SDK's response type doesn't read them back.
  6. A test that sets environment variables clears them in finally.
  7. Write one test per success and per failure the function can return (test-design).

Example

// tests/Presentation.Tests.Integration/HandlerTests.cs
private readonly Handler handler = CreateHandler(new()
{
    ["ConnectionStrings:MovieReviews"] = InMemoryDatabase(),
    ["Database:SeedSampleData"] = "true"
});
private readonly TestLambdaContext context = new() { RemainingTime = TimeSpan.FromSeconds(30) };

[Fact]
public async Task GetMovies_ShouldThrow_WhenLimitIsNotValid()
{
    // Act
    var exception = await Should.ThrowAsync<ValidationException>(() => this.handler.GetMovies(new ListRequest { Limit = 0 }, this.context));

    // Assert
    exception.Errors.ShouldContain(e => e.PropertyName == "Limit" && e.ErrorMessage == "A limit must be between 1 and 50.");
}

Don't

  • Share a Handler across test classes or in a static field. Each class gets its own database.
  • Point a test at /tmp/movie-reviews.db or any file.
  • Leave an environment variable set after a test.
  • Depend on the order rows come back in unless the function promises one.

Check

dotnet test tests/Presentation.Tests.Integration

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.