コード例 #1
0
ファイル: Guards.cs プロジェクト: yonglehou/statemachine
        public void NoMatchingGuard(
            PassiveStateMachine <int, int> machine,
            CurrentStateExtension currentStateExtension)
        {
            bool declined = false;

            "establish state machine with no matching guard"._(() =>
            {
                machine = new PassiveStateMachine <int, int>();

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

                machine.In(SourceState)
                .On(Event)
                .If(() => false).Goto(ErrorState);

                machine.TransitionDeclined += (sender, e) => declined = true;

                machine.Initialize(SourceState);
                machine.Start();
            });

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

            "it should notify about declined transition"._(() =>
                                                           declined.Should().BeTrue("TransitionDeclined event should be fired"));
        }
コード例 #2
0
ファイル: Guards.cs プロジェクト: yonglehou/statemachine
        public void MatchingGuard(
            PassiveStateMachine <int, int> machine,
            CurrentStateExtension currentStateExtension)
        {
            "establish a state machine with guarded transitions"._(() =>
            {
                machine = new PassiveStateMachine <int, int>();

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

                machine.In(SourceState)
                .On(Event)
                .If(() => false).Goto(ErrorState)
                .If(() => true).Goto(DestinationState)
                .If(() => true).Goto(ErrorState)
                .Otherwise().Goto(ErrorState);

                machine.Initialize(SourceState);
                machine.Start();
            });

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

            "it should take transition guarded with first matching guard"._(() =>
                                                                            currentStateExtension.CurrentState.Should().Be(DestinationState));
        }
コード例 #3
0
ファイル: Guards.cs プロジェクト: yonglehou/statemachine
        public void OtherwiseGuard(
            PassiveStateMachine <int, int> machine,
            CurrentStateExtension currentStateExtension)
        {
            "establish a state machine with otherwise guard and no machting other guard"._(() =>
            {
                machine = new PassiveStateMachine <int, int>();

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

                machine.In(SourceState)
                .On(Event)
                .If(() => false).Goto(ErrorState)
                .Otherwise().Goto(DestinationState);

                machine.Initialize(SourceState);
                machine.Start();
            });

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

            "it should_take_transition_guarded_with_otherwise"._(() =>
                                                                 currentStateExtension.CurrentState.Should().Be(DestinationState));
        }
コード例 #4
0
        public void Background()
        {
            "establish a hierarchical state machine"._(() =>
            {
                testExtension = new CurrentStateExtension();

                machine = new PassiveStateMachine <int, int>();

                machine.AddExtension(testExtension);

                machine.DefineHierarchyOn(SuperState)
                .WithHistoryType(HistoryType.None)
                .WithInitialSubState(LeafState);

                machine.In(SuperState)
                .ExecuteOnEntry(() => entryActionOfSuperStateExecuted = true);
                machine.In(LeafState)
                .ExecuteOnEntry(() => entryActionOfLeafStateExecuted = true);
            });
        }