public async void ExecuteAsync_transitions_when_matched() { var stateMachine = getStateMachine(); var sut = new StateTransitionAutoDynamic <Sale, SaleState, SaleEvent>(stateMachine , SaleState.Open , _ => SaleState.Complete , SaleState.ChangeDue , "autocomplete" , priority: 1); var testSale = new Sale(saleId: 2) { State = SaleState.Open }; var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, testSale); var previousResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay, SaleState.Open, SaleState.Open, SaleState.ChangeDue, "previousTransition"); var result = await sut.ExecuteAsync(parameters, previousResult); Assert.True(result.WasTransitioned); Assert.Equal("autocomplete", result.LastTransitionName); Assert.Equal(SaleState.Complete, SaleState.Complete); Assert.Equal(SaleState.Complete, SaleState.Complete); Assert.Equal(SaleState.ChangeDue, SaleState.ChangeDue); Assert.Equal(SaleState.Open, result.StartingState); Assert.Equal(SaleState.Complete, testSale.State); }
public async void ExecuteAsync_fails_if_currentResult_is_null() { var sut = new StateTransitionAutoDynamic <Sale, SaleState, SaleEvent>(getStateMachine() , SaleState.Open , _ => SaleState.Complete , SaleState.ChangeDue , "autocomplete" , priority: 1); var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, new Sale(saleId: 2) { State = SaleState.Open }); var result = await sut.ExecuteAsync(parameters); Assert.False(result.WasTransitioned); Assert.True(result.TransitionDefined); }
public async void ExecuteAsync_fails_if_triggerState_does_not_match() { var sut = new StateTransitionAutoDynamic <Sale, SaleState, SaleEvent>(getStateMachine() , SaleState.Open , _ => SaleState.Complete , SaleState.ChangeDue , "autocomplete" , priority: 1); var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, new Sale(saleId: 2) { State = SaleState.Open }); var previousResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay, SaleState.Open, SaleState.Open, SaleState.Open, "autoChangeDue"); var result = await sut.ExecuteAsync(parameters, previousResult); Assert.False(result.WasTransitioned); Assert.True(result.TransitionDefined); }