Class TestingContext
Testing context that provides access to the system under test during test execution. Provides common functionality for all testing contexts.
public sealed class TestingContext
- Inheritance
-
TestingContext
- Inherited Members
Constructors
TestingContext(ISpec, string)
public TestingContext(ISpec spec, string testDirectoryPath = null)
Parameters
Properties
RequestPrinter
public Func<object, string> RequestPrinter { get; set; }
Property Value
ResponsePrinter
public Func<object, string> ResponsePrinter { get; set; }
Property Value
Spec
The spec being tested.
public ISpec Spec { get; set; }
Property Value
Methods
Get<T>()
Gets the registered service of the specified type. Use this in ExecuteAsync(TestingContext, TRequest) to access the system under test or other registered services.
public T Get<T>()
Returns
- T
The registered service instance.
Type Parameters
TThe type of the service to retrieve.
Exceptions
- InvalidOperationException
Thrown if no service of type T has been registered.
Register<T>(T)
Registers a target instance that can be retrieved via Get<T>(). This is typically called during test initialization to register the system under test.
public void Register<T>(T instance)
Parameters
instanceTThe target instance to register.
Type Parameters
TThe type of the target.
Target<T>()
Gets the registered target of the specified type. This is an alias for Get<T>() for backwards compatibility.
[Obsolete("Use Get<T>() instead. This method will be removed in a future version.")]
public T Target<T>()
Returns
- T
The registered target instance.
Type Parameters
TThe type of the target to retrieve.