Table of Contents

Class HostTest<T>

Namespace
Cuemon.Extensions.Xunit.Hosting
Assembly
Cuemon.Extensions.Xunit.Hosting.dll

Represents a base class from which all implementations of unit testing, that uses Microsoft Dependency Injection, should derive.

public abstract class HostTest<T> : Test, ITest, IDisposable, IClassFixture<T> where T : class, IHostFixture

Type Parameters

T

The type of the object that implements the IHostFixture interface.

Inheritance
Object
HostTest<T>
Implements
IDisposable
IClassFixture<T>
Derived
Inherited Members

Remarks

The class needed to be designed in this rather complex way, as this is the only way that xUnit supports a shared context. The need for shared context is theoretical at best, but it does opt-in for Scoped instances.

Constructors

HostTest(T, ITestOutputHelper, Type)

Initializes a new instance of the HostTest<T> class.

protected HostTest(T hostFixture, ITestOutputHelper output = null, Type callerType = null)

Parameters

hostFixture T

An implementation of the IHostFixture interface.

output ITestOutputHelper

An implementation of the Xunit.Abstractions.ITestOutputHelper interface.

callerType Type

The System.Type of caller that ends up invoking this instance.

Properties

Configuration

Gets the Microsoft.Extensions.Configuration.IConfiguration initialized by the Microsoft.Extensions.Hosting.IHost.

public IConfiguration Configuration { get; }

Property Value

IConfiguration

The Microsoft.Extensions.Configuration.IConfiguration initialized by the Microsoft.Extensions.Hosting.IHost.

Host

Gets the Microsoft.Extensions.Hosting.IHost initialized by the IHostFixture.

public IHost Host { get; protected set; }

Property Value

IHost

The Microsoft.Extensions.Hosting.IHost initialized by the IHostFixture.

HostingEnvironment

Gets the Microsoft.Extensions.Hosting.IHostEnvironment initialized by the Microsoft.Extensions.Hosting.IHost.

public IHostEnvironment HostingEnvironment { get; }

Property Value

IHostEnvironment

The Microsoft.Extensions.Hosting.IHostEnvironment initialized by the Microsoft.Extensions.Hosting.IHost.

ServiceProvider

Gets the System.IServiceProvider initialized by the Microsoft.Extensions.Hosting.IHost.

public IServiceProvider ServiceProvider { get; protected set; }

Property Value

IServiceProvider

The System.IServiceProvider initialized by the Microsoft.Extensions.Hosting.IHost.

Methods

Configure(IConfiguration, IHostEnvironment)

Adds Configuration and HostingEnvironment to this instance.

public virtual void Configure(IConfiguration configuration, IHostEnvironment environment)

Parameters

configuration IConfiguration

The Microsoft.Extensions.Configuration.IConfiguration initialized by the Microsoft.Extensions.Hosting.IHost.

environment IHostEnvironment

The Microsoft.Extensions.Hosting.IHostEnvironment initialized by the Microsoft.Extensions.Hosting.IHost.

ConfigureHost(IHostBuilder)

Provides a way to override the Microsoft.Extensions.Hosting.IHostBuilder defaults set up by T.

protected virtual void ConfigureHost(IHostBuilder hb)

Parameters

hb IHostBuilder

The Microsoft.Extensions.Hosting.IHostBuilder that initializes an instance of Microsoft.Extensions.Hosting.IHost.

ConfigureServices(IServiceCollection)

Adds services to the container.

public abstract void ConfigureServices(IServiceCollection services)

Parameters

services IServiceCollection

The collection of service descriptors.

InitializeHostFixture(T)

Initializes the specified host fixture.

protected virtual void InitializeHostFixture(T hostFixture)

Parameters

hostFixture T

The host fixture to initialize.

See Also

Test
IClassFixture<TFixture>