Soenneker.Tests.HostedUnit 11.0.388

Prefix Reserved
dotnet add package Soenneker.Tests.HostedUnit --version 11.0.388
                    
NuGet\Install-Package Soenneker.Tests.HostedUnit -Version 11.0.388
                    
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="Soenneker.Tests.HostedUnit" Version="11.0.388" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Tests.HostedUnit" Version="11.0.388" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Tests.HostedUnit" />
                    
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 Soenneker.Tests.HostedUnit --version 11.0.388
                    
#r "nuget: Soenneker.Tests.HostedUnit, 11.0.388"
                    
#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 Soenneker.Tests.HostedUnit@11.0.388
                    
#: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=Soenneker.Tests.HostedUnit&version=11.0.388
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Tests.HostedUnit&version=11.0.388
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Tests.HostedUnit

A TUnit base class for tests that resolve services from a shared UnitTestHost while owning a per-test dependency-injection scope.

Installation

dotnet add package Soenneker.Tests.HostedUnit

Define the host

using Microsoft.Extensions.DependencyInjection;
using Soenneker.TestHosts.Unit;

public sealed class Host : UnitTestHost
{
    public override Task InitializeAsync()
    {
        Services.AddSingleton<IClock, TestClock>();
        Services.AddScoped<OrderService>();

        return base.InitializeAsync();
    }
}

Define the tests

using Soenneker.Tests.HostedUnit;

[ClassDataSource<Host>(Shared = SharedType.PerTestSession)]
public sealed class OrderServiceTests : HostedUnitTest
{
    public OrderServiceTests(Host host) : base(host)
    {
    }

    [Test]
    public async Task Creates_an_order()
    {
        OrderService service = Resolve<OrderService>(scoped: true);
        CreateOrder request = AutoFaker.Generate<CreateOrder>();

        Order result = await service.Create(request);

        await Assert.That(result.Id).IsNotEqualTo(Guid.Empty);
    }
}

Resolve<T>() resolves from the shared host's root provider. Resolve<T>(scoped: true) lazily creates one async scope for the test instance, reuses it for subsequent scoped resolutions, and disposes it after the test. CreateScope() can establish that scope explicitly and is idempotent while it exists.

The base class reuses the host's AutoFaker. Its Logger is resolved through the test scope, so log output follows the logging services configured by the host.

Background work

If the host registers IBackgroundQueue, WaitOnQueueToEmpty(cancellationToken) waits for its queued work to finish before assertions or teardown continue. Supply a bounded cancellation token so a stuck producer cannot hang the test run. Accessing this method without an IBackgroundQueue registration fails service resolution.

The ClassDataSource should be shared so TUnit initializes and disposes the host once while each test instance still owns and disposes its own scope.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Tests.HostedUnit:

Package Downloads
Soenneker.Playwrights.Tests.Unit

A fixtured unit test for testing with Playwright

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.388 0 11/18/2026
11.0.387 0 11/18/2026
11.0.384 0 11/18/2026
11.0.383 0 11/18/2026
11.0.382 0 11/18/2026
11.0.381 0 11/18/2026
11.0.380 1,956 11/17/2026
11.0.379 400 11/17/2026
11.0.378 1,700 11/17/2026
11.0.377 5,459 11/15/2026
11.0.376 6,189 11/13/2026
11.0.375 134 11/13/2026
11.0.374 3,137 11/11/2026
11.0.372 991 11/11/2026
11.0.370 829 11/11/2026
11.0.369 869 11/11/2026
11.0.368 1,645 11/11/2026
11.0.367 1,174 11/11/2026
11.0.366 985 11/11/2026
11.0.365 2,109 11/11/2026
Loading failed