Esempio n. 1
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="currentState">Current state.</param>
 /// <param name="stateMachineEvent">State machine event.</param>
 /// <param name="guard">Transition guard.</param>
 /// <param name="newState">New state.</param>
 /// <param name="action">Action.</param>
 public StateTransition(StateType currentState, EventType stateMachineEvent, StateTransitionGuard guard, StateType newState, StateTransitionAction action)
 {
     CurrentState = currentState;
     Event        = stateMachineEvent;
     Guard        = guard;
     NewState     = newState;
     Action       = action;
 }
Esempio n. 2
0
        public void Test_Guard_Methods_Gets_Exectued()
        {
            var guardStatementHasBeenExecuted = false;

            var guard = new StateTransitionGuard(() =>
            {
                guardStatementHasBeenExecuted = true;
                return(true);
            });

            var stateMachine = new StateMachine <MachineState, MachineEvent>(MachineState.Off);

            stateMachine.AddTransition(MachineState.Off, MachineEvent.Start, guard, MachineState.Idle, () => { });
            stateMachine.AddTransition(MachineState.Off, MachineEvent.Honk, () => { return(true); }, MachineState.Idle, () => { });

            stateMachine.HandleEvent(MachineEvent.Start);

            Assert.IsTrue(guardStatementHasBeenExecuted);
            Assert.AreEqual(MachineState.Idle, stateMachine.CurrentState);
        }
Esempio n. 3
0
 /// <summary>
 ///     Creates new instance of state change transition
 /// </summary>
 /// <param name="startState">Start state</param>
 /// <param name="transitionEvent">Event</param>
 /// <param name="guard">Transition guard</param>
 /// <param name="endState">End state</param>
 /// <param name="transitionAction">Transition Action</param>
 public void AddTransition(StateType startState, EventType transitionEvent, StateTransitionGuard guard, StateType endState, StateTransitionAction transitionAction)
 {
     AddTransition(new StateTransition <StateType, EventType>(startState, transitionEvent, guard, endState, transitionAction));
 }
Esempio n. 4
0
 public StateTransition(TState newState, StateTransitionGuard guard)
 {
     NewState = newState;
     Guard    = guard;
 }