public async void Execute_does_not_change_state_if_condition_not_met() { const SaleState startState = SaleState.Open; const SaleState endState = SaleState.Complete; var sale = new Sale(saleID: 66) { State = startState }; var sut = new StateTransitionAutoForwardAsync <Sale, SaleState, SaleEvent>( getStateMachine() , triggerState: startState , toState: endState , conditionAsync: (_, cancelToken) => Task.FromResult(false) , name: "test" , priority: 1); var result = await sut.ExecuteAsync(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale), getDummyResult()); Assert.Equal(startState, sale.State); Assert.False(result.ConditionMet); Assert.False(result.WasTransitioned); Assert.False(result.WasCancelled); Assert.True(result.TransitionDefined); Assert.Equal(startState, result.StartingState); Assert.Equal(startState, result.PreviousState); Assert.Equal(startState, result.CurrentState); }
public async void Execute_changes_state_for_superState() { const SaleState startState = SaleState.Open; const SaleState endState = SaleState.Complete; var sale = new Sale(saleID: 66) { State = SaleState.ChangeDue }; var stateMachine = getStateMachine(); var openStateConfig = stateMachine.ConfigureState(SaleState.Open); stateMachine.ConfigureState(SaleState.ChangeDue) .MakeSubStateOf(openStateConfig); var sut = new StateTransitionAutoForwardAsync <Sale, SaleState, SaleEvent>( stateMachine , triggerState: startState , toState: endState , conditionAsync: (_, cancelToke) => Task.FromResult(true) , name: "test" , priority: 1); var previousResult = getDummyResult(); previousResult.CurrentState = SaleState.ChangeDue; var result = await sut.ExecuteAsync(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale), previousResult); Assert.True(result.WasTransitioned); Assert.Equal(endState, sale.State); Assert.Equal(endState, result.CurrentState); Assert.Equal(SaleState.ChangeDue, result.PreviousState); Assert.Equal(startState, result.StartingState); Assert.True(result.TransitionDefined); }