Class ActorExtensions
- Namespace
- CSF.Screenplay
- Assembly
- CSF.Screenplay.Abstractions.dll
Extension methods for actor types
public static class ActorExtensions
- Inheritance
-
ActorExtensions
- Inherited Members
Methods
AttemptsTo(ICanPerformWhen, IGetsPerformable, CancellationToken)
Performs an action or task which returns no result.
public static ValueTask AttemptsTo(this ICanPerformWhen actor, IGetsPerformable performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformWhenAn actor
performableBuilder
IGetsPerformableThe performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
- ValueTask
A task which completes when the performable is complete
AttemptsTo(ICanPerformWhen, IGetsPerformableWithResult, CancellationToken)
Performs an action or task which returns an untyped result.
public static ValueTask<object> AttemptsTo(this ICanPerformWhen actor, IGetsPerformableWithResult performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformWhenAn actor
performableBuilder
IGetsPerformableWithResultThe performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
AttemptsTo<T>(ICanPerformWhen, IGetsPerformableWithResult<T>, CancellationToken)
Performs an action or task which returns a strongly typed result.
public static ValueTask<T> AttemptsTo<T>(this ICanPerformWhen actor, IGetsPerformableWithResult<T> performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformWhenAn actor
performableBuilder
IGetsPerformableWithResult<T>The performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
- ValueTask<T>
A task which exposes a result when the performable is complete
Type Parameters
T
The result type
GetAbility(ICanPerform, Type)
Gets the first ability which the actor has of the specified type
public static object GetAbility(this ICanPerform actor, Type abilityType)
Parameters
actor
ICanPerformThe actor from whom to get the ability
abilityType
TypeThe type of ability desired
Returns
- object
The ability instance
Exceptions
- ArgumentNullException
If any parameter is null
- ArgumentException
If the actor does not implement IHasAbilities
- InvalidOperationException
If the actor does not have an ability which is or derives from
abilityType
GetAbility<T>(ICanPerform)
Gets the first ability which the actor has of the specified type
public static T GetAbility<T>(this ICanPerform actor)
Parameters
actor
ICanPerformThe actor from whom to get the ability
Returns
- T
The ability instance
Type Parameters
T
The type of ability desired
Exceptions
- ArgumentNullException
If the
actor
is null- ArgumentException
If the actor does not implement IHasAbilities
- InvalidOperationException
If the actor does not have an ability which is or derives from
T
HasAbility(ICanPerform, Type)
Gets a value which indicates if the actor has an ability of the specified type.
public static bool HasAbility(this ICanPerform actor, Type abilityType)
Parameters
actor
ICanPerformAn actor
abilityType
TypeThe ability type for which to test
Returns
Remarks
This method will also return false if the actor does not implement IHasAbilities.
HasAbility(IHasAbilities, Type)
Gets a value which indicates if the actor has an ability of the specified type.
public static bool HasAbility(this IHasAbilities actor, Type abilityType)
Parameters
actor
IHasAbilitiesAn actor
abilityType
TypeThe ability type for which to test
Returns
HasAbility<T>(ICanPerform)
Gets a value which indicates if the actor has an ability of the specified type.
public static bool HasAbility<T>(this ICanPerform actor)
Parameters
actor
ICanPerformAn actor
Returns
Type Parameters
T
The ability type for which to test
Remarks
This method will also return false if the actor does not implement IHasAbilities.
HasAbility<T>(IHasAbilities)
Gets a value which indicates if the actor has an ability of the specified type.
public static bool HasAbility<T>(this IHasAbilities actor)
Parameters
actor
IHasAbilitiesAn actor
Returns
Type Parameters
T
The ability type for which to test
IsAbleTo(ICanPerform, object)
Adds an ability to the specified actor
public static void IsAbleTo(this ICanPerform actor, object ability)
Parameters
actor
ICanPerformThe actor from whom to get the ability
ability
objectThe ability to add to the actor
Exceptions
- ArgumentNullException
If any parameter is null
- ArgumentException
If the actor does not implement IHasAbilities
- InvalidOperationException
If the actor already has an ability of the same type as the
ability
to add, or which derives from the same type
IsAbleTo<TAbility>(ICanPerform)
Adds an ability to the specified actor, where the ability has a public parameterless constructor
public static void IsAbleTo<TAbility>(this ICanPerform actor) where TAbility : new()
Parameters
actor
ICanPerformThe actor from whom to get the ability
Type Parameters
TAbility
The type of the ability to add to the actor
Remarks
This method is a convenience for manually instantiating the ability instance and adding it to the actor in that manner. For abilities which do not have a public parameterless constructor, consider adding them to the actor via dependency injection. The recommended technique for accomplishing this is by implementing IPersona in a class of your own. Implementations of persona are eligible for dependency injection when the actor is retrieved from the persona type via the ICast: GetActor<TPersona>(ICast).
Exceptions
- ArgumentNullException
If any parameter is null
- ArgumentException
If the actor does not implement IHasAbilities
- InvalidOperationException
If the actor already has an ability of the same type as the
TAbility
to add, or which derives from the same type
PerformAsync(ICanPerform, IGetsPerformable, CancellationToken)
Performs an action or task which returns no result from the performable which is exposed by the specified builder object.
public static ValueTask PerformAsync(this ICanPerform actor, IGetsPerformable performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformAn actor
performableBuilder
IGetsPerformableThe performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
- ValueTask
A task which completes when the performable is complete
PerformAsync(ICanPerform, IGetsPerformableWithResult, CancellationToken)
Performs an action or task which returns an untyped result from the performable which is exposed by the specified builder object.
public static ValueTask<object> PerformAsync(this ICanPerform actor, IGetsPerformableWithResult performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformAn actor
performableBuilder
IGetsPerformableWithResultThe performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
PerformAsync<T>(ICanPerform, IGetsPerformableWithResult<T>, CancellationToken)
Performs an action or task which returns a strongly typed result from the performable which is exposed by the specified builder object.
public static ValueTask<T> PerformAsync<T>(this ICanPerform actor, IGetsPerformableWithResult<T> performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformAn actor
performableBuilder
IGetsPerformableWithResult<T>The performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
- ValueTask<T>
A task which exposes a result when the performable is complete
Type Parameters
T
The result type
Should(ICanPerformThen, IGetsPerformable, CancellationToken)
Performs an action or task which returns no result.
public static ValueTask Should(this ICanPerformThen actor, IGetsPerformable performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformThenAn actor
performableBuilder
IGetsPerformableThe performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
- ValueTask
A task which completes when the performable is complete
Should(ICanPerformThen, IGetsPerformableWithResult, CancellationToken)
Performs an action or task which returns an untyped result.
public static ValueTask<object> Should(this ICanPerformThen actor, IGetsPerformableWithResult performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformThenAn actor
performableBuilder
IGetsPerformableWithResultThe performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
Should<T>(ICanPerformThen, IGetsPerformableWithResult<T>, CancellationToken)
Performs an action or task which returns a strongly typed result.
public static ValueTask<T> Should<T>(this ICanPerformThen actor, IGetsPerformableWithResult<T> performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformThenAn actor
performableBuilder
IGetsPerformableWithResult<T>The performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
- ValueTask<T>
A task which exposes a result when the performable is complete
Type Parameters
T
The result type
WasAbleTo(ICanPerformGiven, IGetsPerformable, CancellationToken)
Performs an action or task which returns no result.
public static ValueTask WasAbleTo(this ICanPerformGiven actor, IGetsPerformable performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformGivenAn actor
performableBuilder
IGetsPerformableThe performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
- ValueTask
A task which completes when the performable is complete
WasAbleTo(ICanPerformGiven, IGetsPerformableWithResult, CancellationToken)
Performs an action or task which returns an untyped result.
public static ValueTask<object> WasAbleTo(this ICanPerformGiven actor, IGetsPerformableWithResult performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformGivenAn actor
performableBuilder
IGetsPerformableWithResultThe performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
WasAbleTo<T>(ICanPerformGiven, IGetsPerformableWithResult<T>, CancellationToken)
Performs an action or task which returns a strongly typed result.
public static ValueTask<T> WasAbleTo<T>(this ICanPerformGiven actor, IGetsPerformableWithResult<T> performableBuilder, CancellationToken cancellationToken = default)
Parameters
actor
ICanPerformGivenAn actor
performableBuilder
IGetsPerformableWithResult<T>The performable builder
cancellationToken
CancellationTokenAn optional token to cancel the performable
Returns
- ValueTask<T>
A task which exposes a result when the performable is complete
Type Parameters
T
The result type