Class HostFixture
- Namespace
- Codebelt.Extensions.Xunit.Hosting
- Assembly
- Codebelt.Extensions.Xunit.Hosting.dll
Provides a default implementation of the IHostFixture interface.
public class HostFixture : IHostFixture, IServiceTest, IHostTest, IConfigurationTest, IHostingEnvironmentTest, IDisposable, IAsyncDisposable, IAsyncLifetime
- Inheritance
-
ObjectHostFixture
- Implements
-
IDisposableIAsyncDisposableIAsyncLifetime
- Derived
Constructors
HostFixture()
Initializes a new instance of the HostFixture class.
public HostFixture()
Properties
Configuration
Gets the Microsoft.Extensions.Configuration.IConfiguration initialized by this instance.
public IConfiguration Configuration { get; protected set; }
Property Value
- IConfiguration
The Microsoft.Extensions.Configuration.IConfiguration initialized by this instance.
ConfigureCallback
Gets or sets the delegate that initializes the test class.
public Action<IConfiguration, IHostEnvironment> ConfigureCallback { get; set; }
Property Value
- Action<IConfiguration, IHostEnvironment>
The delegate that initializes the test class.
Remarks
Mimics the Startup convention.
ConfigureHostCallback
Gets or sets the delegate that initializes the host builder.
public Action<IHostBuilder> ConfigureHostCallback { get; set; }
Property Value
- Action<IHostBuilder>
The delegate that initializes the host builder.
ConfigureServicesCallback
Gets or sets the delegate that adds services to the container.
public Action<IServiceCollection> ConfigureServicesCallback { get; set; }
Property Value
- Action<IServiceCollection>
The delegate that adds services to the container.
Disposed
Gets a value indicating whether this HostFixture object is disposed.
public bool Disposed { get; }
Property Value
- Boolean
true
if this HostFixture object is disposed; otherwise,false
.
Host
Gets or sets the Microsoft.Extensions.Hosting.IHost initialized by this instance.
public IHost Host { get; protected set; }
Property Value
- IHost
The Microsoft.Extensions.Hosting.IHost initialized by this instance.
HostingEnvironment
Gets the Microsoft.Extensions.Hosting.IHostEnvironment initialized by this instance.
public IHostEnvironment HostingEnvironment { get; protected set; }
Property Value
- IHostEnvironment
The Microsoft.Extensions.Hosting.IHostEnvironment initialized by this instance.
ServiceProvider
Gets the System.IServiceProvider initialized by this instance.
public IServiceProvider ServiceProvider { get; }
Property Value
- IServiceProvider
The System.IServiceProvider initialized by this instance.
Methods
ConfigureHost(Test)
Creates and configures the Microsoft.Extensions.Hosting.IHost of this instance.
public virtual void ConfigureHost(Test hostTest)
Parameters
hostTest
TestThe object that inherits from HostTest<T>.
Remarks
hostTest
was added to support those cases where the caller is required in the host configuration.
Exceptions
- System.ArgumentNullException
hostTest
is null.- System.ArgumentOutOfRangeException
hostTest
is not assignable from HostTest<T>.
Dispose()
Releases all resources used by the HostFixture object.
public void Dispose()
Dispose(Boolean)
Releases the unmanaged resources used by the HostFixture object and optionally releases the managed resources.
protected void Dispose(bool disposing)
Parameters
disposing
Booleantrue
to release both managed and unmanaged resources;false
to release only unmanaged resources.
DisposeAsync()
Asynchronously releases the resources used by the HostFixture.
public async ValueTask DisposeAsync()
Returns
- ValueTask
A System.Threading.Tasks.ValueTask that represents the asynchronous dispose operation.
Remarks
HasTypes(Type, Type[])
Determines whether the specified type
contains one or more of the specified target types
.
protected static bool HasTypes(Type type, params Type[] types)
Parameters
type
TypeThe System.Type to validate.
types
Type[]The target types to be matched against.
Returns
- Boolean
true
if thetype
contains one or more of the specified target types; otherwise,false
.
InitializeAsync()
Called immediately after the class has been created, before it is used.
public virtual Task InitializeAsync()
Returns
- Task
A System.Threading.Tasks.Task that represents the asynchronous operation.
OnDisposeManagedResources()
Called when this object is being disposed by either Dispose() or Dispose(Boolean) having disposing
set to true
and Disposed is false
.
protected virtual void OnDisposeManagedResources()
OnDisposeManagedResourcesAsync()
Called when this object is being disposed by DisposeAsync().
protected virtual async ValueTask OnDisposeManagedResourcesAsync()
Returns
- ValueTask
OnDisposeUnmanagedResources()
Called when this object is being disposed by either Dispose() or Dispose(Boolean) and Disposed is false
.
protected virtual void OnDisposeUnmanagedResources()
Explicit Interface Implementations
IAsyncLifetime.DisposeAsync()
Task IAsyncLifetime.DisposeAsync()
Returns
- Task