public void StateHistoryThrowWithMoreThanOneStateMachine() { var activity = new NestedStateMachineExample(); var host = WorkflowApplicationTest.Create(activity); var tracker = StateMachineStateTracker.Attach(host.TestWorkflowApplication); try { host.TestWorkflowApplication.RunEpisode("T1", Constants.Timeout); // Run until bookmark "NT1" from nested state machine host.TestWorkflowApplication.ResumeEpisodeBookmark("T1", null, "NT1"); Assert.AreEqual(2, tracker.TrackedStateMachines.Count); AssertHelper.Throws<InvalidOperationException>(() => AssertHelper.GetProperty(tracker.StateHistory)); } finally { Debug.Assert(tracker != null, "tracker != null"); tracker.Trace(); Debug.Assert(host.Tracking != null, "host.Tracking != null"); host.Tracking.Trace(); } }
public void NestedStateMachineIsTracked() { var activity = new NestedStateMachineExample(); var host = WorkflowApplicationTest.Create(activity); var tracker = new StateTracker(); host.Extensions.Add(tracker); try { host.TestWorkflowApplication.RunUntilBookmark(StateTrigger.T1, Constants.Timeout); // Run until bookmark "NT1" from nested state machine host.TestWorkflowApplication.ResumeUntilBookmark("T1", null, "NT1"); Assert.AreEqual(2, tracker.StateMachines.Count); } finally { tracker.Trace(); host.Tracking.Trace(); } }
public void TrackerWithNestedState() { var activity = new NestedStateMachineExample(); var host = WorkflowApplicationTest.Create(activity); Debug.Assert(host != null, "host != null"); var tracker = StateMachineStateTracker.Attach(host.TestWorkflowApplication); try { // Using Microsoft.Activities.Extensions run the workflow until a bookmark named "T1" Assert.IsInstanceOfType( host.TestWorkflowApplication.RunEpisode("T1", Constants.Timeout), typeof(WorkflowIdleEpisodeResult)); WorkflowTrace.Information("First Idle"); Debug.Assert(tracker != null, "tracker != null"); tracker.Trace(); Debug.Assert(tracker.TrackedStateMachines != null, "tracker.TrackedStateMachines != null"); Assert.AreEqual(1, tracker.TrackedStateMachines.Count); var stateTrackerInfo = tracker.TrackedStateMachines.Values.ElementAt(0); Debug.Assert(stateTrackerInfo != null, "stateTrackerInfo != null"); Assert.AreEqual("State1", stateTrackerInfo.CurrentState); Debug.Assert(stateTrackerInfo.Transitions != null, "stateTrackerInfo.Transitions != null"); Assert.AreEqual(2, stateTrackerInfo.Transitions.Count); Assert.AreEqual("T1, T6", stateTrackerInfo.PossibleTransitions); // Run until bookmark "NT1" from nested state machine Assert.IsInstanceOfType( host.TestWorkflowApplication.ResumeEpisodeBookmark("T1", null, "NT1"), typeof(WorkflowIdleEpisodeResult)); WorkflowTrace.Information("Second Idle"); tracker.Trace(); Debug.Assert(tracker.TrackedStateMachines != null, "tracker.TrackedStateMachines != null"); Assert.AreEqual(2, tracker.TrackedStateMachines.Count); // Verify the parent state machine is already in State2 stateTrackerInfo = tracker.TrackedStateMachines.Values.ElementAt(0); Debug.Assert(stateTrackerInfo != null, "stateTrackerInfo != null"); Assert.AreEqual("State2", stateTrackerInfo.CurrentState); Debug.Assert(stateTrackerInfo.Transitions != null, "stateTrackerInfo.Transitions != null"); Assert.AreEqual(3, stateTrackerInfo.Transitions.Count); Assert.AreEqual("T2, T3, T7", stateTrackerInfo.PossibleTransitions); // The nested state machine var nestedStateTrackerInfo = tracker.TrackedStateMachines.Values.ElementAt(1); Debug.Assert(nestedStateTrackerInfo != null, "nestedStateTrackerInfo != null"); Assert.AreEqual("Nested State1", nestedStateTrackerInfo.CurrentState); Debug.Assert(nestedStateTrackerInfo.Transitions != null, "nestedStateTrackerInfo.Transitions != null"); Assert.AreEqual(1, nestedStateTrackerInfo.Transitions.Count); Assert.AreEqual("NT1", nestedStateTrackerInfo.PossibleTransitions); // Resume bookmark "NT1" from nested state machine and run until bookmark "T7" Assert.IsInstanceOfType( host.TestWorkflowApplication.ResumeEpisodeBookmark("NT1", null, "T7"), typeof(WorkflowIdleEpisodeResult)); // Resume bookmark T7 and run until complete Assert.IsInstanceOfType( host.TestWorkflowApplication.ResumeEpisodeBookmark("T7", null), typeof(WorkflowCompletedEpisodeResult)); Assert.AreEqual(2, tracker.TrackedStateMachines.Count); } finally { Debug.Assert(tracker != null, "tracker != null"); tracker.Trace(); Debug.Assert(host.Tracking != null, "host.Tracking != null"); host.Tracking.Trace(); } }