ManagedWebMinimalHostFixture Class
Definition
- Namespace
- Codebelt.Extensions.Xunit.Hosting.AspNetCore
- Assemblies
- 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
| Name | Description |
|---|---|
| ManagedWebMinimalHostFixture() | Initializes a new instance of the ManagedWebMinimalHostFixture class. |
Properties
| Name | Description |
|---|---|
| Application | Gets the IApplicationBuilder initialized by the IHost. |
| ConfigureApplicationCallback | Gets or sets the delegate that configures the HTTP request pipeline. |
Methods
| Name | Description |
|---|---|
| ConfigureHost(Test) | Creates and configures the IHost of this instance. |