public void Execute_transitions_based_on_stateFunc() { var sut = new StateTransitionDynamic <Sale, SaleState, SaleEvent>( stateAccessor: sale => sale.State , stateMutator: (sale, newState) => sale.State = newState , stateFunc: sale => SaleState.Complete , name: "test" , priority: 1); var testSale = new Sale(saleId: 87) { State = SaleState.Open }; var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, testSale); var result = sut.Execute(parameters); Assert.Equal(SaleState.Complete, testSale.State); Assert.Equal(SaleState.Complete, result.CurrentState); Assert.Equal(SaleState.Open, result.PreviousState); }
public void Execute_sends_notification_if_new_state_assigned() { var sut = new StateTransitionDynamic <Sale, SaleState, SaleEvent>( stateAccessor: sale => sale.State , stateMutator: (sale, newState) => sale.State = newState , stateFunc: (sale) => SaleState.Complete , name: "test" , priority: 1); var notificationReceived = false; StateTransitionDynamic <Sale, SaleState, SaleEvent> .OnTransitionedEvent += (sale, _) => notificationReceived = true; var testSale = new Sale(saleID: 87) { State = SaleState.Open }; var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, testSale); sut.Execute(parameters); Assert.True(notificationReceived); }
public void Execute_treats_lack_of_transitions_as_failed_condition() { var sut = new StateTransitionDynamic <Sale, SaleState, SaleEvent>( stateAccessor: sale => sale.State , stateMutator: (sale, newState) => sale.State = newState , stateFunc: sale => SaleState.Open , name: "test" , priority: 1); var testSale = new Sale(saleId: 87) { State = SaleState.Open }; var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, testSale); var result = sut.Execute(parameters); Assert.False(result.ConditionMet); Assert.False(result.WasTransitioned); Assert.False(result.WasCancelled); Assert.Equal(SaleState.Open, testSale.State); Assert.Equal(SaleState.Open, result.CurrentState); Assert.Equal(SaleState.Open, result.PreviousState); }