public void Start(
            PassiveStateMachine <int, int> machine,
            bool entryActionExecuted,
            CurrentStateExtension currentStateExtension)
        {
            "establish a state machine".x(() =>
            {
                var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>();
                stateMachineDefinitionBuilder
                .In(TestState)
                .ExecuteOnEntry(() => entryActionExecuted = true);
                machine = stateMachineDefinitionBuilder
                          .WithInitialState(TestState)
                          .Build()
                          .CreatePassiveStateMachine();

                currentStateExtension = new CurrentStateExtension();
                machine.AddExtension(currentStateExtension);
            });

            "when starting the state machine".x(() =>
                                                machine.Start());

            "should set current state of state machine to state to which it is initialized".x(() =>
                                                                                              currentStateExtension.CurrentState.Should().Be(TestState));

            "should execute entry action of state to which state machine is initialized".x(() =>
                                                                                           entryActionExecuted.Should().BeTrue());
        }
示例#2
0
        public void OtherwiseGuard(
            PassiveStateMachine <int, int> machine,
            CurrentStateExtension currentStateExtension)
        {
            "establish a state machine with otherwise guard and no matching other guard".x(() =>
            {
                var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>();
                stateMachineDefinitionBuilder
                .In(SourceState)
                .On(Event)
                .If(() => false).Goto(ErrorState)
                .Otherwise().Goto(DestinationState);
                machine = stateMachineDefinitionBuilder
                          .WithInitialState(SourceState)
                          .Build()
                          .CreatePassiveStateMachine();

                currentStateExtension = new CurrentStateExtension();
                machine.AddExtension(currentStateExtension);

                machine.Start();
            });

            "when an event is fired".x(() =>
                                       machine.Fire(Event));

            "it should_take_transition_guarded_with_otherwise".x(() =>
                                                                 currentStateExtension.CurrentState.Should().Be(DestinationState));
        }
        public void InitializationInSuperState(
            PassiveStateMachine <int, int> machine,
            CurrentStateExtension testExtension,
            bool entryActionOfLeafStateExecuted,
            bool entryActionOfSuperStateExecuted)
        {
            "establish a hierarchical state machine with super state as initial state".x(() =>
            {
                var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>();
                stateMachineDefinitionBuilder
                .DefineHierarchyOn(SuperState)
                .WithHistoryType(HistoryType.None)
                .WithInitialSubState(LeafState);
                stateMachineDefinitionBuilder
                .In(SuperState)
                .ExecuteOnEntry(() => entryActionOfSuperStateExecuted = true);
                stateMachineDefinitionBuilder
                .In(LeafState)
                .ExecuteOnEntry(() => entryActionOfLeafStateExecuted = true);
                machine = stateMachineDefinitionBuilder
                          .WithInitialState(SuperState)
                          .Build()
                          .CreatePassiveStateMachine();

                testExtension = new CurrentStateExtension();
                machine.AddExtension(testExtension);
            });

            "when initializing to a super state and starting the state machine".x(() =>
            {
                machine.Start();
            });

            "it should_set_current_state_of_state_machine_to_initial_leaf_state_of_the_state_to_which_it_is_initialized".x(() =>
                                                                                                                           testExtension.CurrentState
                                                                                                                           .Should().Be(LeafState));

            "it should_execute_entry_action_of_super_state_to_which_state_machine_is_initialized".x(() =>
                                                                                                    entryActionOfSuperStateExecuted
                                                                                                    .Should().BeTrue());

            "it should_execute_entry_actions_of_initial_sub_states_until_a_leaf_state_is_reached".x(() =>
                                                                                                    entryActionOfLeafStateExecuted
                                                                                                    .Should().BeTrue());
        }
        public void InitializationInLeafState(
            PassiveStateMachine <int, int> machine,
            CurrentStateExtension testExtension,
            bool entryActionOfLeafStateExecuted,
            bool entryActionOfSuperStateExecuted)
        {
            "establish a hierarchical state machine with leaf state as initial state".x(() =>
            {
                var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>();
                stateMachineDefinitionBuilder
                .DefineHierarchyOn(SuperState)
                .WithHistoryType(HistoryType.None)
                .WithInitialSubState(LeafState);
                stateMachineDefinitionBuilder
                .In(SuperState)
                .ExecuteOnEntry(() => entryActionOfSuperStateExecuted = true);
                stateMachineDefinitionBuilder
                .In(LeafState)
                .ExecuteOnEntry(() => entryActionOfLeafStateExecuted = true);
                machine = stateMachineDefinitionBuilder
                          .WithInitialState(LeafState)
                          .Build()
                          .CreatePassiveStateMachine();

                testExtension = new CurrentStateExtension();
                machine.AddExtension(testExtension);
            });

            "when starting the state machine".x(() =>
            {
                machine.Start();
            });

            "it should set current state of state machine to state to which it is initialized".x(() =>
                                                                                                 testExtension.CurrentState
                                                                                                 .Should().Be(LeafState));

            "it should execute entry action of state to which state machine is initialized".x(() =>
                                                                                              entryActionOfLeafStateExecuted
                                                                                              .Should().BeTrue());

            "it should execute entry action of super states of the state to which state machine is initialized".x(() =>
                                                                                                                  entryActionOfSuperStateExecuted
                                                                                                                  .Should().BeTrue());
        }