Пример #1
0
        public override ExpectedTrace GetExpectedTrace()
        {
            this.ResetForValidation();

            OrderedTraces orderedTrace = new OrderedTraces();
            Outcome       outcome      = _activity.GetTrace(orderedTrace);
            ExpectedTrace baseTrace    = new ExpectedTrace(orderedTrace);

            baseTrace.AddIgnoreTypes(typeof(WorkflowExceptionTrace));
            baseTrace.AddIgnoreTypes(typeof(WorkflowAbortedTrace));
            baseTrace.AddIgnoreTypes(typeof(SynchronizeTrace));
            baseTrace.AddIgnoreTypes(typeof(BookmarkResumptionTrace));

            bool compensate = outcome.DefaultPropogationState != OutcomeState.Completed;

            foreach (Directive directive in this.CompensationHint)
            {
                TestActivity target = _activity.FindChildActivity(directive.Name);

                if (compensate)
                {
                    target.GetCompensationTrace(baseTrace.Trace);
                }
                else
                {
                    target.GetConfirmationTrace(baseTrace.Trace);
                }
            }

            return(baseTrace);
        }
Пример #2
0
 private void AddIgnoreTypes(ExpectedTrace expected)
 {
     // always ignore WorkflowInstanceTraces
     expected.AddIgnoreTypes(typeof(WorkflowExceptionTrace));
     expected.AddIgnoreTypes(typeof(WorkflowAbortedTrace));
     expected.AddIgnoreTypes(typeof(SynchronizeTrace));
     expected.AddIgnoreTypes(typeof(BookmarkResumptionTrace));
 }
Пример #3
0
        public void WhileWithExceptionFromCondition()
        {
            //  Test case description:
            //  Throw exception in while and in while condition

            TestSequence     outerSequence = new TestSequence("sequence1");
            TestSequence     innerSequence = new TestSequence("Seq");
            TestAssign <int> increment     = new TestAssign <int>("Increment Counter");
            Variable <int>   counter       = VariableHelper.CreateInitialized <int>("counter", 0);

            TestWhile whileAct = new TestWhile("while act")
            {
                Body = innerSequence,
                HintIterationCount = 10,
            };

            ExceptionThrowingActivitiy <bool> throwFromCondition = new ExceptionThrowingActivitiy <bool>();

            ((Microsoft.CoreWf.Statements.While)whileAct.ProductActivity).Condition = throwFromCondition;
            increment.ToVariable      = counter;
            increment.ValueExpression = ((env) => (((int)counter.Get(env))) + 1);
            innerSequence.Activities.Add(increment);
            outerSequence.Variables.Add(counter);
            outerSequence.Activities.Add(whileAct);
            OrderedTraces trace = new OrderedTraces();

            trace.Steps.Add(new ActivityTrace(outerSequence.DisplayName, ActivityInstanceState.Executing));
            trace.Steps.Add(new ActivityTrace(whileAct.DisplayName, ActivityInstanceState.Executing));

            OrderedTraces   ordered   = new OrderedTraces();
            UnorderedTraces unordered = new UnorderedTraces();

            unordered.Steps.Add(ordered);
            unordered.Steps.Add(new ActivityTrace(throwFromCondition.DisplayName, ActivityInstanceState.Executing));
            unordered.Steps.Add(new ActivityTrace(throwFromCondition.DisplayName, ActivityInstanceState.Faulted));
            trace.Steps.Add(unordered);

            ExpectedTrace expected = new ExpectedTrace(trace);

            expected.AddIgnoreTypes(typeof(WorkflowAbortedTrace));
            expected.AddIgnoreTypes(typeof(SynchronizeTrace));

            Exception           exc;
            TestWorkflowRuntime tr = TestRuntime.CreateTestWorkflowRuntime(outerSequence);

            tr.CreateWorkflow();
            tr.ResumeWorkflow();
            tr.WaitForAborted(out exc, expected);

            Assert.True((exc.GetType() == typeof(DataMisalignedException)) && exc.Message == "I am Miss.Aligned!");
        }
        internal void ValidateTrackingAndTracing(ExpectedTrace expectedTrace)
        {
            expectedTrace.AddIgnoreTypes(false, typeof(WorkflowInstanceTrace));
            //The expected trace may get modified in the validateTraces method. Hence make a copy to be userd for tracking validation.
            ExpectedTrace copyOfExpectedTrace = new ExpectedTrace(expectedTrace);

            ValidateTracking(copyOfExpectedTrace);
            //Log.TraceInternal("[TestTracingWatcher]Validate Tracing...");
            ValidateTraces(expectedTrace, GetActualTrace());
        }
        public void CheckWorkflowProperties()
        {
            TestActivity workflow = new TestWriteLine("Write1", "Write a line");

            TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(workflow);

            runtime.CreateWorkflow();
            runtime.Extensions.Add(new CheckWorkflowPropertiesExtension(runtime.CurrentWorkflowInstanceId, workflow.ProductActivity));

            runtime.ResumeWorkflow();
            ExpectedTrace expectedTrace = workflow.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            runtime.WaitForCompletion(expectedTrace);
        }
        public void ThrowFromInterfaceMethods()
        {
            TestActivity workflow = new TestWriteLine("Write1", "Write a line");

            TestWorkflowRuntime runtime = TestRuntime.CreateTestWorkflowRuntime(workflow);

            runtime.PersistenceProviderFactoryType = null;
            runtime.CreateWorkflow();

            ThrowFromAdditionalExtensions throwFromAdditionalExtensions = new ThrowFromAdditionalExtensions();

            CheckExceptionPropagated(throwFromAdditionalExtensions, "Throw from AdditionalExtensionsAdded", runtime);

            ThrowFromSetInstance throwFromSetInstance = new ThrowFromSetInstance();

            CheckExceptionPropagated(throwFromSetInstance, "Throw from SetInstance", runtime);

            runtime.ResumeWorkflow();
            ExpectedTrace expectedTrace = workflow.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            runtime.WaitForCompletion(expectedTrace);
        }
        public void VerifyAdditionalExtensionsAdded()
        {
            TestActivity        workflow = new TestReadLine <int>("Read1", "Read1");
            TestWorkflowRuntime runtime  = TestRuntime.CreateTestWorkflowRuntime(workflow);

            runtime.OnWorkflowUnloaded += WorkflowInstanceHelper.wfRuntime_OnUnload;
            runtime.CreateWorkflow();
            runtime.Extensions.Add(new AdditionalExtensionsAdded(new Collection <object>()
            {
                new OperationOrderTracePersistExtension(runtime.CurrentWorkflowInstanceId)
            }));

            runtime.ResumeWorkflow();
            runtime.WaitForIdle();
            runtime.ResumeBookMark("Read1", 1);

            ExpectedTrace expectedTrace = workflow.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            runtime.WaitForCompletion(expectedTrace);
            runtime.WaitForTrace(new UserTrace(WorkflowInstanceHelper.UnloadMessage));
            runtime.WaitForTrace(new UserTrace(OperationOrderTracePersistExtension.TraceSave));
        }
Пример #8
0
        public static void TestOperationsResumeBookmarkCallback(int operationId)
        {
            Variable <int> value        = VariableHelper.Create <int>("value");
            const string   WaitMessage  = "WaitActivity will wait for this trace";
            TestSequence   testSequence = new TestSequence()
            {
                Variables  = { value },
                Activities =
                {
                    new TestWriteLine()
                    {
                        Message = "Workflow Started"
                    },
                    new TestWaitForTrace()
                    {
                        DisplayName = "WaitActivity",
                        TraceToWait = WaitMessage
                    },
                    new TestWaitReadLine <int>("Read", "Read")
                    {
                        BookmarkValue = value
                    },
                    new TestReadLine <int>("Read1", "Read1")
                    {
                        BookmarkValue = value
                    },
                    new TestWriteLine()
                    {
                        Message = "Workflow Completed"
                    }
                }
            };

            JsonFileInstanceStore.FileInstanceStore jsonStore = new JsonFileInstanceStore.FileInstanceStore(".\\~");
            TestWorkflowRuntime workflowRuntime = TestRuntime.CreateTestWorkflowRuntime(testSequence, null, jsonStore, PersistableIdleAction.Unload);

            workflowRuntime.ExecuteWorkflow();
            workflowRuntime.WaitForActivityStatusChange("WaitActivity", TestActivityInstanceState.Executing);

            TestWorkflowRuntimeAsyncResult asyncResult = workflowRuntime.BeginResumeBookMark("Read", 10, new AsyncCallback(ResumeBookmarkCallback), operationId);

            //Continue the WaitActivity
            TestTraceManager.Instance.AddTrace(workflowRuntime.CurrentWorkflowInstanceId, new SynchronizeTrace(WaitMessage));
            SynchronizeTrace.Trace(workflowRuntime.CurrentWorkflowInstanceId, WaitMessage);
            workflowRuntime.EndResumeBookMark(asyncResult);
            workflowRuntime.WaitForTrace(new UserTrace("After ResumeBookmarkCallback"));

            if (operationId == 2)
            {
                //Do nothing
            }
            else if (operationId == 3)
            {
                workflowRuntime.UnloadWorkflow();
                workflowRuntime.LoadWorkflow();
                workflowRuntime.ExecuteWorkflow();
                workflowRuntime.ResumeBookMark("Read1", 99);
            }
            else if (operationId == 4)
            {
                workflowRuntime.LoadWorkflow();
                workflowRuntime.ExecuteWorkflow();
                workflowRuntime.ResumeBookMark("Read1", 99);
            }

            ExpectedTrace expectedTrace = testSequence.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(UserTrace));
            workflowRuntime.WaitForCompletion(expectedTrace);
        }
Пример #9
0
        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");
                }
            }
        }
        public void SetDelegateArgument()
        {
            // for using delegate argument

            TheStruct valueType             = new TheStruct();
            int       indiceValue           = 2;
            DelegateInArgument <int> indice = new DelegateInArgument <int>();
            Variable <TheStruct>     var    = VariableHelper.CreateInitialized <TheStruct>("var", valueType);
            TestValueTypeIndexerReference <TheStruct, int> valueTypeIndexerReference = new TestValueTypeIndexerReference <TheStruct, int>()
            {
                OperandLocationVariable = var,
            };

            valueTypeIndexerReference.Indices.Add(new TestArgument <int>(Direction.In, null, (env) => indice.Get(env)));

            int value = 321;
            TestAssign <int> testAssign = new TestAssign <int>()
            {
                ToLocation = valueTypeIndexerReference, Value = value
            };

            TestSequence seq = new TestSequence()
            {
                Activities =
                {
                    testAssign,
                    new TestWriteLine {
                        MessageExpression = ((ctx) => var.Get(ctx)[indiceValue].ToString())
                    }
                }
            };

            CoreWf.Statements.Sequence outerSeq = new CoreWf.Statements.Sequence()
            {
                Variables =
                {
                    var
                },
                Activities =
                {
                    new InvokeAction <int>()
                    {
                        Argument = indiceValue,
                        Action   = new ActivityAction <int>()
                        {
                            Argument = indice,
                            Handler  = seq.ProductActivity
                        }
                    }
                }
            };

            TestCustomActivity testActivity = TestCustomActivity <CoreWf.Statements.Sequence> .CreateFromProduct(outerSeq);

            UnorderedTraces traces = new UnorderedTraces()
            {
                Steps =
                {
                    new UserTrace(value.ToString())
                }
            };

            testActivity.ActivitySpecificTraces.Add(traces);
            ExpectedTrace expectedTrace = testActivity.GetExpectedTrace();

            expectedTrace.AddIgnoreTypes(typeof(ActivityTrace));

            TestRuntime.RunAndValidateWorkflow(testActivity, expectedTrace);
        }
Пример #11
0
        public void ParallelForEachWithAChildThatOverridesCancelAndCompletionConditionIsTrue()
        {
            Variable <bool> cancelIt = new Variable <bool> {
                Name = "cancelIt", Default = false
            };
            DelegateInArgument <bool> arg = new DelegateInArgument <bool>("arg");

            TestParallelForEach <bool> pfeAct = new TestParallelForEach <bool>
            {
                DisplayName                 = "ParallelForEach1",
                HintIterationCount          = 2,
                HintValues                  = new bool[] { true, false },
                ValuesExpression            = (e => new bool[] { true, false }),
                CurrentVariable             = arg,
                CompletionConditionVariable = cancelIt,
                Body = new TestIf(HintThenOrElse.Then, HintThenOrElse.Else)
                {
                    DisplayName         = "If1",
                    ConditionExpression = e => arg.Get(e),
                    ThenActivity        = new TestBlockingActivityWithWriteLineInCancel("writeLineInCancel", OutcomeState.Completed)
                    {
                        ExpectedOutcome = new Outcome(OutcomeState.Completed, OutcomeState.Canceled),
                    },
                    ElseActivity = new TestSequence
                    {
                        DisplayName = "Sequence2",
                        Activities  =
                        {
                            new TestDelay("d1", new TimeSpan(1)),
                            new TestAssign <bool> {
                                DisplayName = "Assign1",Value = true,    ToVariable       = cancelIt
                            }
                        }
                    }
                },
            };

            TestSequence root = new TestSequence
            {
                DisplayName = "Sequence1",
                Activities  = { pfeAct },
                Variables   = { cancelIt },
            };

            OrderedTraces ordered = new OrderedTraces()
            {
                Steps =
                {
                    new ActivityTrace("Sequence1",                              ActivityInstanceState.Executing),
                    new ActivityTrace("ParallelForEach1",                       ActivityInstanceState.Executing),
                    new UnorderedTraces
                    {
                        Steps =
                        {
                            new OrderedTraces()
                            {
                                Steps =
                                {
                                    new ActivityTrace("If1",               ActivityInstanceState.Executing),
                                    new ActivityTrace("writeLineInCancel", ActivityInstanceState.Executing),
                                    new ActivityTrace("w1",                ActivityInstanceState.Executing),
                                    new ActivityTrace("w1",                ActivityInstanceState.Closed),
                                    new ActivityTrace("writeLineInCancel", ActivityInstanceState.Closed),
                                    new ActivityTrace("If1",               ActivityInstanceState.Closed),
                                }
                            },
                            new OrderedTraces()
                            {
                                Steps =
                                {
                                    new ActivityTrace("If1",                    ActivityInstanceState.Executing),
                                    new ActivityTrace("Sequence2",              ActivityInstanceState.Executing),
                                    new ActivityTrace("d1",                     ActivityInstanceState.Executing),
                                    new ActivityTrace("d1",                     ActivityInstanceState.Closed),
                                    new ActivityTrace("Assign1",                ActivityInstanceState.Executing),
                                    new ActivityTrace("Assign1",                ActivityInstanceState.Closed),
                                    new ActivityTrace("Sequence2",              ActivityInstanceState.Closed),
                                    new ActivityTrace("If1",                    ActivityInstanceState.Closed),
                                    new ActivityTrace("VariableValue<Boolean>", ActivityInstanceState.Executing),
                                    new ActivityTrace("VariableValue<Boolean>", ActivityInstanceState.Closed),
                                }
                            }
                        }
                    },
                    new ActivityTrace("ParallelForEach1",                       ActivityInstanceState.Closed),
                    new ActivityTrace("Sequence1",                              ActivityInstanceState.Closed),
                }
            };

            ExpectedTrace trace = new ExpectedTrace(ordered);

            trace.AddIgnoreTypes(typeof(SynchronizeTrace));
            trace.AddIgnoreTypes(typeof(BookmarkResumptionTrace));
            TestRuntime.RunAndValidateWorkflow(root, trace);
        }