QueryGuard.Testing
0.1.0-preview.1
Prefix Reserved
See the version list below for details.
dotnet add package QueryGuard.Testing --version 0.1.0-preview.1
NuGet\Install-Package QueryGuard.Testing -Version 0.1.0-preview.1
<PackageReference Include="QueryGuard.Testing" Version="0.1.0-preview.1" />
<PackageVersion Include="QueryGuard.Testing" Version="0.1.0-preview.1" />
<PackageReference Include="QueryGuard.Testing" />
paket add QueryGuard.Testing --version 0.1.0-preview.1
#r "nuget: QueryGuard.Testing, 0.1.0-preview.1"
#:package QueryGuard.Testing@0.1.0-preview.1
#addin nuget:?package=QueryGuard.Testing&version=0.1.0-preview.1&prerelease
#tool nuget:?package=QueryGuard.Testing&version=0.1.0-preview.1&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.
[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());
}
The scope and the interceptor must share an accessor
The example above relies on both using QueryGuardScope.DefaultAccessor. If your interceptor came from
a dependency injection container, pass that container's accessor to the scope instead:
accessor: services.GetRequiredService<IQueryGuardSessionAccessor>()
Get this wrong and the scope completes with zero commands, so every count assertion fails for a reason
unrelated to the code under test. With WebApplicationFactory there is a second trap —
TestServer does not flow ExecutionContext into requests unless asked, and QueryGuard finds the
active session through AsyncLocal. Both are covered in
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.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- QueryGuard.Core (>= 0.1.0-preview.1)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- QueryGuard.Core (>= 0.1.0-preview.1)
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 |