本文整理汇总了C#中StateMechanic.StateMachine.CreateEvent方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.CreateEvent方法的具体用法?C# StateMachine.CreateEvent怎么用?C# StateMachine.CreateEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMechanic.StateMachine
的用法示例。
在下文中一共展示了StateMachine.CreateEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CurrentChildStateReflectsCurrentStateOfChild
public void CurrentChildStateReflectsCurrentStateOfChild()
{
var sm = new StateMachine("state machine");
var initialState = sm.CreateInitialState("initial state");
var state1 = sm.CreateState("state1");
var childSm = state1.CreateChildStateMachine();
var childInitialState = childSm.CreateInitialState("childInitialState");
var childState1 = childSm.CreateState("childState1");
var evt = sm.CreateEvent("evt");
var evt2 = sm.CreateEvent("evt2");
initialState.TransitionOn(evt).To(state1);
childInitialState.TransitionOn(evt).To(childState1);
state1.TransitionOn(evt2).To(initialState);
Assert.AreEqual(initialState, sm.CurrentChildState);
evt.Fire();
Assert.AreEqual(childInitialState, sm.CurrentChildState);
evt.Fire();
Assert.AreEqual(childState1, sm.CurrentChildState);
evt2.Fire();
Assert.AreEqual(initialState, sm.CurrentChildState);
}
示例2: RecursiveFireDoesNotThrowIfTransitionNotFound
public void RecursiveFireDoesNotThrowIfTransitionNotFound()
{
var sm = new StateMachine("sm");
var initialState = sm.CreateInitialState("initialState");
var state1 = sm.CreateState("state1");
var evt = sm.CreateEvent("evt");
var evt2 = sm.CreateEvent("evt2");
initialState.TransitionOn(evt).To(state1).WithHandler(i => Assert.DoesNotThrow(() => evt2.Fire()));
try { evt.TryFire(); } catch { }
}
示例3: OuterEventTryFireReturnsTrueIfRecursiveTransitionNotFoundAndFiredWithTryFire
public void OuterEventTryFireReturnsTrueIfRecursiveTransitionNotFoundAndFiredWithTryFire()
{
var sm = new StateMachine("sm");
var initialState = sm.CreateInitialState("initialState");
var state1 = sm.CreateState("state1");
var evt = sm.CreateEvent("evt");
var evt2 = sm.CreateEvent("evt2");
initialState.TransitionOn(evt).To(state1).WithHandler(i => evt2.TryFire());
Assert.True(evt.TryFire());
}
示例4: OuterEventFireThrowsIfRecursiveTransitionNotFound
public void OuterEventFireThrowsIfRecursiveTransitionNotFound()
{
var sm = new StateMachine("sm");
var initialState = sm.CreateInitialState("initialState");
var state1 = sm.CreateState("state1");
var evt = sm.CreateEvent("evt");
var evt2 = sm.CreateEvent("evt2");
initialState.TransitionOn(evt).To(state1).WithHandler(i => evt2.Fire());
var e = Assert.Throws<TransitionNotFoundException>(() => evt.Fire());
Assert.AreEqual(state1, e.From);
Assert.AreEqual(evt2, e.Event);
Assert.AreEqual(sm, e.StateMachine);
}
示例5: IndicatesWhetherInState
public void IndicatesWhetherInState()
{
var sm = new StateMachine("State Machine");
var state1 = sm.CreateInitialState("State 1");
var state2 = sm.CreateState("State 2");
var state3 = sm.CreateState("State 3");
var evt = sm.CreateEvent("Event");
var group1 = new StateGroup("Group 1");
var group2 = new StateGroup("Group 2");
state1.AddToGroup(group1);
state2.AddToGroup(group2);
state3.AddToGroup(group2);
state1.TransitionOn(evt).To(state2);
state2.TransitionOn(evt).To(state3);
Assert.True(group1.IsCurrent);
Assert.False(group2.IsCurrent);
evt.Fire();
Assert.False(group1.IsCurrent);
Assert.True(group2.IsCurrent);
evt.Fire();
Assert.False(group1.IsCurrent);
Assert.True(group2.IsCurrent);
}
示例6: TransitionRaisedWhenTransitionOnChild
public void TransitionRaisedWhenTransitionOnChild()
{
var sm = new StateMachine("sm");
var initial = sm.CreateInitialState("initial");
var child = initial.CreateChildStateMachine();
var childInitial = child.CreateInitialState("childInitial");
var childState1 = child.CreateState("childState1");
var evt = sm.CreateEvent("evt");
childInitial.TransitionOn(evt).To(childState1);
TransitionEventArgs<State> ea = null;
sm.Transition += (o, e) =>
{
ea = e;
};
evt.Fire();
Assert.NotNull(ea);
Assert.AreEqual(childInitial, ea.From);
Assert.AreEqual(childState1, ea.To);
Assert.AreEqual(evt, ea.Event);
Assert.False(ea.IsInnerTransition);
}
示例7: TryFireReturnsFalseIfTransitionNotFound
public void TryFireReturnsFalseIfTransitionNotFound()
{
var sm = new StateMachine("sm");
var initialState = sm.CreateInitialState("initialState");
var evt = sm.CreateEvent("evt");
Assert.False(evt.TryFire());
}
示例8: 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));
}
示例9: EventFireInTransitionHandlerIsQueued
public void EventFireInTransitionHandlerIsQueued()
{
var sm = new StateMachine("sm");
var initial = sm.CreateInitialState("initial");
var state1 = sm.CreateState("state1");
var state2 = sm.CreateState("state2");
var state3 = sm.CreateState("state3");
var evt = sm.CreateEvent("evt");
var evt2 = sm.CreateEvent("evt2");
initial.TransitionOn(evt).To(state1).WithHandler(i => evt2.Fire());
initial.TransitionOn(evt2).To(state2);
state1.TransitionOn(evt2).To(state3);
evt.Fire();
Assert.AreEqual(state3, sm.CurrentState);
}
示例10: DoesNotThrowIfParentEventUsedInChildStateMachine
public void DoesNotThrowIfParentEventUsedInChildStateMachine()
{
var sm = new StateMachine("State Machine");
var state = sm.CreateInitialState("Initial State");
var subSm = state.CreateChildStateMachine();
var subState = subSm.CreateInitialState("Child Initial State");
var evt = sm.CreateEvent("Event");
Assert.DoesNotThrow(() => subState.TransitionOn(evt).To(subState));
}
示例11: FireThrowsIfTransitionNotFound
public void FireThrowsIfTransitionNotFound()
{
var sm = new StateMachine("sm");
var initialState = sm.CreateInitialState("initialState");
var evt = sm.CreateEvent("evt");
var e = Assert.Throws<TransitionNotFoundException>(() => evt.Fire());
Assert.AreEqual(initialState, e.From);
Assert.AreEqual(evt, e.Event);
Assert.AreEqual(sm, e.StateMachine);
}
示例12: NormalSelfTransitionShouldFireExitAndEntry
public void NormalSelfTransitionShouldFireExitAndEntry()
{
var events = new List<string>();
var sm = new StateMachine("State Machine");
var evt = sm.CreateEvent("Event");
var state1 = sm.CreateInitialState("State 1").WithEntry(i => events.Add("State 1 Entry")).WithExit(i => events.Add("State 1 Exit"));
state1.TransitionOn(evt).To(state1).WithHandler(i => events.Add("Transition 1 1"));
evt.Fire();
Assert.That(events, Is.EquivalentTo(new[] { "State 1 Exit", "Transition 1 1", "State 1 Entry" }));
}
示例13: ThrowsIfChildStateUsedInParentStateMachine
public void ThrowsIfChildStateUsedInParentStateMachine()
{
var sm = new StateMachine("State Machine");
var state = sm.CreateInitialState("Initial State");
var subSm = state.CreateChildStateMachine();
var subState = subSm.CreateInitialState("Child Initial State");
var evt = sm.CreateEvent("Event");
var e = Assert.Throws<InvalidStateTransitionException>(() => state.TransitionOn(evt).To(subState));
Assert.AreEqual(state, e.From);
Assert.AreEqual(subState, e.To);
}
示例14: InnerSelfTransitionOnEventTShouldNotFireExitAndEntry
public void InnerSelfTransitionOnEventTShouldNotFireExitAndEntry()
{
var events = new List<string>();
var sm = new StateMachine("State Machine");
var evt = sm.CreateEvent<int>("Event");
var state1 = sm.CreateInitialState("State 1").WithEntry(i => events.Add("State 1 Entry")).WithExit(i => events.Add("State 1 Exit"));
state1.InnerSelfTransitionOn(evt).WithHandler(i => events.Add("Transition 1 1 Inner"));
evt.Fire(3);
Assert.That(events, Is.EquivalentTo(new[] { "Transition 1 1 Inner" }));
}
示例15: CorrectHandlersAreInvokedInNormalTransition
public void CorrectHandlersAreInvokedInNormalTransition()
{
var events = new List<string>();
var sm = new StateMachine("State Machine");
var evt = sm.CreateEvent("Event");
var state1 = sm.CreateInitialState("State 1").WithExit(i => events.Add("State 1 Exit"));
var state2 = sm.CreateState("State 2").WithEntry(i => events.Add("State 2 Entry"));
var transition = state1.TransitionOn(evt).To(state2).WithHandler(i => events.Add("Transition 1 2"));
evt.Fire();
Assert.That(events, Is.EquivalentTo(new[] { "State 1 Exit", "Transition 1 2", "State 2 Entry" }));
}