Table of Contents

ManagedMinimalHostFixture Class

Definition

Namespace
Codebelt.Extensions.Xunit.Hosting
Assemblies
Codebelt.Extensions.Xunit.Hosting.dll
Source
src/Codebelt.Extensions.Xunit.Hosting/ManagedMinimalHostFixture.cs

Provides a default implementation of the IMinimalHostFixture interface.

public class ManagedMinimalHostFixture : HostFixture, IAsyncLifetime, IMinimalHostFixture, IHostFixture, IConfigurationTest, IEnvironmentTest, IDisposable, IAsyncDisposable
Inheritance
ManagedMinimalHostFixture
Implements
IAsyncLifetime
Derived
Inherited Members
Extension Methods

Examples

The following example uses ManagedMinimalHostFixture as the fixture type for a minimal host test class. The fixture automatically starts the minimal host and makes it available for the test duration, then disposes it. This is ideal for lean test scenarios that do not need the full generic host.

using Codebelt.Extensions.Xunit.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit;

namespace HostFixtureTests;

public class MinimalWorkerTest : MinimalHostTest<ManagedMinimalHostFixture>
{
    public MinimalWorkerTest(ManagedMinimalHostFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output)
    {
    }

    protected override void ConfigureHost(IHostApplicationBuilder hb)
    {
        hb.Services.AddSingleton<MetricsTracker>();
        hb.Services.AddXunitTestLogging();
    }

    [Fact]
    public void Host_ShouldNotBeNull()
    {
        Assert.NotNull(Host);
    }
}

public class MetricsTracker;

Remarks

This is the "modern" minimal style implementation of ManagedHostFixture.

Constructors

Name Description
ManagedMinimalHostFixture()

Initializes a new instance of the ManagedMinimalHostFixture class.

Properties

Name Description
ConfigureHostCallback

Gets or sets the delegate that initializes the host application builder.

Methods

Name Description
ConfigureHost(Test)

Creates and configures the IHost of this instance.

See Also