MintPlayer.Spark.Testing 10.0.0-preview.39

This is a prerelease version of MintPlayer.Spark.Testing.
dotnet add package MintPlayer.Spark.Testing --version 10.0.0-preview.39
                    
NuGet\Install-Package MintPlayer.Spark.Testing -Version 10.0.0-preview.39
                    
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="MintPlayer.Spark.Testing" Version="10.0.0-preview.39" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MintPlayer.Spark.Testing" Version="10.0.0-preview.39" />
                    
Directory.Packages.props
<PackageReference Include="MintPlayer.Spark.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 MintPlayer.Spark.Testing --version 10.0.0-preview.39
                    
#r "nuget: MintPlayer.Spark.Testing, 10.0.0-preview.39"
                    
#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 MintPlayer.Spark.Testing@10.0.0-preview.39
                    
#: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=MintPlayer.Spark.Testing&version=10.0.0-preview.39&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MintPlayer.Spark.Testing&version=10.0.0-preview.39&prerelease
                    
Install as a Cake Tool

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 IAsyncLifetime type but contains no [Fact]s (IsTestProject=false). Add it to your own xUnit test project as a <PackageReference>. It is xUnit-based and pulls in RavenDB.TestDriver (which bundles an embedded RavenDB server) and Verify.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:

  1. The RAVENDB_LICENSE environment variable (JSON content — CI-friendly).
  2. A raven-license.log file 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 own IAccessControl via configureServices.

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).

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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