private static void TestInstanceOperationFromResumeBookmarkCallback(int operationsId, bool isSync) { string shouldNotExecuteMsg = "Should not see this message"; Variable <int> value = VariableHelper.Create <int>("value"); TestWriteLine writeLineNotRun = new TestWriteLine("NotExecuted", shouldNotExecuteMsg) { }; TestSequence testSequence = new TestSequence() { Variables = { value }, Activities = { new TestWriteLine() { Message = "Workflow Started" }, new TestWaitReadLine <int>("Read", "Read") { BookmarkValue = value }, } }; //Get Expected Trace without TestWriteLine() if (operationsId == 2) { testSequence.ExpectedOutcome = Outcome.Canceled; } ExpectedTrace expectedTrace = testSequence.GetExpectedTrace(); if (operationsId == 4) { expectedTrace.Trace.Steps.RemoveAt(expectedTrace.Trace.Steps.Count - 1); } else if (operationsId == 3) { expectedTrace.Trace.Steps.RemoveAt(expectedTrace.Trace.Steps.Count - 1); expectedTrace.Trace.Steps.Add(new ActivityTrace(testSequence.DisplayName, ActivityInstanceState.Faulted)); } //Now Add TestWriteLine to workflow testSequence.Activities.Add(writeLineNotRun); TestWorkflowRuntimeAsyncResult asyncResultResume = null; TestWorkflowRuntimeAsyncResult asyncResultOperation = null; string message = ""; //Execute Workflow JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~"); // using PersistableIdleAction.None here because the idle unload was racing with the resume bookmark after the wait for the BeforeWait trace. TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.None); workflowRuntime.ExecuteWorkflow(); workflowRuntime.WaitForActivityStatusChange("Read", TestActivityInstanceState.Executing); if (isSync) { //Log.Info("Resuming Bookmark"); if (isSync) { workflowRuntime.ResumeBookMark("Read", 9999); } else { asyncResultResume = workflowRuntime.BeginResumeBookMark("Read", 9999, null, null); } workflowRuntime.WaitForTrace(new UserTrace(WaitReadLine <int> .BeforeWait)); switch (operationsId) { case 2: //Cancel Workflow during OnResumeBookmark is executing //Log.Info("CancelWorkflow during OnResumeBookmark executing"); if (isSync) { workflowRuntime.CancelWorkflow(); } else { asyncResultOperation = workflowRuntime.BeginCancelWorkflow(null, null); workflowRuntime.EndResumeBookMark(asyncResultResume); workflowRuntime.EndCancelWorkflow(asyncResultOperation); } //Trace.WriteLine should not execute break; case 3: //Terminate Workflow during OnResumeBookmark is executing //Log.Info("TerminateWorkflow during OnResumeBookmark executing"); if (isSync) { workflowRuntime.TerminateWorkflow("Terminate Exception"); } else { asyncResultOperation = workflowRuntime.BeginTerminateWorkflow("Terminate Exception", null, null); workflowRuntime.EndResumeBookMark(asyncResultResume); workflowRuntime.EndTerminateWorkflow(asyncResultOperation); } //Trace.WriteLine should not execute. break; case 4: //Unload Workflow during OnResumeBookmark is executing //This should wait till ResumeMark finishes the work //Log.Info("UnloadWorkflow during OnResumeBookmark executing"); if (isSync) { workflowRuntime.UnloadWorkflow(); } else { asyncResultOperation = workflowRuntime.BeginUnloadWorkflow(null, null); workflowRuntime.EndResumeBookMark(asyncResultResume); workflowRuntime.EndUnloadWorkflow(asyncResultOperation); } //message = String.Format(ExceptionStrings.WorkflowInstanceUnloaded, workflowRuntime.CurrentWorkflowInstanceId); ExceptionHelpers.CheckForException(typeof(WorkflowApplicationUnloadedException), message, new ExceptionHelpers.MethodDelegate( delegate { workflowRuntime.ResumeWorkflow(); })); break; } } if (isSync) { switch (operationsId) { case 2: { workflowRuntime.WaitForCanceled(expectedTrace); break; } case 3: { Exception terminationException; workflowRuntime.WaitForTerminated(1, out terminationException, expectedTrace); break; } case 4: { // We tried to do a ResumeWorkflow without loading it after an unload, so we expected // to get a WorkflowApplicationUnloadedException. The workflow will never complete, // so don't wait for it to complete. break; } } } else { //Give some time for Workflow to execute Thread.CurrentThread.Join((int)TimeSpan.FromSeconds(1).TotalMilliseconds); } if (isSync) { expectedTrace.AddIgnoreTypes(typeof(WorkflowInstanceTrace)); workflowRuntime.ActualTrace.Validate(expectedTrace); } else { //The traces are vary in the async situations, thus we can not do a full trace valdation //validate the writeline after read activity is not executed is sufficient if (workflowRuntime.ActualTrace.ToString().Contains(shouldNotExecuteMsg)) { throw new Exception("The NotExecuted WriteLine activity has been executed, the expectation is it does not"); } } }