Class PerformanceAdapter
- Namespace
- CSF.Screenplay
- Assembly
- CSF.Screenplay.NUnit.dll
An adapter which enables the use of IPerformance within an NUnit3 test, without needing to parameter-inject the instance
as Lazy<IPerformance>.
public sealed class PerformanceAdapter : IPerformance, IHasPerformanceIdentity, IHasServiceProvider, IDisposable, IBeginsAndEndsPerformance
- Inheritance
-
PerformanceAdapter
- Implements
- Inherited Members
Remarks
Due to NUnit architectural limitations, injectable parameters cannot be resolved from DI at the point the test method is built. If we were to attempt this, then the parameter value would not be associated with the correct Screenplay/DI scope (and thus Event Bus). This is due to the two-process model which NUnit uses; one process for building the test methods and another process for running the tests. By using an adapter with Lazy resolution of the real implementation, we ensure that DI resolution is deferred into the test-run process and not the test-building process.
Constructors
PerformanceAdapter(Guid)
Creates a new instance of PerformanceAdapter for the specified performance identity.
public PerformanceAdapter(Guid performanceIdentity)
Parameters
performanceIdentityGuidA performance identity, corresponding to PerformanceIdentity.
Properties
NamingHierarchy
Gets an ordered list of identifiers which indicate the current performance's name within an organisational hierarchy.
public IReadOnlyList<IdentifierAndName> NamingHierarchy { get; }
Property Value
Examples
If the current performance is to be named Joe can take out the Trash, and it is part of a parent name, named
Joe can do his chores then the first identifier in the list will be named Joe can do his chores
and the second will be named Joe can take out the Trash.
Remarks
A Screenplay typically contains more than one performance and may contain many. It is normal to organise performances into a hierarchical structure based upon their purpose, role or relationship. The position of the current performance in that naming structure is represented by the value of this property.
The ordered list of IdentifierAndName instances indicate a path from the 'root' of the hierarchy (which has no inherent name) to the current performance. Identifier/name pairs which are earlier in the collection are considered to be closer to the root, whereas latter identifier/names are branch & leaf names. In this manner, they work very similarly to .NET namespaces. The earlier in the list that a name appears, the more general it should be, representing a wider category.
When using Screenplay with Integration, this hierarchy of names would typically correspond to the naming convention used by the testing framework. That might be based upon .NET namespaces, classes and test methods for a more traditional unit testing framework. Alternatively, for a BDD-style testing framework, it could be named based upon human-readable feature & scenario names.
PerformanceIdentity
Gets the unique IPerformance identifier
public Guid PerformanceIdentity { get; }
Property Value
Remarks
This value is used to uniquely identify a performance within a CSF.Screenplay.
PerformanceState
Gets a value which indicates the state of the current performance.
public PerformanceState PerformanceState { get; }
Property Value
- See Also
ServiceProvider
Gets a service provider/resolver instance associated with this object.
public IServiceProvider ServiceProvider { get; }
Property Value
Methods
BeginPerformance()
Begins the performance
public void BeginPerformance()
Dispose()
public void Dispose()
FinishPerformance(bool?)
Finishes the performance with a value indicating whether or not it was a success
public void FinishPerformance(bool? success)