public void OtherwiseGuard( PassiveStateMachine <int, int> machine, CurrentStateExtension currentStateExtension) { "establish a state machine with otherwise guard and no machting other guard".x(() => { 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".x(() => machine.Fire(Event)); "it should_take_transition_guarded_with_otherwise".x(() => currentStateExtension.CurrentState.Should().Be(DestinationState)); }
public void NoMatchingGuard( PassiveStateMachine <int, int> machine, CurrentStateExtension currentStateExtension) { bool declined = false; "establish state machine with no matching guard".x(() => { 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".x(() => machine.Fire(Event)); "it should notify about declined transition".x(() => declined.Should().BeTrue("TransitionDeclined event should be fired")); }
public void MatchingGuard( PassiveStateMachine <int, int> machine, CurrentStateExtension currentStateExtension) { "establish a state machine with guarded transitions".x(() => { 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".x(() => machine.Fire(Event)); "it should take transition guarded with first matching guard".x(() => currentStateExtension.CurrentState.Should().Be(DestinationState)); }
public void Background() { "establish a hierarchical state machine"._(() => { this.testExtension = new CurrentStateExtension(); this.machine = new PassiveStateMachine <int, int>(); this.machine.AddExtension(this.testExtension); this.machine.DefineHierarchyOn(SuperState) .WithHistoryType(HistoryType.None) .WithInitialSubState(LeafState); this.machine.In(SuperState) .ExecuteOnEntry(() => this.entryActionOfSuperStateExecuted = true); this.machine.In(LeafState) .ExecuteOnEntry(() => this.entryActionOfLeafStateExecuted = true); }); }