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


C# StateMachine.ForceTransition方法代码示例

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


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

示例1: ForcefullyTransitioningFromChildStateMachineCallsExitHandlerOnCurrentState

        public void ForcefullyTransitioningFromChildStateMachineCallsExitHandlerOnCurrentState()
        {
            StateHandlerInfo<State> state22ExitInfo = null;

            var sm = new StateMachine("State Machine");
            var evt1 = new Event("Event 1");
            var state1 = sm.CreateInitialState("State 1");
            var state2 = sm.CreateState("State 2");
            var subSm = state2.CreateChildStateMachine();
            var state21 = subSm.CreateInitialState("State 2.1");
            var state22 = subSm.CreateState("State 2.2").WithExit(i => state22ExitInfo = i);

            state1.TransitionOn(evt1).To(state2);
            state21.TransitionOn(evt1).To(state22);

            // Enter state2, and start child state machine
            evt1.Fire();
            // Enter State 2.2
            evt1.Fire();
            // Transition from state2 to state1, exiting the child state machine
            sm.ForceTransition(state1, evt1);

            Assert.NotNull(state22ExitInfo);
            Assert.AreEqual(state22, state22ExitInfo.From);
            Assert.AreEqual(state1, state22ExitInfo.To);
            Assert.AreEqual(evt1, state22ExitInfo.Event);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:27,代码来源:HandlerOrderTests.cs

示例2: ThrowsIfForcedTransitionToAStateBelongingToAChildStateMachine

 public void ThrowsIfForcedTransitionToAStateBelongingToAChildStateMachine()
 {
     var sm = new StateMachine("State Machine");
     var evt = sm.CreateEvent("Event");
     var state = sm.CreateInitialState("Initial State");
     var subSm = state.CreateChildStateMachine();
     var subState = subSm.CreateInitialState("Child Initial State");
     
     Assert.Throws<InvalidStateTransitionException>(() => sm.ForceTransition(subState, evt));
 }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:10,代码来源:AssertionTests.cs

示例3: TransitionRaisedWhenForcedTransition

        public void TransitionRaisedWhenForcedTransition()
        {
            var sm = new StateMachine("sm");
            var initial = sm.CreateInitialState("initial");
            var state1 = sm.CreateState("state1");
            var evt = new Event("evt");

            TransitionEventArgs<State> ea = null;
            sm.Transition += (o, e) => ea = e;

            sm.ForceTransition(state1, evt);

            Assert.NotNull(ea);
            Assert.AreEqual(initial, ea.From);
            Assert.AreEqual(state1, ea.To);
            Assert.AreEqual(evt, ea.Event);
            Assert.False(ea.IsInnerTransition);
            Assert.AreEqual(EventFireMethod.Fire, ea.EventFireMethod);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:19,代码来源:TransitionNotificationTests.cs

示例4: ForceTransitionCallsSynchronizerForceTransition

        public void ForceTransitionCallsSynchronizerForceTransition()
        {
            var sm = new StateMachine("sm");
            var initial = sm.CreateInitialState("initial");
            var evt = new Event("evt");

            var synchronizer = new Mock<IStateMachineSynchronizer>();
            sm.Synchronizer = synchronizer.Object;

            sm.ForceTransition(initial, evt);

            synchronizer.Verify(x => x.ForceTransition(It.IsAny<Action>()));
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:13,代码来源:StateMachineSynchronizerTests.cs

示例5: ForcedTransitionDoesNotOccurUntilActionInvoked

        public void ForcedTransitionDoesNotOccurUntilActionInvoked()
        {
            var sm = new StateMachine("sm");
            var initial = sm.CreateInitialState("initial");
            var state1 = sm.CreateState("state1");
            var evt = new Event("evt");

            var synchronizer = new Mock<IStateMachineSynchronizer>();
            sm.Synchronizer = synchronizer.Object;

            Action forceAction = null;
            synchronizer.Setup(x => x.ForceTransition(It.IsAny<Action>()))
                .Callback<Action>(a => forceAction = a);

            sm.ForceTransition(state1, evt);

            Assert.AreEqual(initial, sm.CurrentState);
            Assert.NotNull(forceAction);

            forceAction();

            Assert.AreEqual(state1, sm.CurrentState);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:23,代码来源:StateMachineSynchronizerTests.cs

示例6: ForceTransitionIsQueued

        public void ForceTransitionIsQueued()
        {
            var sm = new StateMachine("sm");
            var initial = sm.CreateInitialState("initial");
            var state1 = sm.CreateState("state1");
            var state2 = sm.CreateState("state2");
            var evt = sm.CreateEvent("evt");

            State entryFrom = null;
            state2.EntryHandler = i => entryFrom = i.From;

            initial.TransitionOn(evt).To(state1).WithHandler(i => sm.ForceTransition(state2, evt));

            evt.Fire();

            Assert.AreEqual(state1, entryFrom);
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:17,代码来源:TransitionTests.cs

示例7: ThrowsIfForcedTransitionOnAChildEvent

        public void ThrowsIfForcedTransitionOnAChildEvent()
        {
            var sm = new StateMachine("State Machine");
            var state1 = sm.CreateInitialState("Initial State");
            var state2 = sm.CreateState("State 2");
            var subSm = state1.CreateChildStateMachine();
            var evt = subSm.CreateEvent("Event");

            Assert.Throws<InvalidEventTransitionException>(() => sm.ForceTransition(state2, evt));
        }
开发者ID:modulexcite,项目名称:StateMechanic,代码行数:10,代码来源:AssertionTests.cs

示例8: ForcefullyTransitioningToChildStateMachineCallsEntryHandlerOnInitialState

        public void ForcefullyTransitioningToChildStateMachineCallsEntryHandlerOnInitialState()
        {
            StateHandlerInfo<State> state21EntryInfo = null;

            var sm = new StateMachine("State Machine");
            var evt = new Event("Event");
            var state1 = sm.CreateInitialState("State 1");
            var state2 = sm.CreateState("State 2");
            var subSm = state2.CreateChildStateMachine();
            var state21 = subSm.CreateInitialState("State 2.1").WithEntry(i => state21EntryInfo = i);

            sm.ForceTransition(state2, evt);

            Assert.NotNull(state21EntryInfo);
            Assert.AreEqual(state1, state21EntryInfo.From);
            Assert.AreEqual(state21, state21EntryInfo.To);
            Assert.AreEqual(evt, state21EntryInfo.Event);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:18,代码来源:HandlerOrderTests.cs

示例9: ForcefullyTransitioningToMoreChildStateCallsCorrectHandlers

        public void ForcefullyTransitioningToMoreChildStateCallsCorrectHandlers()
        {
            var log = new List<Tuple<string, StateHandlerInfo<State>>>();

            var sm = new StateMachine("sm");
            var state1 = sm.CreateInitialState("state1");

            var childSm1 = state1.CreateChildStateMachine("childSm1");
            var state11 = childSm1.CreateInitialState("state11");
            var state12 = childSm1.CreateState("state12");

            var childSm11 = state11.CreateChildStateMachine("childsm11");
            var state111 = childSm11.CreateInitialState("state111");
            var state112 = childSm11.CreateState("state112");

            var childSm12 = state12.CreateChildStateMachine("childSm12");
            var state121 = childSm12.CreateInitialState("state121");
            var state122 = childSm12.CreateState("state122");

            var evt = new Event("evt");

            // Start off in state112, forcefully transition to state122
            sm.ForceTransition(state112, evt);

            state1.EntryHandler = x => log.Add(Tuple.Create("state1 Entry", x));
            state1.ExitHandler = x => log.Add(Tuple.Create("state1 Exit", x));

            state11.EntryHandler = x => log.Add(Tuple.Create("state11 Entry", x));
            state11.ExitHandler = x => log.Add(Tuple.Create("state11 Exit", x));

            state111.EntryHandler = x => log.Add(Tuple.Create("state111 Entry", x));
            state111.ExitHandler = x => log.Add(Tuple.Create("state111 Exit", x));

            state112.EntryHandler = x => log.Add(Tuple.Create("state112 Entry", x));
            state112.ExitHandler = x => log.Add(Tuple.Create("state112 Exit", x));

            state12.EntryHandler = x => log.Add(Tuple.Create("state12 Entry", x));
            state12.ExitHandler = x => log.Add(Tuple.Create("state12 Exit", x));

            state121.EntryHandler = x => log.Add(Tuple.Create("state121 Entry", x));
            state121.ExitHandler = x => log.Add(Tuple.Create("state121 Exit", x));

            state122.EntryHandler = x => log.Add(Tuple.Create("state122 Entry", x));
            state122.ExitHandler = x => log.Add(Tuple.Create("state122 Exit", x));

            sm.ForceTransition(state122, evt);

            Assert.AreEqual(6, log.Count);

            Assert.AreEqual("state112 Exit", log[0].Item1);
            Assert.AreEqual(evt, log[0].Item2.Event);
            Assert.AreEqual(state112, log[0].Item2.From);
            Assert.AreEqual(state12, log[0].Item2.To);

            Assert.AreEqual("state11 Exit", log[1].Item1);
            Assert.AreEqual(evt, log[1].Item2.Event);
            Assert.AreEqual(state11, log[1].Item2.From);
            Assert.AreEqual(state12, log[1].Item2.To);

            Assert.AreEqual("state12 Entry", log[2].Item1);
            Assert.AreEqual(evt, log[2].Item2.Event);
            Assert.AreEqual(state11, log[2].Item2.From);
            Assert.AreEqual(state12, log[2].Item2.To);

            Assert.AreEqual("state121 Entry", log[3].Item1);
            Assert.AreEqual(evt, log[3].Item2.Event);
            Assert.AreEqual(state11, log[3].Item2.From);
            Assert.AreEqual(state121, log[3].Item2.To);

            Assert.AreEqual("state121 Exit", log[4].Item1);
            Assert.AreEqual(evt, log[4].Item2.Event);
            Assert.AreEqual(state121, log[4].Item2.From);
            Assert.AreEqual(state122, log[4].Item2.To);

            Assert.AreEqual("state122 Entry", log[5].Item1);
            Assert.AreEqual(evt, log[5].Item2.Event);
            Assert.AreEqual(state121, log[5].Item2.From);
            Assert.AreEqual(state122, log[5].Item2.To);
        }
开发者ID:canton7,项目名称:StateMechanic,代码行数:79,代码来源:HandlerOrderTests.cs

示例10: ForceTransitionThrowsIfToStateIsNull

 public void ForceTransitionThrowsIfToStateIsNull()
 {
     var sm = new StateMachine();
     var evt = new Event("evt");
     Assert.Throws<ArgumentNullException>(() => sm.ForceTransition(null, evt));
 }
开发者ID:canton7,项目名称:StateMechanic,代码行数:6,代码来源:AssertionTests.cs

示例11: ForceTransitionThrowsIfEventIsNull

 public void ForceTransitionThrowsIfEventIsNull()
 {
     var sm = new StateMachine();
     var state1 = sm.CreateInitialState("state1");
     Assert.Throws<ArgumentNullException>(() => sm.ForceTransition(state1, null));
 }
开发者ID:canton7,项目名称:StateMechanic,代码行数:6,代码来源:AssertionTests.cs


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