ManagedApplicationFixture<TEntryPoint> Class
Definition
- Namespace
- Codebelt.Extensions.Xunit.Hosting
- Assemblies
- Codebelt.Extensions.Xunit.Hosting.dll
Provides an entrypoint-owned implementation of the IApplicationFixture<TEntryPoint> interface.
public class ManagedApplicationFixture<TEntryPoint> : HostFixture, IAsyncLifetime, IApplicationFixture<TEntryPoint>, IHostFixture, IConfigurationTest, IEnvironmentTest, IDisposable, IAsyncDisposable where TEntryPoint : class
Type Parameters
TEntryPointA type in the entry point assembly of the application.
- Inheritance
-
ManagedApplicationFixture<TEntryPoint>
- Implements
-
IAsyncLifetimeIApplicationFixture<TEntryPoint>
- Inherited Members
- Extension Methods
Examples
Use ManagedApplicationFixture<TEntryPoint> when an xUnit class fixture should exercise the application's real entry point and let that entry point start the host. Derive the test from ApplicationTest<TEntryPoint,T> and pass the fixture to its base constructor so the base class initializes the fixture through ConfigureHost before the test reads Host. Fixture setup remains lazy; accessing the test host starts the deferred host and surfaces startup failures at the point the test consumes it. ApplicationTestFactory uses this fixture by default.
using Codebelt.Extensions.Xunit.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit;
namespace InventoryWorker.Tests;
public sealed class InventoryWorkerTest : ApplicationTest<WorkerProgram, ManagedApplicationFixture<WorkerProgram>>
{
public InventoryWorkerTest(ManagedApplicationFixture<WorkerProgram> fixture, ITestOutputHelper output)
: base(fixture, output)
{
}
[Fact]
public void Host_ContainsApplicationService()
{
var identity = Host.Services.GetRequiredService<WorkerIdentity>();
Assert.Equal("Inventory worker", identity.Name);
}
}
public sealed record WorkerIdentity(string Name);
public sealed class WorkerProgram
{
public static void Main(string[] args)
{
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSingleton(new WorkerIdentity("Inventory worker"));
using var host = builder.Build();
host.Run();
}
}
Remarks
The application's Main method owns host startup. The fixture captures the host after it has been built without starting it during fixture setup; the test host starts the deferred host when it is consumed.
Constructors
| Name | Description |
|---|---|
| ManagedApplicationFixture() | Initializes a new instance of the ManagedApplicationFixture<TEntryPoint> class. |
Properties
| Name | Description |
|---|---|
| ConfigureHostCallback | Gets or sets the delegate that provides a way to override the IHostBuilder before the application is built. |
Methods
| Name | Description |
|---|---|
| ConfigureHost(Test) | Creates and configures the IHost of this instance. |