public void AddReentryAction_throws_InvalidOperationException_if_already_set()
        {
            var stateMachine = new StateMachineAsync <Sale, SaleState, SaleEvent>(sale => sale.State, (sale, newState) => sale.State = newState);
            var sut          = new StateConfigurationAsync <Sale, SaleState, SaleEvent>(SaleState.ChangeDue, stateMachine);

            sut.AddReentryAction((sale, _) => Task.CompletedTask);

            Assert.Throws <InvalidOperationException>(() => sut.AddReentryAction((sale, _) => Task.CompletedTask));
        }
        public async Task ExecuteReentryActionAsync_executes_ReentryAction()
        {
            var sale = new Sale(saleID: 96)
            {
                State = SaleState.Open
            };
            var transitionResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.AddItem
                                                                                    , SaleState.Open
                                                                                    , SaleState.Open
                                                                                    , SaleState.Open
                                                                                    , "lastTransitionName");
            var stateMachine   = new StateMachineAsync <Sale, SaleState, SaleEvent>(sale1 => sale1.State, (sale1, newState) => sale1.State = newState);
            var openState      = new StateConfigurationAsync <Sale, SaleState, SaleEvent>(SaleState.Open, stateMachine);
            var changeDueState = new StateConfigurationAsync <Sale, SaleState, SaleEvent>(SaleState.ChangeDue, stateMachine);

            changeDueState.AddSuperstate(openState);
            var changeDueEntryActionFromOpenFired = false;

            changeDueState.AddReentryAction((sale1, _) => { changeDueEntryActionFromOpenFired = true; return(Task.CompletedTask); });
            var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale);

            await changeDueState.ExecuteReentryActionAsync(parameters, transitionResult);

            Assert.True(changeDueEntryActionFromOpenFired);
        }
        public void AddReentryAction_throws_ArgumentNullException_if_Action_null()
        {
            var stateMachine = new StateMachineAsync <Sale, SaleState, SaleEvent>(sale => sale.State, (sale, newState) => sale.State = newState);
            var sut          = new StateConfigurationAsync <Sale, SaleState, SaleEvent>(SaleState.ChangeDue, stateMachine);

            Assert.Throws <ArgumentNullException>(() => sut.AddReentryAction(action: null));
        }