Class ExpectedOutcomeBuilder<TResponse>
Builder for constructing ExpectedOutcome instances fluently.
public class ExpectedOutcomeBuilder<TResponse>
Type Parameters
TResponseThe type of response this outcome validates.
- Inheritance
-
ExpectedOutcomeBuilder<TResponse>
- Inherited Members
Constructors
ExpectedOutcomeBuilder(ResponseValidator)
Creates a new ExpectedOutcomeBuilder with the given validator.
public ExpectedOutcomeBuilder(ResponseValidator validator)
Parameters
validatorResponseValidatorThe validator to use for validating responses.
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 ExpectedOutcomeBuilder<TResponse> SameState()
Returns
- ExpectedOutcomeBuilder<TResponse>
This builder for method chaining.
ThenStateWithMap<TState>(Action<TResponse, TState, Dictionary<object, object>>, Func<TResponse>)
Specifies a response-dependent next state with access to the state clone map. The framework automatically clones the current state with CloneWithMap() and passes both the clone and the mapping from original to cloned states.
public ExpectedOutcomeBuilder<TResponse> ThenStateWithMap<TState>(Action<TResponse, TState, Dictionary<object, object>> modifier, Func<TResponse> mock) where TState : State
Parameters
modifierAction<TResponse, TState, Dictionary<object, object>>An action that receives the response and modifies the cloned state, with access to the clone map.
mockFunc<TResponse>A function that generates a mock response for state exploration.
Returns
- ExpectedOutcomeBuilder<TResponse>
This builder for method chaining.
Type Parameters
TStateThe type of state.
Examples
return Expect.That<ApiResult>(r => r.IsSuccess, "success") .ThenStateWithMap<MyState>((response, nextState, map) => { var clonedUser = (UserState)map[state.Users[response.UserId]]; clonedUser.ETag = response.ETag; }, mock: () => new ApiResult { UserId = "user1", ETag = "mock" });
ThenStateWithMap<TState>(Action<TState, Dictionary<object, object>>)
Specifies a next state using a modifier action with access to the state clone map. The framework automatically clones the current state with CloneWithMap() and passes both the clone and the mapping from original to cloned states.
public ExpectedOutcomeBuilder<TResponse> ThenStateWithMap<TState>(Action<TState, Dictionary<object, object>> modifier) where TState : State
Parameters
modifierAction<TState, Dictionary<object, object>>An action that modifies the cloned state, with access to the clone map.
Returns
- ExpectedOutcomeBuilder<TResponse>
This builder for method chaining.
Type Parameters
TStateThe type of state.
Examples
return Expect.That<int>(r => r > 0, "positive") .ThenStateWithMap<MyState>((nextState, map) => { var clonedChild = (ChildState)map[state.Child]; clonedChild.Value = 42; });
ThenState<TState>(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 ExpectedOutcomeBuilder<TResponse> ThenState<TState>(Action<TResponse, TState> modifier, Func<TResponse> mock) where TState : class, IState
Parameters
modifierAction<TResponse, TState>An action that receives the response and modifies the cloned state.
mockFunc<TResponse>A function that generates a mock response for state exploration.
Returns
- ExpectedOutcomeBuilder<TResponse>
This builder for method chaining.
Type Parameters
TStateThe type of state.
Examples
return Expect.That<ApiResult>(r => r.IsSuccess, "success") .ThenState<MyState>((response, nextState) => { nextState.ETag = response.ETag; }, mock: () => new ApiResult { ETag = "mock" });
ThenState<TState>(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.
public ExpectedOutcomeBuilder<TResponse> ThenState<TState>(Action<TState> modifier) where TState : class, IState
Parameters
modifierAction<TState>An action that modifies the cloned state.
Returns
- ExpectedOutcomeBuilder<TResponse>
This builder for method chaining.
Type Parameters
TStateThe type of state.
Examples
return Expect.That<int>(r => r > 0, "positive") .ThenState<MyState>(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 ExpectedOutcomeBuilder<TResponse> Triggers(IStepFunction stepFunction)
Parameters
stepFunctionIStepFunctionThe step function to trigger.
Returns
- ExpectedOutcomeBuilder<TResponse>
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 ExpectedOutcomeBuilder<TResponse> Triggers(params IStepFunction[] stepFunctions)
Parameters
stepFunctionsIStepFunction[]The step functions to trigger.
Returns
- ExpectedOutcomeBuilder<TResponse>
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 ExpectedOutcomeBuilder<TResponse> Triggers(Func<TResponse, IStepFunction> stepFunctionGenerator)
Parameters
stepFunctionGeneratorFunc<TResponse, IStepFunction>A function that creates the step function given the response.
Returns
- ExpectedOutcomeBuilder<TResponse>
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 ExpectedOutcomeBuilder<TResponse> Triggers(Func<TResponse, IList<IStepFunction>> stepFunctionsGenerator)
Parameters
stepFunctionsGeneratorFunc<TResponse, IList<IStepFunction>>A function that creates the step functions given the response.
Returns
- ExpectedOutcomeBuilder<TResponse>
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 ExpectedOutcomeBuilder<TResponse> TriggersWhen(Func<TResponse, bool> predicate, IStepFunction stepFunction)
Parameters
predicateFunc<TResponse, bool>A function that returns true when the step function should be triggered.
stepFunctionIStepFunctionThe step function to trigger when the predicate is true.
Returns
- ExpectedOutcomeBuilder<TResponse>
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 ExpectedOutcomeBuilder<TResponse> TriggersWhen(Func<TResponse, bool> predicate, params IStepFunction[] stepFunctions)
Parameters
predicateFunc<TResponse, bool>A function that returns true when the step functions should be triggered.
stepFunctionsIStepFunction[]The step functions to trigger when the predicate is true.
Returns
- ExpectedOutcomeBuilder<TResponse>
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 ExpectedOutcomeBuilder<TResponse> WithNextState(IState nextState)
Parameters
nextStateIStateThe state to use after this operation.
Returns
- ExpectedOutcomeBuilder<TResponse>
This builder for method chaining.
Examples
return Expect.That<int>(r => r == expectedValue, "should equal expected") .WithNextState(new CounterState(state.Value + request));
Remarks
This method is ideal for simple value-based states.
For complex states with nested objects where clone-and-mutate is more convenient, use ThenState<TState>(Action<TState>) instead.
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 ExpectedOutcomeBuilder<TResponse> WithNextState(Func<TResponse, State> nextStateFunc, Func<TResponse> mock)
Parameters
nextStateFuncFunc<TResponse, State>A function that takes the response and returns the next state.
mockFunc<TResponse>A function that generates a mock response for state exploration.
Returns
- ExpectedOutcomeBuilder<TResponse>
This builder for method chaining.
Examples
return Expect.That<CreateResponse>(r => r.Success, "created successfully") .WithNextState( response => new MyState(response.Id), mock: () => new CreateResponse { Id = "mock-id" });
Remarks
This method requires a mock response generator for state exploration during test generation. The mock response provides values when the real response is not yet available.
For complex states where clone-and-mutate is more convenient, use ThenState<TState>(Action<TResponse, TState>, Func<TResponse>) instead.
Operators
implicit operator ExpectedOutcome(ExpectedOutcomeBuilder<TResponse>)
Implicit conversion to ExpectedOutcome for cleaner syntax.
public static implicit operator ExpectedOutcome(ExpectedOutcomeBuilder<TResponse> builder)
Parameters
builderExpectedOutcomeBuilder<TResponse>
Returns
implicit operator ExpectedOutcomes(ExpectedOutcomeBuilder<TResponse>)
Implicit conversion to ExpectedOutcomes for cleaner syntax. Wraps this single outcome in an ExpectedOutcomes collection.
public static implicit operator ExpectedOutcomes(ExpectedOutcomeBuilder<TResponse> builder)
Parameters
builderExpectedOutcomeBuilder<TResponse>