QueryGuard.Testing
0.1.0-preview.6
Prefix Reserved
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
<PackageReference Include="QueryGuard.Testing" Version="0.1.0-preview.6" />
<PackageVersion Include="QueryGuard.Testing" Version="0.1.0-preview.6" />
<PackageReference Include="QueryGuard.Testing" />
paket add QueryGuard.Testing --version 0.1.0-preview.6
#r "nuget: QueryGuard.Testing, 0.1.0-preview.6"
#:package QueryGuard.Testing@0.1.0-preview.6
#addin nuget:?package=QueryGuard.Testing&version=0.1.0-preview.6&prerelease
#tool nuget:?package=QueryGuard.Testing&version=0.1.0-preview.6&prerelease
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 | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.0)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- QueryGuard.Core (>= 0.1.0-preview.6)
- QueryGuard.EntityFrameworkCore (>= 0.1.0-preview.6)
-
net8.0
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.1)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- QueryGuard.Core (>= 0.1.0-preview.6)
- QueryGuard.EntityFrameworkCore (>= 0.1.0-preview.6)
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 |