Class ScreenplayLocator
- Namespace
- CSF.Screenplay
- Assembly
- CSF.Screenplay.NUnit.dll
A small static service locator of sorts, dedicated to getting an appropriate instance of Screenplay for a specified test object.
public static class ScreenplayLocator
- Inheritance
-
ScreenplayLocator
- Inherited Members
Remarks
This type uses reflection to find the ScreenplayAssemblyAttribute which decorates the assembly in which the specified object (a test, a test method or the assembly itself) resides. It additionally caches the results in-memory to avoid repetitive reflection, only to retrieve the same results.
Methods
GetScopedPerformance(ITest)
Gets a DI scope and IPerformance for the specified test.
public static ScopeAndPerformance GetScopedPerformance(ITest test)
Parameters
testITestAn NUnit3 test object.
Returns
- ScopeAndPerformance
A DI scope and performance.
Remarks
This method will return a cached ScopeAndPerformance if one exists for the specified test. If one does not yet exist then a new scope will be created, with an associated performance, and added to the cache.
GetScopedPerformance(Guid)
Gets a DI scope and IPerformance matching the specified performance identity.
public static ScopeAndPerformance GetScopedPerformance(Guid identity)
Parameters
identityGuidA GUID performance identity, corresponding to PerformanceIdentity.
Returns
- ScopeAndPerformance
A DI scope and performance.
Remarks
Unlike the other overload of this method, this overload will not create a scoped performance if one does not yet exist. If this method is used with a performance identity which is not yet cached, then an exception will be raised.
Exceptions
- ArgumentException
If no scope & performance exists in the cache, matching the specified identity
GetScreenplay(IMethodInfo)
Gets a Screenplay instance from the specified test method.
public static Screenplay GetScreenplay(IMethodInfo method)
Parameters
methodIMethodInfoThe test method for which to get a Screenplay object.
Returns
- Screenplay
The Screenplay object for the specified test method.
Remarks
This method makes use of the ScreenplayAssemblyAttribute which decorates the assembly in which the specified method was declared, to get a Screenplay object instance applicable to the test method. If the method's assembly is not decorated with the Screenplay assembly attribute then this method will raise an exception.
Exceptions
- ArgumentNullException
If
methodis null.- ArgumentException
If the
method's assembly is null or is not decorated with ScreenplayAssemblyAttribute.
GetScreenplay(ITest)
Gets a Screenplay instance from the specified test.
public static Screenplay GetScreenplay(ITest test)
Parameters
testITestThe test for which to get a Screenplay object.
Returns
- Screenplay
The Screenplay object for the specified test.
Remarks
This method makes use of the ScreenplayAssemblyAttribute which decorates the assembly in which the specified test's method was declared, to get a Screenplay object instance applicable to the test method. If the test's method's assembly is not decorated with the Screenplay assembly attribute then this method will raise an exception.
Exceptions
- ArgumentNullException
If
testis null.- ArgumentException
If the
test's method's assembly is null or is not decorated with ScreenplayAssemblyAttribute.
GetScreenplay(Assembly)
Gets a Screenplay instance from the specified Assembly.
public static Screenplay GetScreenplay(Assembly assembly)
Parameters
assemblyAssemblyThe test assembly for which to get a Screenplay object.
Returns
- Screenplay
The Screenplay object for the specified assembly.
Remarks
This method makes use of the ScreenplayAssemblyAttribute which decorates the assembly to get a Screenplay object instance for that assembly. If the specified assembly is not decorated with the Screenplay assembly attribute then this method will raise an exception.
Exceptions
- ArgumentNullException
If
assemblyis null.- ArgumentException
If the
assemblyis not decorated with ScreenplayAssemblyAttribute.