Table of Contents

Class ManagedWebMinimalHostFixture

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

Provides a default implementation of the IWebMinimalHostFixture interface.

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

Examples

The following example uses ManagedWebMinimalHostFixture as the fixture type for a minimal web host test class. The fixture starts and manages a minimal web host, giving the test access to a configured host and the ability to send HTTP requests through the ASP.NET Core pipeline.

using System.Threading.Tasks;
using Codebelt.Extensions.Xunit.Hosting.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit;

namespace WebFixtureTests;

public class MinimalApiTest : MinimalWebHostTest<ManagedWebMinimalHostFixture>
{
    public MinimalApiTest(ManagedWebMinimalHostFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output)
    {
    }

    protected override void ConfigureHost(IHostApplicationBuilder hb)
    {
        hb.Services.AddFakeHttpContextAccessor();
    }

    public override void ConfigureApplication(IApplicationBuilder app)
    {
        app.UseMiddleware<TestMiddleware>();
    }
}

internal class TestMiddleware
{
    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
    {
        await next(context);
    }
}

Remarks

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

Constructors

ManagedWebMinimalHostFixture()

Initializes a new instance of the ManagedWebMinimalHostFixture class.

public ManagedWebMinimalHostFixture()

Properties

Application

Gets the IApplicationBuilder initialized by the IHost.

public IApplicationBuilder Application { get; protected set; }

Property Value

IApplicationBuilder

The IApplicationBuilder initialized by the IHost.

ConfigureApplicationCallback

Gets or sets the delegate that configures the HTTP request pipeline.

public Action<IApplicationBuilder> ConfigureApplicationCallback { get; set; }

Property Value

Action<IApplicationBuilder>

The delegate that configures the HTTP request pipeline.

Methods

ConfigureHost(Test)

Creates and configures the IHost of this instance.

public override void ConfigureHost(Test hostTest)

Parameters

hostTest Test

The object that inherits from MinimalWebHostTest<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 MinimalWebHostTest<T>.

See Also