public void NoMatchingGuard( PassiveStateMachine <int, int> machine, CurrentStateExtension currentStateExtension) { bool declined = false; "establish state machine with no matching guard"._(() => { machine = new PassiveStateMachine <int, int>(); currentStateExtension = new CurrentStateExtension(); machine.AddExtension(currentStateExtension); machine.In(SourceState) .On(Event) .If(() => false).Goto(ErrorState); machine.TransitionDeclined += (sender, e) => declined = true; machine.Initialize(SourceState); machine.Start(); }); "when an event is fired"._(() => machine.Fire(Event)); "it should notify about declined transition"._(() => declined.Should().BeTrue("TransitionDeclined event should be fired")); }
public void MatchingGuard( PassiveStateMachine <int, int> machine, CurrentStateExtension currentStateExtension) { "establish a state machine with guarded transitions"._(() => { machine = new PassiveStateMachine <int, int>(); currentStateExtension = new CurrentStateExtension(); machine.AddExtension(currentStateExtension); machine.In(SourceState) .On(Event) .If(() => false).Goto(ErrorState) .If(() => true).Goto(DestinationState) .If(() => true).Goto(ErrorState) .Otherwise().Goto(ErrorState); machine.Initialize(SourceState); machine.Start(); }); "when an event is fired"._(() => machine.Fire(Event)); "it should take transition guarded with first matching guard"._(() => currentStateExtension.CurrentState.Should().Be(DestinationState)); }
public void OtherwiseGuard( PassiveStateMachine <int, int> machine, CurrentStateExtension currentStateExtension) { "establish a state machine with otherwise guard and no machting other guard"._(() => { machine = new PassiveStateMachine <int, int>(); currentStateExtension = new CurrentStateExtension(); machine.AddExtension(currentStateExtension); machine.In(SourceState) .On(Event) .If(() => false).Goto(ErrorState) .Otherwise().Goto(DestinationState); machine.Initialize(SourceState); machine.Start(); }); "when an event is fired"._(() => machine.Fire(Event)); "it should_take_transition_guarded_with_otherwise"._(() => currentStateExtension.CurrentState.Should().Be(DestinationState)); }
public void Start( PassiveStateMachine <int, int> machine, bool entryActionExecuted) { "establish an initialized state machine"._(() => { machine = new PassiveStateMachine <int, int>(); machine.AddExtension(testExtension); machine.In(TestState) .ExecuteOnEntry(() => entryActionExecuted = true); machine.Initialize(TestState); }); "when starting the state machine"._(() => machine.Start()); "should set current state of state machine to state to which it is initialized"._(() => this.testExtension.CurrentState.Should().Be(TestState)); "should execute entry action of state to which state machine is initialized"._(() => entryActionExecuted.Should().BeTrue()); }
public void Background() { "establish a hierarchical state machine"._(() => { testExtension = new CurrentStateExtension(); machine = new PassiveStateMachine <int, int>(); machine.AddExtension(testExtension); machine.DefineHierarchyOn(SuperState) .WithHistoryType(HistoryType.None) .WithInitialSubState(LeafState); machine.In(SuperState) .ExecuteOnEntry(() => entryActionOfSuperStateExecuted = true); machine.In(LeafState) .ExecuteOnEntry(() => entryActionOfLeafStateExecuted = true); }); }
public void Initialize( PassiveStateMachine <int, int> machine, bool entryActionExecuted) { "establish a state machine"._(() => { machine = new PassiveStateMachine <int, int>(); machine.AddExtension(testExtension); machine.In(TestState) .ExecuteOnEntry(() => entryActionExecuted = true); }); "when state machine is initialized"._(() => machine.Initialize(TestState)); "should not yet execute any entry actions"._(() => entryActionExecuted.Should().BeFalse()); }
public void ExecutingTransition( PassiveStateMachine <int, int> machine, string actualParameter, bool exitActionExecuted, bool entryActionExecuted) { "establish a state machine with transitions"._(() => { machine = new PassiveStateMachine <int, int>(); machine.AddExtension(CurrentStateExtension); machine.In(SourceState) .ExecuteOnExit(() => exitActionExecuted = true) .On(Event).Goto(DestinationState).Execute <string>(p => actualParameter = p); machine.In(DestinationState) .ExecuteOnEntry(() => entryActionExecuted = true); machine.Initialize(SourceState); machine.Start(); }); "when firing an event onto the state machine"._(() => machine.Fire(Event, Parameter)); "it should_execute_transition_by_switching_state"._(() => CurrentStateExtension.CurrentState.Should().Be(DestinationState)); "it should_execute_transition_actions"._(() => actualParameter.Should().NotBeNull()); "it should_pass_parameters_to_transition_action"._(() => actualParameter.Should().Be(Parameter)); "it should_execute_exit_action_of_source_state"._(() => exitActionExecuted.Should().BeTrue()); "it should_execute_entry_action_of_destination_state"._(() => entryActionExecuted.Should().BeTrue()); }
public void ClearingExtensions( IStateMachine <string, int> machine, IExtension <string, int> extension) { "establish a state machine with an extension"._(() => { machine = new PassiveStateMachine <string, int>(); extension = A.Fake <IExtension <string, int> >(); machine.AddExtension(extension); }); "when clearing all extensions from the state machine"._(() => { machine.ClearExtensions(); machine.Initialize("initial"); }); "it should not anymore notify extension about internal events"._(() => A.CallTo(extension) .MustNotHaveHappened()); }