public void Execute_transitions_when_matched() { var stateMachine = getStateMachine(); var sut = new StateTransitionAutoDynamicParameterized <Sale, SaleState, SaleEvent, string>(stateMachine , SaleState.Open , (sale, stringParam) => 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, request: "testParam"); var previousResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay, SaleState.Open, SaleState.Open, SaleState.ChangeDue, "previousTransition"); var result = sut.Execute(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 void Execute_transitions_when_matched_superState() { var notificationReceived = false; var stateMachine = getStateMachine(); stateMachine.RegisterOnTransitionedAction((sale, _) => notificationReceived = true); var openStateConfig = stateMachine.ConfigureState(SaleState.Open); stateMachine.ConfigureState(SaleState.ChangeDue).MakeSubStateOf(openStateConfig); var sut = new StateTransitionAutoDynamicParameterized <Sale, SaleState, SaleEvent, string>(stateMachine , SaleState.Open , (sale, stringParam) => SaleState.Complete , SaleState.Open , "autoComplete" , 1); var testSale = new Sale(2) { State = SaleState.ChangeDue }; var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, testSale, request: "testParam"); var previousResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay, SaleState.Open, SaleState.Open, SaleState.ChangeDue, "previousTransition"); var result = sut.Execute(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); Assert.True(notificationReceived); }
public void Execute_throws_ArgumentException_if_request_is_null_or_wrong_type() { var sut = new StateTransitionAutoDynamicParameterized <Sale, SaleState, SaleEvent, string>(getStateMachine() , SaleState.Open , (sale, stringParam) => SaleState.Complete , SaleState.ChangeDue , "autocomplete" , 1); var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, new Sale(2) { State = SaleState.Open }, request: 14); Assert.Throws <ArgumentException>(() => sut.Execute(parameters)); }
public void Execute_fails_if_currentResult_is_null() { var sut = new StateTransitionAutoDynamicParameterized <Sale, SaleState, SaleEvent, string>(getStateMachine() , SaleState.Open , (sale, stringParam) => SaleState.Complete , SaleState.ChangeDue , "autocomplete" , 1); var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, new Sale(2) { State = SaleState.Open }, request: "testParam"); var result = sut.Execute(parameters); Assert.False(result.WasTransitioned); Assert.True(result.TransitionDefined); }
public void Execute_fails_if_triggerState_does_not_match() { var sut = new StateTransitionAutoDynamicParameterized <Sale, SaleState, SaleEvent, string>(getStateMachine() , SaleState.Open , (sale, stringParam) => SaleState.Complete , SaleState.ChangeDue , "autocomplete" , priority: 1); var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, new Sale(saleId: 2) { State = SaleState.Open }, request: "testParam"); var previousResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay, SaleState.Open, SaleState.Open, SaleState.Open, "autoChangeDue"); var result = sut.Execute(parameters, previousResult); Assert.False(result.WasTransitioned); Assert.True(result.TransitionDefined); }