public async Task ExecuteEntryActionAsync_does_not_execute_if_cancelled()
        {
            var sale = new Sale(saleId: 96)
            {
                State = SaleState.ChangeDue
            };
            var transitionResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay
                                                                                    , SaleState.Open
                                                                                    , SaleState.Open
                                                                                    , SaleState.ChangeDue
                                                                                    , "lastTransitionName");
            var stateMachine             = new StateMachine <Sale, SaleState, SaleEvent>(sale1 => sale1.State, (sale1, newState) => sale1.State = newState);
            var sut                      = new StateConfiguration <Sale, SaleState, SaleEvent>(SaleState.ChangeDue, stateMachine);
            var entryActionFromOpenFired = false;

            sut.AddEntryAction((sale1, _) => { entryActionFromOpenFired = true; return(Task.CompletedTask); });

            using var cancelSource = new CancellationTokenSource();
            var parameters = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale, cancelSource.Token);

            cancelSource.Cancel();

            await sut.ExecuteEntryActionAsync(parameters, transitionResult);

            Assert.False(entryActionFromOpenFired);
        }
        public async Task ExecuteEntryActionAsync_executes_for_super_state()
        {
            var entryActionCalled = false;
            var stateMachine      = new StateMachine <Sale, SaleState, SaleEvent>(sale1 => sale1.State, (sale1, newState) => sale1.State = newState);
            var openConfig        = new StateConfiguration <Sale, SaleState, SaleEvent>(SaleState.Open, stateMachine);

            openConfig.AddEntryAction((sale1, _) => { entryActionCalled = true; return(Task.CompletedTask); });
            var changeDueConfig = new StateConfiguration <Sale, SaleState, SaleEvent>(SaleState.ChangeDue, stateMachine);

            changeDueConfig.MakeSubStateOf(openConfig);
            var sale = new Sale(saleId: 96)
            {
                State = SaleState.ChangeDue
            };
            var parameters       = new ExecutionParameters <Sale, SaleEvent>(SaleEvent.Pay, sale);
            var transitionResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay
                                                                                    , SaleState.Open
                                                                                    , SaleState.Complete
                                                                                    , SaleState.ChangeDue
                                                                                    , "lastTransitionName");

            await changeDueConfig.ExecuteEntryActionAsync(parameters, transitionResult);

            Assert.True(entryActionCalled);
        }
        public async Task ExecuteEntryActionAsync_executes_EntryAction_without_previous_state()
        {
            var sale = new Sale(saleId: 96)
            {
                State = SaleState.ChangeDue
            };
            var transitionResult = new StateTransitionResult <SaleState, SaleEvent>(SaleEvent.Pay
                                                                                    , SaleState.Open
                                                                                    , SaleState.Open
                                                                                    , SaleState.ChangeDue
                                                                                    , "lastTransitionName");
            var stateMachine             = new StateMachine <Sale, SaleState, SaleEvent>(sale1 => sale1.State, (sale1, newState) => sale1.State = newState);
            var sut                      = new StateConfiguration <Sale, SaleState, SaleEvent>(SaleState.ChangeDue, stateMachine);
            var entryActionFromOpenFired = false;

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

            await sut.ExecuteEntryActionAsync(parameters, transitionResult);

            Assert.True(entryActionFromOpenFired);
        }