Example #1
0
        public void Execute_doesnt_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 StateTransition <Sale, SaleState, SaleEvent>(
                stateAccessor: saleToUpdate => saleToUpdate.State
                , stateMutator: (saleToUpdate, newState) => saleToUpdate.State = newState
                , toState: endState
                , condition: (_) => false
                , name: "test"
                , priority: 1);

            var result = sut.Execute(new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale));

            Assert.False(result.WasTransitioned);
            Assert.Equal(startState, sale.State);
        }