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
output
ITestOutputHelperAn implementation of the Xunit.Abstractions.ITestOutputHelper interface.
callerType
TypeThe 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
- Boolean
true
if 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(Boolean)
Releases the unmanaged resources used by the Test 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 Test.
public async 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
expected
StringThe expected string value.
actual
StringThe actual string value.
setup
Action<WildcardOptions>The WildcardOptions which may be configured.
Returns
- Boolean
true
ifactual
matchesexpected
,false
otherwise.
Remarks
Credits for inspiration goes to this SO answer: https://stackoverflow.com/questions/30299671/matching-strings-with-wildcard/30300521#30300521
Exceptions
- ArgumentOutOfRangeException
expected
cannot be matched withactual
. Includes the non-matched string(s) in ActualValue.
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 ValueTask OnDisposeManagedResourcesAsync()
Returns
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()