Table of Contents

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 ICanPerformWhen

An actor

performableBuilder IGetsPerformable

The performable builder

cancellationToken CancellationToken

An 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 ICanPerformWhen

An actor

performableBuilder IGetsPerformableWithResult

The performable builder

cancellationToken CancellationToken

An optional token to cancel the performable

Returns

ValueTask<object>

A task which exposes a result when the performable is complete

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 ICanPerformWhen

An actor

performableBuilder IGetsPerformableWithResult<T>

The performable builder

cancellationToken CancellationToken

An 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 ICanPerform

The actor from whom to get the ability

abilityType Type

The 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 ICanPerform

The 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 ICanPerform

An actor

abilityType Type

The ability type for which to test

Returns

bool

true if the actor has an ability of the specified abilityType; false if not.

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 IHasAbilities

An actor

abilityType Type

The ability type for which to test

Returns

bool

true if the actor has an ability of the specified abilityType; false if not.

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 ICanPerform

An actor

Returns

bool

true if the actor has an ability of the specified T; false if not.

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 IHasAbilities

An actor

Returns

bool

true if the actor has an ability of the specified T; false if not.

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 ICanPerform

The actor from whom to get the ability

ability object

The 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 ICanPerform

The 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 ICanPerform

An actor

performableBuilder IGetsPerformable

The performable builder

cancellationToken CancellationToken

An 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 ICanPerform

An actor

performableBuilder IGetsPerformableWithResult

The performable builder

cancellationToken CancellationToken

An optional token to cancel the performable

Returns

ValueTask<object>

A task which exposes a result when the performable is complete

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 ICanPerform

An actor

performableBuilder IGetsPerformableWithResult<T>

The performable builder

cancellationToken CancellationToken

An 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 ICanPerformThen

An actor

performableBuilder IGetsPerformable

The performable builder

cancellationToken CancellationToken

An 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 ICanPerformThen

An actor

performableBuilder IGetsPerformableWithResult

The performable builder

cancellationToken CancellationToken

An optional token to cancel the performable

Returns

ValueTask<object>

A task which exposes a result when the performable is complete

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 ICanPerformThen

An actor

performableBuilder IGetsPerformableWithResult<T>

The performable builder

cancellationToken CancellationToken

An 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 ICanPerformGiven

An actor

performableBuilder IGetsPerformable

The performable builder

cancellationToken CancellationToken

An 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 ICanPerformGiven

An actor

performableBuilder IGetsPerformableWithResult

The performable builder

cancellationToken CancellationToken

An optional token to cancel the performable

Returns

ValueTask<object>

A task which exposes a result when the performable is complete

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 ICanPerformGiven

An actor

performableBuilder IGetsPerformableWithResult<T>

The performable builder

cancellationToken CancellationToken

An 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