Table of Contents

Class ManagedMinimalHostFixture

Namespace
Codebelt.Extensions.Xunit.Hosting
Assembly
Codebelt.Extensions.Xunit.Hosting.dll

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

ManagedMinimalHostFixture()

Initializes a new instance of the ManagedMinimalHostFixture class.

public ManagedMinimalHostFixture()

Properties

ConfigureHostCallback

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

public Action<IHostApplicationBuilder> ConfigureHostCallback { get; set; }

Property Value

Action<IHostApplicationBuilder>

The delegate that initializes the host application builder.

Methods

ConfigureHost(Test)

Creates and configures the IHost of this instance.

public virtual void ConfigureHost(Test hostTest)

Parameters

hostTest Test

The object that inherits from MinimalHostTest<T>.

Remarks

hostTest was added to support those cases where the caller is required in the host configuration.

Exceptions

ArgumentNullException

hostTest is null.

ArgumentOutOfRangeException

hostTest is not assignable from MinimalHostTest<T>.

See Also