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
actorICanPerformWhenAn actor
performableBuilderIGetsPerformableThe performable builder
cancellationTokenCancellationTokenAn 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
actorICanPerformWhenAn actor
performableBuilderIGetsPerformableWithResultThe performable builder
cancellationTokenCancellationTokenAn 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
actorICanPerformWhenAn actor
performableBuilderIGetsPerformableWithResult<T>The performable builder
cancellationTokenCancellationTokenAn optional token to cancel the performable
Returns
- ValueTask<T>
A task which exposes a result when the performable is complete
Type Parameters
TThe 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
actorICanPerformThe actor from whom to get the ability
abilityTypeTypeThe 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
actorICanPerformThe actor from whom to get the ability
Returns
- T
The ability instance
Type Parameters
TThe type of ability desired
Exceptions
- ArgumentNullException
If the
actoris 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
actorICanPerformAn actor
abilityTypeTypeThe 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
actorIHasAbilitiesAn actor
abilityTypeTypeThe 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
actorICanPerformAn actor
Returns
Type Parameters
TThe 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
actorIHasAbilitiesAn actor
Returns
Type Parameters
TThe 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
actorICanPerformThe actor from whom to get the ability
abilityobjectThe 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
abilityto 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
actorICanPerformThe actor from whom to get the ability
Type Parameters
TAbilityThe 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
TAbilityto 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
actorICanPerformAn actor
performableBuilderIGetsPerformableThe performable builder
cancellationTokenCancellationTokenAn 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
actorICanPerformAn actor
performableBuilderIGetsPerformableWithResultThe performable builder
cancellationTokenCancellationTokenAn 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
actorICanPerformAn actor
performableBuilderIGetsPerformableWithResult<T>The performable builder
cancellationTokenCancellationTokenAn optional token to cancel the performable
Returns
- ValueTask<T>
A task which exposes a result when the performable is complete
Type Parameters
TThe 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
actorICanPerformThenAn actor
performableBuilderIGetsPerformableThe performable builder
cancellationTokenCancellationTokenAn 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
actorICanPerformThenAn actor
performableBuilderIGetsPerformableWithResultThe performable builder
cancellationTokenCancellationTokenAn 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
actorICanPerformThenAn actor
performableBuilderIGetsPerformableWithResult<T>The performable builder
cancellationTokenCancellationTokenAn optional token to cancel the performable
Returns
- ValueTask<T>
A task which exposes a result when the performable is complete
Type Parameters
TThe 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
actorICanPerformGivenAn actor
performableBuilderIGetsPerformableThe performable builder
cancellationTokenCancellationTokenAn 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
actorICanPerformGivenAn actor
performableBuilderIGetsPerformableWithResultThe performable builder
cancellationTokenCancellationTokenAn 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
actorICanPerformGivenAn actor
performableBuilderIGetsPerformableWithResult<T>The performable builder
cancellationTokenCancellationTokenAn optional token to cancel the performable
Returns
- ValueTask<T>
A task which exposes a result when the performable is complete
Type Parameters
TThe result type