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
-
ObjectHostTest<T>
- Implements
-
IDisposableIClassFixture<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
TAn implementation of the IHostFixture interface.
output
ITestOutputHelperAn implementation of the Xunit.Abstractions.ITestOutputHelper interface.
callerType
TypeThe 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
IConfigurationThe Microsoft.Extensions.Configuration.IConfiguration initialized by the Microsoft.Extensions.Hosting.IHost.
environment
IHostEnvironmentThe 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
IHostBuilderThe 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
IServiceCollectionThe collection of service descriptors.
InitializeHostFixture(T)
Initializes the specified host fixture.
protected virtual void InitializeHostFixture(T hostFixture)
Parameters
hostFixture
TThe host fixture to initialize.