Table of Contents

Class TypedExpectBuilder<TResponse, TState>

Namespace
Microsoft.Accordant
Assembly
Accordant.Operations.dll

A typed builder for constructing ExpectedOutcome instances fluently. This builder knows both the response type and state type, allowing methods like ThenState(Action<TState>) to work without explicit generic type parameters.

public class TypedExpectBuilder<TResponse, TState> where TState : class, IState

Type Parameters

TResponse

The response type.

TState

The state type.

Inheritance
TypedExpectBuilder<TResponse, TState>
Inherited Members

Constructors

TypedExpectBuilder(ExpectedOutcomeBuilder<TResponse>)

Creates a new TypedExpectBuilder wrapping an ExpectedOutcomeBuilder.

public TypedExpectBuilder(ExpectedOutcomeBuilder<TResponse> inner)

Parameters

inner ExpectedOutcomeBuilder<TResponse>

The inner builder to wrap.

Methods

Build()

Builds the ExpectedOutcome from this builder's configuration.

public ExpectedOutcome Build()

Returns

ExpectedOutcome

The constructed expected outcome.

SameState()

Indicates that the state is unchanged by this operation. When the outcome is matched, the original input state will be used.

public TypedExpectBuilder<TResponse, TState> SameState()

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

ThenState(Action<TResponse, TState>, Func<TResponse>)

Specifies a response-dependent next state using a modifier action that mutates a pre-cloned state. The framework automatically clones the current state and passes it to the modifier.

public TypedExpectBuilder<TResponse, TState> ThenState(Action<TResponse, TState> modifier, Func<TResponse> mock)

Parameters

modifier Action<TResponse, TState>

An action that receives the response and modifies the cloned state.

mock Func<TResponse>

A function that generates a mock response for state exploration.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

ThenState(Action<TState>)

Specifies a next state using a modifier action that mutates a pre-cloned state. The framework automatically clones the current state and passes it to the modifier. The state type is inferred from the operation context.

public TypedExpectBuilder<TResponse, TState> ThenState(Action<TState> modifier)

Parameters

modifier Action<TState>

An action that modifies the cloned state.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

Examples

return Expect.That(r => r > 0, "positive") .ThenState(nextState => nextState.Items.Add(request));

Triggers(IStepFunction)

Specifies that this operation triggers background activity via a step function. The step function runs concurrently with subsequent operations.

public TypedExpectBuilder<TResponse, TState> Triggers(IStepFunction stepFunction)

Parameters

stepFunction IStepFunction

The step function to trigger.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

Triggers(params IStepFunction[])

Specifies that this operation triggers multiple background activities via step functions. The step functions run concurrently with subsequent operations.

public TypedExpectBuilder<TResponse, TState> Triggers(params IStepFunction[] stepFunctions)

Parameters

stepFunctions IStepFunction[]

The step functions to trigger.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

Triggers(Func<TResponse, IStepFunction>)

Specifies that this operation triggers response-dependent background activity. The step function runs concurrently with subsequent operations.

public TypedExpectBuilder<TResponse, TState> Triggers(Func<TResponse, IStepFunction> stepFunctionGenerator)

Parameters

stepFunctionGenerator Func<TResponse, IStepFunction>

A function that creates the step function given the response.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

Triggers(Func<TResponse, IList<IStepFunction>>)

Specifies that this operation triggers response-dependent background activity that may result in multiple concurrent step functions.

public TypedExpectBuilder<TResponse, TState> Triggers(Func<TResponse, IList<IStepFunction>> stepFunctionsGenerator)

Parameters

stepFunctionsGenerator Func<TResponse, IList<IStepFunction>>

A function that creates the step functions given the response.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

TriggersWhen(Func<TResponse, bool>, IStepFunction)

Specifies that this operation conditionally triggers a step function based on the response. The step function is only triggered when the predicate returns true.

public TypedExpectBuilder<TResponse, TState> TriggersWhen(Func<TResponse, bool> predicate, IStepFunction stepFunction)

Parameters

predicate Func<TResponse, bool>

A function that returns true when the step function should be triggered.

stepFunction IStepFunction

The step function to trigger when the predicate is true.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

TriggersWhen(Func<TResponse, bool>, params IStepFunction[])

Specifies that this operation conditionally triggers multiple step functions based on the response. The step functions are only triggered when the predicate returns true.

public TypedExpectBuilder<TResponse, TState> TriggersWhen(Func<TResponse, bool> predicate, params IStepFunction[] stepFunctions)

Parameters

predicate Func<TResponse, bool>

A function that returns true when the step functions should be triggered.

stepFunctions IStepFunction[]

The step functions to trigger when the predicate is true.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

WithNextState(IState)

Specifies the exact next state to use after this operation. Use this for simple state types where you construct a new state instance rather than mutating a clone.

public TypedExpectBuilder<TResponse, TState> WithNextState(IState nextState)

Parameters

nextState IState

The state to use after this operation.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

WithNextState(Func<TResponse, State>, Func<TResponse>)

Specifies a response-dependent next state. Use this when the next state depends on values in the response (e.g., server-generated IDs).

public TypedExpectBuilder<TResponse, TState> WithNextState(Func<TResponse, State> nextStateFunc, Func<TResponse> mock)

Parameters

nextStateFunc Func<TResponse, State>

A function that takes the response and returns the next state.

mock Func<TResponse>

A function that generates a mock response for state exploration.

Returns

TypedExpectBuilder<TResponse, TState>

This builder for method chaining.

Operators

implicit operator ExpectedOutcome(TypedExpectBuilder<TResponse, TState>)

Implicit conversion to ExpectedOutcome for cleaner syntax.

public static implicit operator ExpectedOutcome(TypedExpectBuilder<TResponse, TState> builder)

Parameters

builder TypedExpectBuilder<TResponse, TState>

Returns

ExpectedOutcome

implicit operator ExpectedOutcomes(TypedExpectBuilder<TResponse, TState>)

Implicit conversion to ExpectedOutcomes for cleaner syntax. Wraps this single outcome in an ExpectedOutcomes collection.

public static implicit operator ExpectedOutcomes(TypedExpectBuilder<TResponse, TState> builder)

Parameters

builder TypedExpectBuilder<TResponse, TState>

Returns

ExpectedOutcomes