Skip to content
Purview Dev logo

ResourceKit is designed to be test-friendly: resource composition is split into focused classes, and generated options give you a typed way to override names and enablement from tests.

The repository uses TUnit with the TUnit.Aspire integration. Test projects live under src/tests:

  • ResourceKit.UnitTests — runtime behavior of the kit base types, run modes and OptionsHelper.
  • ResourceKit.IntegrationTests — starts the example AppHosts and asserts against real resources.
  • SourceGeneration.UnitTests / SourceGeneration.IntegrationTests — generator output, diagnostics, suppression, code fixes, and caching.
  • Repository.UnitTests — the repository itself: authored skills, the architecture policy, and the Purview.BuildSdk feature opt-ins.
  • SharedTestingInfra — a shared-testing library, referenced rather than executed.

Reports are written to TestResults/.

Create an AspireFixture<TAppHost> for the AppHost under test:

using TUnit.Aspire;
namespace Purview.Aspire.ResourceKit.Fixtures;
public sealed class ExampleAppHostFixture<TAppHost> : AspireFixture<TAppHost>
where TAppHost : class;

Then drive it from a TUnit test class:

using Projects;
[ClassDataSource<ExampleAppHostFixture<Example_AppHost>>(Shared = SharedType.PerTestSession)]
public sealed class ExampleAppHostIntegrationTests(ExampleAppHostFixture<Example_AppHost> fixture)
{
[Test]
public async Task AppHost_WhenServicesStarted_APIIsHealthy(CancellationToken cancellationToken)
{
// Arrange
// The fixture is a running AppHost, started once for the test session by TUnit.Aspire.
// Act
await fixture.APIIsHealthyAsync(cancellationToken);
// Assert
// APIIsHealthyAsync asserts the API resource's /health endpoint answered 200 OK.
}
}

TUnit.Aspire wires the AppHost lifecycle (start/stop) around the fixture. The example API exposes a /health endpoint for this purpose. The assertion lives in the fixture extension so every AppHost suite proves the same thing; see src/tests/ResourceKit.IntegrationTests/Extensions/TUnit/Aspire/AspireFixtureExtensions.cs.

The generated extension method binds host options from configuration, so you can pass command-line arguments through the fixture to toggle resources. OptionsHelper generates these arguments from strongly typed assignments:

using TUnit.Aspire;
public sealed class CustomOptionsExampleAppHostFixture : AspireFixture<Projects.Example_AppHost>
{
public const string AzureStorageName = "custom-options-azure-storage-example";
protected override string[] Args =>
[
"--ExampleHostKit:Redis:IsEnabled=false",
$"--ExampleHostKit:AzureStorage:Name={AzureStorageName}",
];
}

The test then asserts the options took effect — Redis is disabled (no connection string), and Azure Storage is registered under the custom name:

[Test]
public async Task AppHost_WithCustomOptions_IsPassedToTheHostKit(CancellationToken cancellationToken)
{
// Arrange
// CustomOptionsExampleAppHostFixture starts the AppHost with the options below as command-line
// arguments, so ResourceKit should bind the Azure Storage name it is given and disable Redis.
// Act
await fixture.ConnectionStringIsUnavailableAsync(Platform.ResourceKits.Redis, cancellationToken);
// Assert
await Assert
.That(fixture.GetResourceSnapshot(CustomOptionsExampleAppHostFixture.AzureStorageName))
.IsNotNull()
.Because("The custom Azure Storage name should be passed to the host kit.");
await Assert
.That(fixture.GetResourceSnapshot(Platform.ResourceKits.AzureStorage))
.IsNull()
.Because("The default Azure Storage name should not be passed to the host kit.");
}

Prefer OptionsHelper.Assign<TOptions>(...) for typed, refactor-safe args:

protected override string[] Args =>
[
.. base.Args,
.. OptionsHelper.Assign<ExampleHostKit.ExampleHostKitOptions>(
c => c.Redis.IsEnabled = false,
c => c.AzureStorage.Name = "custom-options-azure-storage-example"
).Build(),
];

Child options use the nested path, so the same helper works at any depth:

OptionsHelper.Assign<ExampleHostKit.ExampleHostKitOptions>(
static o => o.Postgres.Database.IsEnabled = false).Build();

See Parent and child resource kits for the configuration shape.

ResourceKit.UnitTests builds real Aspire models for a PostgreSQL server/database, a VNET with several subnets, storage account/container, and a Service Bus namespace/topic/queue/subscription. Those tests assert resource creation through Parent.ResourceBuilder, plus inherited enablement and graph validation, without starting the AppHost or provisioning infrastructure. The example AppHost tests inspect the generated hierarchy model and its nested configuration paths.

See OptionsHelper for Assign, AsEnvironmentVariables, and the SG0020 single-property-path rule.

If you already have a populated options object, use OptionsHelper.Environment(...) to flatten it into configuration-style environment variables and selectively override or ignore members before emission.

The manual host pattern (see Examples) composes ResourceKitBase<THostKit, TResource> without generation, which makes the lifecycle directly unit-testable: instantiate a kit, call Build(builder)/Configure(), and assert on ResourceBuilder and option-driven behavior.

Unit tests are filtered with the TUnit tree-node filter:

Terminal window
just test "/*/*/*/*[Category=Unit]"

Integration tests (which require Docker/Testcontainers) run locally:

Terminal window
just test

See Contributing and Release Flow for the CI filter and local workflow.