public void Loading( StateMachineSaver <State> saver, StateMachineLoader <State> loader, State sourceState, State targetState) { "establish a saved state machine with history"._(() => { var machine = new PassiveStateMachine <State, Event>(); DefineMachine(machine); machine.Initialize(State.A); machine.Start(); machine.Fire(Event.S2); // set history of super state S machine.Fire(Event.B); // set current state to B saver = new StateMachineSaver <State>(); loader = new StateMachineLoader <State>(); machine.Save(saver); }); "when state machine is loaded"._(() => { loader.SetCurrentState(saver.CurrentStateId); loader.SetHistoryStates(saver.HistoryStates); var loadedMachine = new PassiveStateMachine <State, Event>(); DefineMachine(loadedMachine); loadedMachine.Load(loader); loadedMachine.TransitionCompleted += (sender, args) => { sourceState = args.StateId; targetState = args.NewStateId; }; loadedMachine.Start(); loadedMachine.Fire(Event.S); }); "it should reset current state"._(() => sourceState.Should().Be(State.B)); "it should reset all history states of super states"._(() => targetState.Should().Be(State.S2)); }
public void TransitionActionException() { "establish a transition action throwing an exception"._(() => this.machine.In(Values.Source) .On(Values.Event).Goto(Values.Destination).Execute(() => { throw Values.Exception; })); "when executing the transition"._(() => { machine.Initialize(Values.Source); machine.Start(); machine.Fire(Values.Event, Values.Parameter); }); this.ItShouldHandleTransitionException(); }