当前位置: 首页>>代码示例>>C#>>正文


C# StateMachine.AddGlobalTransition方法代码示例

本文整理汇总了C#中StateMachine.AddGlobalTransition方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.AddGlobalTransition方法的具体用法?C# StateMachine.AddGlobalTransition怎么用?C# StateMachine.AddGlobalTransition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StateMachine的用法示例。


在下文中一共展示了StateMachine.AddGlobalTransition方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Trigger

        public void StateMachine_AddGlobalTransition_TwoTransitionsWithSameTriggerFromToNoGuard_ThrowsDuplicateTransitionException()
        {
            var machine = new StateMachine<StubStateModel>();
            var state2 = new State<StubStateModel>("s2");
            var trigger1 = new Trigger("t1");
            var transition1 = new Transition<StubStateModel>(trigger1, null, state2);
            var transition2 = new Transition<StubStateModel>(trigger1, null, state2);

            machine.AddGlobalTransition(transition1);
            Assert.Throws<InvalidTransitionException>(() =>
                machine.AddGlobalTransition(transition2));
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:12,代码来源:StateMachineTests.cs

示例2: StateMachine_AddGlobalTransition_SourceNonNull_ThrowsInvalidTransEx

        public void StateMachine_AddGlobalTransition_SourceNonNull_ThrowsInvalidTransEx()
        {
            var machine = new StateMachine<StubStateModel>();
            var state1 = new State<StubStateModel>("s1");
            var state2 = new State<StubStateModel>("s2");
            var trigger1 = new Trigger("t1");
            var transition1 = new Transition<StubStateModel>(trigger1, state1, state2);

            Assert.Throws<InvalidTransitionException>(() =>
                machine.AddGlobalTransition(transition1));
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:11,代码来源:StateMachineTests.cs

示例3: StateMachine_AddGlobalTransition_TwoValidTranSameTrigger_ReturnsBothWithTransitionsOn

        public void StateMachine_AddGlobalTransition_TwoValidTranSameTrigger_ReturnsBothWithTransitionsOn()
        {
            var machine = new StateMachine<StubStateModel>();
            var state2 = new State<StubStateModel>("s2");
            var state3 = new State<StubStateModel>("s2");
            var trigger1 = new Trigger("t1");
            var transition1 = new Transition<StubStateModel>(trigger1, null, state2, m => 1 == 2);
            var transition2 = new Transition<StubStateModel>(trigger1, null, state3, m => 1 == 1);

            machine.AddGlobalTransition(transition1);
            machine.AddGlobalTransition(transition2);

            var trans = machine.GlobalTransitionsOn(trigger1).ToList();
            Assert.Equal(transition1, trans[0]);
            Assert.Equal(transition2, trans[1]);
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:16,代码来源:StateMachineTests.cs

示例4: StateMachine_AddGlobalTransition_TwoValidTranDiffTriggers_ReturnsOneForEachTransitionsOn

        public void StateMachine_AddGlobalTransition_TwoValidTranDiffTriggers_ReturnsOneForEachTransitionsOn()
        {
            var machine = new StateMachine<StubStateModel>();
            var state2 = new State<StubStateModel>("s2");
            var state3 = new State<StubStateModel>("s2");
            var trigger1 = new Trigger("t1");
            var trigger2 = new Trigger("t2");
            var transition1 = new Transition<StubStateModel>(trigger1, null, state2, m => 1 == 2);
            var transition2 = new Transition<StubStateModel>(trigger2, null, state3, m => 1 == 1);

            machine.AddGlobalTransition(transition1);
            machine.AddGlobalTransition(transition2);

            Assert.Same(transition1, machine.GlobalTransitionsOn(trigger1).FirstOrDefault());
            Assert.Same(transition2, machine.GlobalTransitionsOn(trigger2).FirstOrDefault());
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:16,代码来源:StateMachineTests.cs

示例5: StateMachine_Trigger_ValidTriggerAndTrans_ChoosesFirstTranWthPassGuard_SameAsCurrentState_NoRaised

        public void StateMachine_Trigger_ValidTriggerAndTrans_ChoosesFirstTranWthPassGuard_SameAsCurrentState_NoRaised()
        {
            var model = new StubStateModel();
            var machine = new StateMachine<StubStateModel>();
            TransitionEventArgs<StubStateModel> transitioningArgs = null;
            machine.Transitioning += (s, e) => { transitioningArgs = e; };
            TransitionEventArgs<StubStateModel> transitionedArgs = null;
            machine.Transitioned += (s, e) => { transitionedArgs = e; };

            var trigger1 = new Trigger("t1");
            var trigger2 = new Trigger("t2");

            var state1Mock = new Mock<State<StubStateModel>>("s1");
            var state2Mock = new Mock<State<StubStateModel>>("s2");
            var state3Mock = new Mock<State<StubStateModel>>("s3");
            var state4Mock = new Mock<State<StubStateModel>>("s4");

            var state1 = state1Mock.Object;
            var state2 = state2Mock.Object;
            var state3 = state3Mock.Object;
            var state4 = state4Mock.Object;

            var statetrans1 = new Transition<StubStateModel>(trigger1, state1, state2, m => 1 == 2);
            var statetrans2 = new Transition<StubStateModel>(trigger1, state1, state3, m => 1 == 3);
            var statetrans3 = new Transition<StubStateModel>(trigger2, state1, state3);

            var globaltrans1 = new Transition<StubStateModel>(trigger1, null, state1, m => 1 == 1);

            machine.AddGlobalTransition(globaltrans1);
            state1.AddTransition(statetrans1);
            state1.AddTransition(statetrans2);
            state1.AddTransition(statetrans3);

            model.CurrentState = state1;

            // so when trigger1 is triggered on state model whose current state is state1,
            // it will fall through to the first matching transition with a passing guard, the global transition to state 1
            // but since this is same state as current state, it shouldn't actually transition.  no events should be called.

            machine.Trigger(trigger1, model);

            // verify that no transition events were calledb
            state1Mock.Verify(s =>
                s.RaiseEntered(
                    It.IsAny<StubStateModel>(),
                    It.IsAny<State<StubStateModel>>(),
                    It.IsAny<Trigger>()), Times.Never());
            state1Mock.Verify(s =>
                s.RaiseExiting(
                    It.IsAny<StubStateModel>(),
                    It.IsAny<State<StubStateModel>>(),
                    It.IsAny<Trigger>()), Times.Never());
            Assert.Null(transitioningArgs);
            Assert.Null(transitionedArgs);
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:55,代码来源:StateMachineTests.cs

示例6: StateMachine_Trigger_ValidTriggerAndTrans_ChoosesFirstTranWthPassGuard_DiffAsCurrentState_Raised_Sets

        public void StateMachine_Trigger_ValidTriggerAndTrans_ChoosesFirstTranWthPassGuard_DiffAsCurrentState_Raised_Sets()
        {
            var model = new StubStateModel();
            var machine = new StateMachine<StubStateModel>();

            var transitioningEventArgs = new List<TransitionEventArgs<StubStateModel>>();
            machine.Transitioning += (s, e) => { transitioningEventArgs.Add(e); };

            var transitionedEventArgs = new List<TransitionEventArgs<StubStateModel>>();
            machine.Transitioned += (s, e) => { transitionedEventArgs.Add(e); };

            var trigger1 = new Trigger("t1");
            var trigger2 = new Trigger("t2");

            var state1Mock = new Mock<State<StubStateModel>>("s1");
            var state2Mock = new Mock<State<StubStateModel>>("s2");
            var state3Mock = new Mock<State<StubStateModel>>("s3");
            var state4Mock = new Mock<State<StubStateModel>>("s4");

            var state1 = state1Mock.Object;
            var state2 = state2Mock.Object;
            var state3 = state3Mock.Object;
            var state4 = state4Mock.Object;

            var statetrans1 = new Transition<StubStateModel>(trigger1, state1, state2, m => 1 == 2);
            var statetrans2 = new Transition<StubStateModel>(trigger1, state1, state3, m => 1 == 3);
            var statetrans3 = new Transition<StubStateModel>(trigger2, state1, state3);

            var globaltrans1 = new Transition<StubStateModel>(trigger1, null, state2, m => 1 == 1);

            machine.AddGlobalTransition(globaltrans1);
            state1.AddTransition(statetrans1);
            state1.AddTransition(statetrans2);
            state1.AddTransition(statetrans3);

            model.CurrentState = state1;

            // so when trigger 1 is triggered on state model whose current state is state1,
            // it will fall through to the first maching transition with a passing guard, the global transition to state 2
            // it will then transition to state2.

            // make sure that transition events are called for moving from state 1 to state 2
            state1Mock.Setup(s => s.RaiseExiting(model, state2, trigger1)).Verifiable();
            state2Mock.Setup(s => s.RaiseEntered(model, state1, trigger1)).Verifiable();

            machine.Trigger(trigger1, model);

            // verify that no transition events were called that shouldn't have been
            state1Mock.Verify(s =>
                s.RaiseEntered(
                    It.IsAny<StubStateModel>(),
                    It.IsAny<State<StubStateModel>>(),
                    It.IsAny<Trigger>()), Times.Never());
            state2Mock.Verify(s =>
                s.RaiseExiting(
                    It.IsAny<StubStateModel>(),
                    It.IsAny<State<StubStateModel>>(),
                    It.IsAny<Trigger>()), Times.Never());
            Assert.Equal(1, transitioningEventArgs.Count);
            Assert.Equal(1, transitionedEventArgs.Count);

            Assert.Equal(state1, transitioningEventArgs[0].From);
            Assert.Equal(state2, transitioningEventArgs[0].To);
            Assert.Equal(trigger1, transitioningEventArgs[0].Trigger);
            Assert.Equal(model, transitioningEventArgs[0].Model);
            Assert.Equal(state1, transitionedEventArgs[0].From);
            Assert.Equal(state2, transitionedEventArgs[0].To);
            Assert.Equal(trigger1, transitionedEventArgs[0].Trigger);
            Assert.Equal(model, transitionedEventArgs[0].Model);
            Assert.Equal(state2, model.CurrentState);
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:71,代码来源:StateMachineTests.cs

示例7: StateMachine_GlobalTransitionsOn_TriggerMatchingTwoTransitionsNotAnother_ReturnsTwoMatching

        public void StateMachine_GlobalTransitionsOn_TriggerMatchingTwoTransitionsNotAnother_ReturnsTwoMatching()
        {
            var machine = new StateMachine<StubStateModel>();
            var state2 = new State<StubStateModel>("s2");
            var state3 = new State<StubStateModel>("s2");
            var trigger1 = new Trigger("t1");
            var transition1 = new Transition<StubStateModel>(trigger1, null, state2, m => 1 == 2);
            var transition2 = new Transition<StubStateModel>(trigger1, null, state3, m => 1 == 1);

            machine.AddGlobalTransition(transition1);
            machine.AddGlobalTransition(transition2);

            var result = machine.GlobalTransitionsOn(new Trigger("t1"));
            Assert.NotNull(result);
            Assert.Equal(2, result.Count());
            Assert.Same(transition1, result.ToList()[0]);
            Assert.Same(transition2, result.ToList()[1]);
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:18,代码来源:StateMachineTests.cs

示例8: StateMachine_GlobalTransitionsOn_TriggerMatchingOneTransitionNotAnother_ReturnsOnlyMatchingONe

        public void StateMachine_GlobalTransitionsOn_TriggerMatchingOneTransitionNotAnother_ReturnsOnlyMatchingONe()
        {
            var machine = new StateMachine<StubStateModel>();
            var state2 = new State<StubStateModel>("s2");
            var trigger1 = new Trigger("t1");
            var transition1 = new Transition<StubStateModel>(trigger1, null, state2, m => 1 == 2);

            machine.AddGlobalTransition(transition1);

            var result = machine.GlobalTransitionsOn(new Trigger("t1"));
            Assert.NotNull(result);
            Assert.Equal(1, result.Count());
            Assert.Same(transition1, result.FirstOrDefault());
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:14,代码来源:StateMachineTests.cs

示例9: StateMachine_AvailableTriggers_ConcatsModelsTransWithGlobal_ReturnsDistinctTrigsByName

        public void StateMachine_AvailableTriggers_ConcatsModelsTransWithGlobal_ReturnsDistinctTrigsByName()
        {
            var model = new StubStateModel();
            var machine = new StateMachine<StubStateModel>();

            var trigger1 = new Trigger("t1");
            var trigger2 = new Trigger("t2");

            var state1 = new State<StubStateModel>("s1");
            var state2 = new State<StubStateModel>("s2");
            var state3 = new State<StubStateModel>("s3");
            var state4 = new State<StubStateModel>("s4");

            var statetrans1 = new Transition<StubStateModel>(trigger1, state1, state2);
            var statetrans2 = new Transition<StubStateModel>(trigger1, state1, state3);
            var statetrans3 = new Transition<StubStateModel>(trigger2, state1, state3);

            var globaltrans1 = new Transition<StubStateModel>(trigger2, null, state1);

            machine.AddGlobalTransition(globaltrans1);
            state1.AddTransition(statetrans1);
            state1.AddTransition(statetrans2);
            state1.AddTransition(statetrans3);

            model.CurrentState = state1;

            var result = machine.AvailableTriggers(model);

            Assert.Equal(2, result.Count());
            Assert.Equal(trigger1, result.ToList()[0]);
            Assert.Equal(trigger2, result.ToList()[1]);
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:32,代码来源:StateMachineTests.cs

示例10: StateMachine_AddGlobalTransition_ValidTran_ReturnsWithTransitionsOnTrigger

        public void StateMachine_AddGlobalTransition_ValidTran_ReturnsWithTransitionsOnTrigger()
        {
            var machine = new StateMachine<StubStateModel>();
            var state2 = new State<StubStateModel>("s2");
            var trigger1 = new Trigger("t1");
            var transition1 = new Transition<StubStateModel>(trigger1, null, state2);

            machine.AddGlobalTransition(transition1);

            Assert.Same(transition1, machine.GlobalTransitionsOn(trigger1).FirstOrDefault());
        }
开发者ID:mmonteleone,项目名称:nate,代码行数:11,代码来源:StateMachineTests.cs


注:本文中的StateMachine.AddGlobalTransition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。