Class Test
- Namespace
- Codebelt.Extensions.Xunit
- Assembly
- Codebelt.Extensions.Xunit.dll
Represents the base class from which all implementations of unit testing should derive.
public abstract class Test : ITest, IDisposable, IAsyncDisposable, IAsyncLifetime
- Inheritance
-
Test
- Implements
-
IAsyncLifetime
- Derived
Constructors
Test(ITestOutputHelper, Type)
Initializes a new instance of the Test class.
protected Test(ITestOutputHelper output = null, Type callerType = null)
Parameters
outputITestOutputHelperAn implementation of the Xunit.Abstractions.ITestOutputHelper interface.
callerTypeTypeThe Type of caller that ends up invoking this instance.
Remarks
output is initialized automatically in an xUnit project.
Properties
CallerType
Gets the type of caller for this instance. Default is GetType().
public Type CallerType { get; }
Property Value
- Type
The type of caller for this instance.
Disposed
Gets a value indicating whether this Test object is disposed.
public bool Disposed { get; }
Property Value
HasTestOutput
Gets a value indicating whether TestOutput has a reference to an implementation of Xunit.Abstractions.ITestOutputHelper.
protected bool HasTestOutput { get; }
Property Value
- bool
trueif this instance has a reference to an implementation of Xunit.Abstractions.ITestOutputHelper; otherwise,false.
TestOutput
Gets the console substitute to write out unit test information.
protected ITestOutputHelper TestOutput { get; }
Property Value
- ITestOutputHelper
The console substitute to write out unit test information.
Methods
Dispose()
Releases all resources used by the Test object.
public void Dispose()
Dispose(bool)
Releases the unmanaged resources used by the Test object and optionally releases the managed resources.
protected void Dispose(bool disposing)
Parameters
disposingbooltrueto release both managed and unmanaged resources;falseto release only unmanaged resources.
DisposeAsync()
Asynchronously releases the resources used by the Test.
public ValueTask DisposeAsync()
Returns
Remarks
InitializeAsync()
Called immediately after the class has been created, before it is used.
public virtual Task InitializeAsync()
Returns
Match(string, string, Action<WildcardOptions>)
Provides a way, with wildcard support, to determine if actual matches expected.
public static bool Match(string expected, string actual, Action<WildcardOptions> setup = null)
Parameters
expectedstringThe expected string value.
actualstringThe actual string value.
setupAction<WildcardOptions>The WildcardOptions which may be configured.
Returns
- bool
trueifactualmatchesexpected,falseotherwise.
Remarks
Credits for inspiration goes to this SO answer: https://stackoverflow.com/questions/30299671/matching-strings-with-wildcard/30300521#30300521
Exceptions
- ArgumentOutOfRangeException
expectedcannot be matched withactual. Includes the non-matched string(s) in ActualValue.
OnDisposeManagedResources()
Called when this object is being disposed by either Dispose() or Dispose(bool) 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 ValueTask OnDisposeManagedResourcesAsync()
Returns
OnDisposeUnmanagedResources()
Called when this object is being disposed by either Dispose() or Dispose(bool) and Disposed is false.
protected virtual void OnDisposeUnmanagedResources()