Table of Contents

Class QueryGuardScope

Namespace
QueryGuard.Testing
Assembly
QueryGuard.Testing.dll

A QueryGuard session opened explicitly, for use in a test or any code that is not an HTTP request.

public sealed class QueryGuardScope : IDisposable, IAsyncDisposable
Inheritance
QueryGuardScope
Implements
Inherited Members

Examples

await using var scope = QueryGuardScope.Start(
    "GET /api/companies",
    QueryGuardPolicy.Create("companies").WithMaxQueries(3));

var response = await client.GetAsync("/api/companies");

QueryGuardAssert.Passes(await scope.CompleteAsync());

Remarks

This is the surface most users touch, because the main intended use of QueryGuard is inside an integration test. Open a scope, exercise the code, complete the scope, assert on the result.

The scope is disposable both ways. DisposeAsync() completes the session if the caller did not, so a test that throws mid-way still releases the ambient session: otherwise the next test on the same execution flow would record into a session nobody is reading.

Properties

DefaultAccessor

Gets the default accessor, for wiring an interceptor when a test constructs one by hand.

Session

Gets the session this scope opened.

Methods

Complete()

Completes the session and analyzes it.

CompleteAsync(CancellationToken)

Completes the session and analyzes it.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

Start(string, QueryGuardPolicy?, IQueryGuardSessionAccessor?, IQueryGuardRedactor?, QueryGuardAnalyzer?, bool)

Opens a scope.