MintPlayer.Spark.Testing
10.0.0-preview.39
dotnet add package MintPlayer.Spark.Testing --version 10.0.0-preview.39
NuGet\Install-Package MintPlayer.Spark.Testing -Version 10.0.0-preview.39
<PackageReference Include="MintPlayer.Spark.Testing" Version="10.0.0-preview.39" />
<PackageVersion Include="MintPlayer.Spark.Testing" Version="10.0.0-preview.39" />
<PackageReference Include="MintPlayer.Spark.Testing" />
paket add MintPlayer.Spark.Testing --version 10.0.0-preview.39
#r "nuget: MintPlayer.Spark.Testing, 10.0.0-preview.39"
#:package MintPlayer.Spark.Testing@10.0.0-preview.39
#addin nuget:?package=MintPlayer.Spark.Testing&version=10.0.0-preview.39&prerelease
#tool nuget:?package=MintPlayer.Spark.Testing&version=10.0.0-preview.39&prerelease
MintPlayer.Spark.Testing
Test-utilities library for writing automated tests against Spark apps. It provides an embedded RavenDB driver, an in-memory Spark host factory, antiforgery-aware HTTP helpers, JSON fixture seeding, index helpers, and Verify snapshot defaults.
This is a test-utilities library, not a test project — it references xUnit for the
IAsyncLifetimetype but contains no[Fact]s (IsTestProject=false). Add it to your own xUnit test project as a<PackageReference>. It is xUnit-based and pulls inRavenDB.TestDriver(which bundles an embedded RavenDB server) andVerify.Xunit, so treat it as a batteries-included integration-test harness.
What's in the box
| Type | Purpose |
|---|---|
SparkTestDriver |
xUnit base class that spins up an in-memory RavenDB instance per test class and exposes a ready IDocumentStore Store. |
SparkEndpointFactory<TContext> |
Boots a minimal in-memory Spark HTTP host (ASP.NET Core TestServer) wired to a supplied store, for endpoint/integration tests. |
SparkTestClient |
HttpClient wrapper that attaches the antiforgery cookie + X-XSRF-TOKEN header to every mutating request. |
JsonFixtureImporter |
Seeds a store from RavenDB query-result-format JSON fixture files. |
RavenIndexHelper |
Deploys indexes and waits for them to become non-stale (usable from any store-holding fixture). |
VerifyDefaults |
Centralizes Verify snapshot path configuration (auto-initialized via a module initializer). |
Setup
1. Reference the project
<ItemGroup>
<ProjectReference Include="..\MintPlayer.Spark.Testing\MintPlayer.Spark.Testing.csproj" />
</ItemGroup>
2. Provide a RavenDB license
RavenDB 7.x requires a license even for the embedded TestDriver. SparkTestDriver loads one from, in order:
- The
RAVENDB_LICENSEenvironment variable (JSON content — CI-friendly). - A
raven-license.logfile at the repository root (local development).
If neither is present, tests fail at initialization with a clear message. See ravendb.net/buy for community/developer licenses.
Usage
Data-layer tests — SparkTestDriver
Derive from SparkTestDriver to get a per-class embedded store. Override IndexAssemblies to auto-deploy and wait on indexes before the first test runs.
public class PersonQueryTests : SparkTestDriver
{
// Indexes in this assembly are deployed and awaited during InitializeAsync.
protected override IEnumerable<Assembly> IndexAssemblies => [typeof(People_ByName).Assembly];
[Fact]
public async Task Finds_people_by_name()
{
await SeedFromJsonAsync("Data/Seed/people.json"); // resolves against the test output dir
using var session = Store.OpenAsyncSession();
var matches = await session.Query<Person, People_ByName>()
.Where(p => p.Name == "Ada")
.ToListAsync();
matches.Should().ContainSingle();
}
}
Copy fixtures to the output directory so the relative path resolves:
<ItemGroup>
<Content Include="Data\**\*"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>
</ItemGroup>
Endpoint/integration tests — SparkEndpointFactory<TContext>
Boots a real Spark middleware pipeline over TestServer, against a store you supply (typically Store from a SparkTestDriver). It writes the supplied model definitions into a per-test temp content root, so ModelLoader sees exactly the entity types your fixture declares.
public class CarEndpointTests : SparkTestDriver
{
[Fact]
public async Task Create_then_get_round_trips()
{
await using var factory = new SparkEndpointFactory<FleetContext>(
testStore: Store,
models: FleetModels.All,
configureServices: services =>
{
// Optional: register custom Actions, swap IAccessControl for authz tests, etc.
});
// Antiforgery-aware client: warms up to mint the XSRF token, then attaches it to writes.
using var client = await factory.CreateAuthorizedClientAsync();
var create = await client.PostJsonAsync("/spark/po/Car", new { Brand = "Tesla" });
create.EnsureSuccessStatusCode();
var list = await client.GetAsync("/spark/po/Car");
list.EnsureSuccessStatusCode();
}
}
By default the factory opts into
AllowAnonymousAccess()so endpoint logic can be tested under an "everyone-can" baseline (the framework default is deny-all). Tests that exercise authorization should register their ownIAccessControlviaconfigureServices.
TestServer's HttpClient does not manage cookies automatically, which is why mutating requests need the antiforgery cookie + token threaded through explicitly. SparkTestClient (via CreateAuthorizedClientAsync) does this for you; if you need the raw values, call factory.MintAntiforgeryAsync().
Snapshot tests — VerifyDefaults
The module initializer configures Verify automatically, so snapshots land under VerifyResults/{TestClass}/{TestMethod}.verified.*. No per-test setup needed; just await Verify(result).
Related
- CronosCore RavenDB test helper — complementary JSON-seeding + Verify infrastructure standardized across MintPlayer repos.
- HTTP API Specification — the endpoints the
SparkEndpointFactoryhost exposes.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.AspNetCore.TestHost (>= 10.0.0)
- MintPlayer.Spark (>= 10.0.0-preview.39)
- MintPlayer.Spark.Abstractions (>= 10.0.0-preview.39)
- Newtonsoft.Json (>= 13.0.4)
- RavenDB.TestDriver (>= 7.2.0)
- Verify.Xunit (>= 28.6.1)
- xunit (>= 2.9.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.0-preview.39 | 0 | 6/9/2026 |
| 10.0.0-preview.38 | 0 | 6/9/2026 |
| 10.0.0-preview.35 | 35 | 6/7/2026 |
| 10.0.0-preview.34 | 49 | 6/6/2026 |