private void SendTriggerEvent_WithTwoTransitions_ExecutesExpected(bool useDoActions) #endif { // Arrange string[] expectedExec; if (useDoActions) { expectedExec = new string[] { "EnS1", "DoS1", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", }; } else { expectedExec = new string[] { "EnS1", "CHK", "ExS1", "EnS2", "CHK", "ExS2", "EnS1", "CHK", "CHK", "ExS1", "EnS2", "CHK", "ExS2", "EnS1", "CHK", "CHK", "ExS1", "EnS2", "CHK", "ExS2", "EnS1", "CHK", "CHK", "ExS1", "EnS2", "CHK", "ExS2", "EnS1", "CHK", "CHK", "ExS1", "EnS2", "CHK", "ExS2", "EnS1", "CHK", }; } ActionRecorder recorder = new ActionRecorder(); bool transition1Enabled = false; bool transition2Enabled = false; StateMachineTemplate t = new StateMachineTemplate(useDoActions ? StateMachineOptions.UseDoActions : StateMachineOptions.None); t.Region("S1", false); t.State("S1", recorder.CreateAction("EnS1"), recorder.CreateAction("ExS1"), useDoActions ? recorder.CreateDoAction("DoS1") : NullDo); t.Transition("T1", "S1", "S2", null, (stm, ev, args) => transition1Enabled, (stm, ev, args) => { transition1Enabled = false; transition2Enabled = true; }); t.EndState(); t.State("S2", recorder.CreateAction("EnS2"), recorder.CreateAction("ExS2"), useDoActions ? recorder.CreateDoAction("DoS2") : NullDo); t.Transition("T2", "S2", "S1", null, (stm, ev, args) => transition2Enabled, (stm, ev, args) => { transition2Enabled = false; }); t.EndState(); t.EndRegion(); StateMachine stateMachine = t.CreateStateMachine(); stateMachine.TraceDispatchTriggerEvent = recorder.CreateTraceMethod("CHK"); stateMachine.Startup(); // Act for (int i = 0; i < 5; i++) { transition1Enabled = true; stateMachine.SendTriggerEvent(null); } // Assert Assert.That(recorder.RecordedActions, Is.EqualTo(expectedExec), "Unexpected action invocations"); }
public void SendTriggerEvent_WithOneTransitionsAndDoChangesGuard_ExecutesExpected() { // Arrange string[] expectedExec; expectedExec = new string[] { "EnS1", "DoS1", "CHK", "DoS1", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", "CHK", "DoS1", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", "CHK", "DoS1", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", "CHK", "DoS1", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", "CHK", "DoS1", "CHK", "ExS1", "EnS2", "DoS2", "CHK", "ExS2", "EnS1", "DoS1", "CHK", }; ActionRecorder recorder = new ActionRecorder(); int transition1State = 0; StateMachineTemplate t = new StateMachineTemplate(StateMachineOptions.UseDoActions); t.Region("S1", false); t.State("S1", recorder.CreateAction("EnS1"), recorder.CreateAction("ExS1"), (stm) => { recorder.Add("DoS1"); transition1State += 1; }); t.Transition("T1", "S1", "S2", null, (stm, ev, args) => transition1State == 1, null); t.EndState(); t.State("S2", recorder.CreateAction("EnS2"), recorder.CreateAction("ExS2"), recorder.CreateDoAction("DoS2")); t.Transition("T2", "S2", "S1", null, (stm, ev, args) => true, null); t.EndState(); t.EndRegion(); StateMachine stateMachine = t.CreateStateMachine(); stateMachine.TraceDispatchTriggerEvent = recorder.CreateTraceMethod("CHK"); stateMachine.Startup(); // Act for (int i = 0; i < 5; i++) { transition1State = 0; stateMachine.SendTriggerEvent(null); } // Assert Assert.That(recorder.RecordedActions, Is.EqualTo(expectedExec), "Unexpected action invocations"); }