QueryGuard.Testing 0.1.0-preview.6

Prefix Reserved
This is a prerelease version of QueryGuard.Testing.
There is a newer version of this package available.
See the version list below for details.
dotnet add package QueryGuard.Testing --version 0.1.0-preview.6
                    
NuGet\Install-Package QueryGuard.Testing -Version 0.1.0-preview.6
                    
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="QueryGuard.Testing" Version="0.1.0-preview.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QueryGuard.Testing" Version="0.1.0-preview.6" />
                    
Directory.Packages.props
<PackageReference Include="QueryGuard.Testing" />
                    
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 QueryGuard.Testing --version 0.1.0-preview.6
                    
#r "nuget: QueryGuard.Testing, 0.1.0-preview.6"
                    
#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 QueryGuard.Testing@0.1.0-preview.6
                    
#: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=QueryGuard.Testing&version=0.1.0-preview.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=QueryGuard.Testing&version=0.1.0-preview.6&prerelease
                    
Install as a Cake Tool

QueryGuard.Testing

Turn database behaviour into an assertion. Open a QueryGuard.NET scope around the code under test and check that its query budget held.

Two lines of setup. Attach QueryGuard where the context is configured:

options.UseSqlite(connectionString).UseQueryGuard();

Then measure:

[Fact]
public async Task Companies_endpoint_stays_within_its_query_budget()
{
    await using var scope = QueryGuardScope.Start(
        "GET /api/companies",
        QueryGuardPolicy.Create("companies")
            .WithMaxQueries(3)
            .WithMaxOccurrencesPerFingerprint(1));

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

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

No interceptor to construct and no accessor to match up: UseQueryGuard() and QueryGuardScope.Start default to the same ambient accessor, so they are wired to each other. Calling UseQueryGuard() twice is a no-op rather than a double count.

Outside a scope, nothing is captured, so leaving the call in place costs about a nanosecond per command and no allocation.

When you do need to pass an accessor

Only when the interceptor came from a dependency injection container, in which case hand the scope that container's accessor:

accessor: services.GetRequiredService<IQueryGuardSessionAccessor>()

With WebApplicationFactory there is one more thing to know: TestServer does not flow ExecutionContext into requests unless asked, and QueryGuard finds the active session through AsyncLocal. See troubleshooting.

No test framework dependency

This package references no test framework. QueryGuardAssert throws QueryGuardBudgetExceededException, and every test framework reports an unexpected exception with its message, so xUnit, NUnit, MSTest, and TUnit all work unchanged, and installing this package does not drag a framework into your project.

Because there is no framework-native formatting to lean on, the exception message carries the evidence: the policy, expected against actual, the top repeated fingerprint with its redacted SQL, any ignored findings, and where to read about false positives. See ADR-0010.

Prefer your own assertions? CompleteAsync returns the QueryGuardResult; assert on it however you like.

Preview

Public APIs may change before 1.0.0. See the changelog.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on QueryGuard.Testing:

Package Downloads
QueryGuard.AspNetCore.Testing

Measure EF Core queries from WebApplicationFactory tests with one setup call. Preserves the test execution context, disables request middleware, and wires the matching session accessor.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 47 8/21/2026
0.1.0-preview.6 52 8/21/2026
0.1.0-preview.5 47 8/21/2026
0.1.0-preview.4 43 8/20/2026
0.1.0-preview.3 44 8/20/2026
0.1.0-preview.2 37 8/20/2026
0.1.0-preview.1 44 8/20/2026