public void Execute_transitions_based_on_StateFuncAsync()
        {
            var sut = new StateTransitionDynamicParameterized <Sale, SaleState, SaleEvent, string>(
                stateAccessor: sale => sale.State
                , stateMutator: (sale, newState) => sale.State = newState
                , stateFunc: (sale, stringParam) => SaleState.Complete
                , name: "test"
                , priority: 1);

            var testSale = new Sale(saleID: 87)
            {
                State = SaleState.Open
            };
            var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, testSale, request: "request");

            var result = sut.Execute(parameters);

            Assert.Equal(SaleState.Complete, result.CurrentState);
            Assert.Equal(SaleState.Open, result.PreviousState);
        }
        public void Execute_sends_notification_if_new_state_assigned()
        {
            var sut = new StateTransitionDynamicParameterized <Sale, SaleState, SaleEvent, string>(
                stateAccessor: sale => sale.State
                , stateMutator: (sale, newState) => sale.State = newState
                , stateFunc: (sale, stringParam) => 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, request: "request");

            sut.Execute(parameters);

            Assert.True(notificationReceived);
        }
        public void Execute_treats_lack_of_transitions_as_failed_condition()
        {
            var sut = new StateTransitionDynamicParameterized <Sale, SaleState, SaleEvent, string>(
                stateAccessor: sale => sale.State
                , stateMutator: (sale, newState) => sale.State = newState
                , stateFunc: (sale, stringParam) => SaleState.Open
                , name: "test"
                , priority: 1);

            var testSale = new Sale(saleID: 87)
            {
                State = SaleState.Open
            };
            var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, testSale, request: "request");

            var result = sut.Execute(parameters);

            Assert.False(result.ConditionMet);
            Assert.False(result.WasTransitioned);
            Assert.Equal(SaleState.Open, testSale.State);
            Assert.Equal(SaleState.Open, result.CurrentState);
            Assert.Equal(SaleState.Open, result.PreviousState);
        }