Class HostTest<T>
- Namespace
- Codebelt.Extensions.Xunit.Hosting
- Assembly
- Codebelt.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> : HostTest, IAsyncLifetime, IHostTest, IConfigurationTest, IEnvironmentTest, ITest, IDisposable, IAsyncDisposable, IClassFixture<T> where T : class, IGenericHostFixture
Type Parameters
T
The type of the object that implements the IGenericHostFixture interface.
- Inheritance
-
HostTest<T>
- Implements
-
IAsyncLifetimeIClassFixture<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 IGenericHostFixture interface.
output
ITestOutputHelperAn implementation of the Xunit.Abstractions.ITestOutputHelper interface.
callerType
TypeThe Type of caller that ends up invoking this instance.
Exceptions
- ArgumentNullException
hostFixture
is null.
HostTest(Boolean, T, ITestOutputHelper, Type)
Initializes a new instance of the HostTest<T> class.
protected HostTest(bool skipHostFixtureInitialization, T hostFixture, ITestOutputHelper output = null, Type callerType = null)
Parameters
skipHostFixtureInitialization
BooleanA value indicating whether to skip the host fixture initialization.
hostFixture
TAn implementation of the IGenericHostFixture interface.
output
ITestOutputHelperAn implementation of the Xunit.Abstractions.ITestOutputHelper interface.
callerType
TypeThe Type of caller that ends up invoking this instance.
Exceptions
- ArgumentNullException
hostFixture
is null.
Methods
ConfigureHost(IHostBuilder)
Provides a way to override the IHostBuilder defaults set up by T
.
protected virtual void ConfigureHost(IHostBuilder hb)
Parameters
hb
IHostBuilderThe IHostBuilder that initializes an instance of IHost.
ConfigureServices(IServiceCollection)
Adds services to the container.
public abstract void ConfigureServices(IServiceCollection services)
Parameters
services
IServiceCollectionThe collection of service descriptors.