internal void ValidateTrackingAndTracing(ExpectedTrace expectedTrace, ExpectedTrace expectedWorkflowInstanceTrace)
        {
            //The expected trace may get modified in the validateTraces method. Hence make a copy to be prior to tracking validation.
            //We are merging two sets of traces
            //1) the traces generated by activities
            //2) the traces generated by workflowinstance method calls
            UnorderedTraces mergedTrace = new UnorderedTraces();

            mergedTrace.Steps.Add(expectedTrace.Trace);
            if (expectedWorkflowInstanceTrace != null)
            {
                mergedTrace.Steps.Add(expectedWorkflowInstanceTrace.Trace);
            }

            ExpectedTrace expectedMergedTrace = new ExpectedTrace(expectedTrace)
            {
                Trace = mergedTrace
            };

            ValidateTracking(expectedTrace);

            //Log.TraceInternal("[TestWorkflowRuntime]***Validate Tracing...");

            ValidateTraces(expectedMergedTrace, GetActualTrace());
        }
Exemple #2
0
        protected override void GetCancelTrace(TraceGroup traceGroup)
        {
            UnorderedTraces finalCancelTraces = new UnorderedTraces();

            GetCompensationTrace(finalCancelTraces);
            finalCancelTraces.Steps.Add(new ActivityTrace(this.DisplayName, ActivityInstanceState.Canceled));

            traceGroup.Steps.Add(new ActivityTrace(this.DisplayName, ActivityInstanceState.Canceled));
        }
Exemple #3
0
        protected override void GetCancelTrace(TraceGroup traceGroup)
        {
            // The Parallel.Canceled trace and Compensation traces can come unordered...
            UnorderedTraces finalCancelTraces = new UnorderedTraces();

            GetCompensationTrace(finalCancelTraces);
            finalCancelTraces.Steps.Add(new ActivityTrace(this.DisplayName, ActivityInstanceState.Canceled));

            traceGroup.Steps.Add(finalCancelTraces);
        }
Exemple #4
0
        public void ThrowExceptionInValues()
        {
            UnorderedTraces ordered = new UnorderedTraces()
            {
                Steps =
                {
                    new OrderedTraces()
                    {
                        Steps =
                        {
                            new ActivityTrace("w1", ActivityInstanceState.Executing),
                            new ActivityTrace("w1", ActivityInstanceState.Faulted),
                        }
                    },
                    new OrderedTraces()
                    {
                        Steps =
                        {
                            new ActivityTrace("w1", ActivityInstanceState.Executing),
                            new ActivityTrace("w1", ActivityInstanceState.Faulted),
                        }
                    },
                    new OrderedTraces()
                    {
                        Steps =
                        {
                            new ActivityTrace("w1", ActivityInstanceState.Executing),
                            new ActivityTrace("w1", ActivityInstanceState.Faulted),
                        }
                    }
                }
            };

            TestParallelForEach <int> foreachAct = new TestParallelForEach <int>("foreach")
            {
                ValuesExpression = context => new IEnumerableWithException {
                    NumberOfIterations = 3
                },
                Body = new TestWriteLine("w1")
                {
                    Message = "w1"
                },
                ExpectedOutcome        = Outcome.Faulted,
                ActivitySpecificTraces =
                {
                    ordered,
                }
            };

            TestRuntime.RunAndValidateAbortedException(foreachAct, typeof(TestCaseException), new Dictionary <string, string>());
        }
Exemple #5
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!");
        }
Exemple #6
0
        //
        // Example hint list describing 3 branches and the order of processing for CA's on each Branch
        // { Branch, CA2, CA1, Branch, CA3, Branch, CA6, CA5, CA4 }
        //

        private void ProcessCompensationHints(IList <Directive> hints, string defaultAction, TraceGroup traceGroup)
        {
            // A splited flowchart Confirmation/Compensation are collections of unordered branch traces
            // (similar to Parallel)
            UnorderedTraces unordered = new UnorderedTraces();

            OrderedTraces ordered = null;

            foreach (Directive directive in hints)
            {
                // If we encounter a Branch directive that means we need to start a new OrderedTraces group
                if (directive.Name == "Branch")
                {
                    if (ordered != null)             // Already had one, so add it to our collection before we create a new one
                    {
                        if (ordered.Steps.Count > 0) // There's a chance we didn't produce any output
                        {
                            unordered.Steps.Add(ordered);
                        }
                    }

                    ordered = new OrderedTraces();
                }
                else
                {
                    TestActivity target = FindChildActivity(directive.Name);

                    TestCompensableActivity.ProcessDirective(target, directive, defaultAction, traceGroup);
                }
            }

            // Was there one left over? (From the last branch directive)
            if (ordered != null)
            {
                if (ordered.Steps.Count > 0) // There's a chance we didn't produce any output
                {
                    unordered.Steps.Add(ordered);
                }
            }

            if (unordered.Steps.Count > 0)
            {
                traceGroup.Steps.Add(unordered);
            }
        }
Exemple #7
0
        protected override void GetActivitySpecificTrace(Test.Common.TestObjects.Utilities.Validation.TraceGroup traceGroup)
        {
            UnorderedTraces parallelTraceGroup = null;

            Outcome outcome = Outcome.Completed;

            parallelTraceGroup = new UnorderedTraces();
            foreach (TestPickBranch branch in this.Branches)
            {
                // Each Branch is Ordered with respect to itself (like normal)
                OrderedTraces branchTraceGroup = new OrderedTraces();

                Outcome bOutcome = branch.GetTriggerTrace(branchTraceGroup);

                if (bOutcome.GetType() != typeof(Outcome))
                {
                    outcome = bOutcome;
                }


                parallelTraceGroup.Steps.Add(branchTraceGroup);
            }
            traceGroup.Steps.Add(parallelTraceGroup);

            parallelTraceGroup = new UnorderedTraces();
            foreach (TestPickBranch branch in this.Branches)
            {
                // Each Branch is Ordered with respect to itself (like normal)
                OrderedTraces branchTraceGroup = new OrderedTraces();

                Outcome bOutcome = branch.GetActionTrace(branchTraceGroup);

                if (bOutcome != null && bOutcome.GetType() != typeof(Outcome))
                {
                    outcome = bOutcome;
                }

                parallelTraceGroup.Steps.Add(branchTraceGroup);
            }
            traceGroup.Steps.Add(parallelTraceGroup);

            this.CurrentOutcome = outcome;
        }
        private Outcome GetTransitInTrace(TraceGroup stateTraceGroup, TestTransition incomingTransition)
        {
            HashSet <TestActivity> triggerHash  = new HashSet <TestActivity>();
            UnorderedTraces        triggerTrace = new UnorderedTraces();

            Outcome outcome = this.ExpectedOutcome;

            this.CurrentOutcome = this.ExpectedOutcome;

            this.GetStartTrace(stateTraceGroup);

            outcome = this.GetEntryTrace(stateTraceGroup);
            if (this.CurrentOutcome.IsOverrideable)
            {
                this.CurrentOutcome = outcome;
            }

            if (outcome.DefaultPropogationState == OutcomeState.Completed)
            {
                stateTraceGroup.Steps.Add(triggerTrace);
                foreach (TestTransition t in this.Transitions)
                {
                    // Shared trigger transitions
                    if (triggerHash.Add(t.Trigger))
                    {
                        outcome = t.GetTriggerTrace(triggerTrace);

                        if (outcome.DefaultPropogationState == OutcomeState.Completed)
                        {
                            outcome = t.GetConditionTrace(triggerTrace);

                            if (this.CurrentOutcome.IsOverrideable)
                            {
                                this.CurrentOutcome = outcome.Propogate();
                            }
                        }
                        else if (outcome.DefaultPropogationState == OutcomeState.Faulted || outcome is UncaughtExceptionOutcome || outcome is CaughtExceptionOutcome)
                        {
                            if (this.CurrentOutcome.IsOverrideable)
                            {
                                this.CurrentOutcome = outcome.Propogate();
                            }
                        }
                        // trigger cancel can mean two things:
                        // 1. trigger is cancelled by another trigger. This is normal behavior.
                        // 2. trigger is cancelled externally. In such case, Transition.ExpectedOutcome should be set to canceled.
                        else if (outcome.DefaultPropogationState == OutcomeState.Canceled)
                        {
                            if (t.ExpectedOutcome.DefaultPropogationState == OutcomeState.Canceled)
                            {
                                if (this.CurrentOutcome.IsOverrideable)
                                {
                                    this.CurrentOutcome = outcome.Propogate();
                                }
                            }
                            continue;
                        }
                    }
                    else
                    {
                        outcome = t.GetConditionTrace(triggerTrace);

                        if (outcome.DefaultPropogationState != OutcomeState.Completed)
                        {
                            if (CurrentOutcome.IsOverrideable)
                            {
                                CurrentOutcome = outcome.Propogate();
                            }
                        }
                    }
                }
            }

            if (this.CurrentOutcome.DefaultPropogationState == OutcomeState.Canceled)
            {
                this.GetCancelTrace(stateTraceGroup);
            }

            return(this.CurrentOutcome.Propogate());
        }
Exemple #9
0
        protected override void GetActivitySpecificTrace(TraceGroup traceGroup)
        {
            UnorderedTraces parallelTraceGroup = new UnorderedTraces();

            if (this.HintIterationCount < 0 && _values == null)
            {
                return;
            }

            if (this.HintIterationCount < 0 && _values != null)
            {
                this.HintIterationCount = _values.Count <T>();
            }

            if (_valuesActivity != null)
            {
                Outcome conditionOutcome = _valuesActivity.GetTrace(traceGroup);

                if (conditionOutcome.DefaultPropogationState != OutcomeState.Completed)
                {
                    // propogate the unknown outcome upwards
                    this.CurrentOutcome = conditionOutcome;
                }
            }

            if (this.Body != null)
            {
                Outcome outc;

                for (int i = 1; i < _values.Count <T>() + 1; i++)
                {
                    OrderedTraces orderedTraceGroup = new OrderedTraces();

                    if (HintIterationCount < i)
                    {
                        TestDummyTraceActivity tdt = new TestDummyTraceActivity(Body.DisplayName)
                        {
                            ExpectedOutcome = Outcome.Canceled
                        };
                        tdt.GetTrace(orderedTraceGroup);
                    }
                    else
                    {
                        outc = this.Body.GetTrace(orderedTraceGroup);
                        if (this.ProductParallelForEach.CompletionCondition != null && outc.DefaultPropogationState != OutcomeState.Canceled)
                        {
                            TestDummyTraceActivity condition = new TestDummyTraceActivity(this.ProductParallelForEach.CompletionCondition, ConditionOutcome);
                            CurrentOutcome = condition.GetTrace(orderedTraceGroup);
                        }
                        if (outc.DefaultPropogationState != OutcomeState.Completed)
                        {
                            CurrentOutcome = outc;
                        }
                    }


                    parallelTraceGroup.Steps.Add(orderedTraceGroup);
                }

                traceGroup.Steps.Add(parallelTraceGroup);
            }
        }
Exemple #10
0
        protected override void GetActivitySpecificTrace(TraceGroup traceGroup)
        {
            // Parallel is a collection of unordered branches
            UnorderedTraces parallelTraceGroup = new UnorderedTraces();

            bool oneCompleted = false;
            int  index        = 0;

            foreach (TestActivity branch in _branches)
            {
                // Each Branch is Ordered with respect to itself (like normal)
                OrderedTraces branchTraceGroup = new OrderedTraces();

                if (_numberOfBranchesExecution == index)
                {
                    // so if we have gone past the hint
                    if (branch.ExpectedOutcome.DefaultPropogationState == OutcomeState.Completed)
                    {
                        TestDummyTraceActivity tdt = new TestDummyTraceActivity(branch.DisplayName)
                        {
                            ExpectedOutcome = Outcome.Canceled
                        };
                        tdt.GetTrace(branchTraceGroup);
                    }
                }
                else
                {
                    index++;

                    Outcome bOutcome = branch.GetTrace(branchTraceGroup);
                    if (bOutcome.DefaultPropogationState == OutcomeState.Completed)
                    {
                        oneCompleted = true;

                        if (this.ProductParallel.CompletionCondition != null)
                        {
                            if (_expressionActivity != null)
                            {
                                CurrentOutcome = _expressionActivity.GetTrace(branchTraceGroup);
                            }
                            else
                            {
                                TestDummyTraceActivity tdt = new TestDummyTraceActivity(this.ProductParallel.CompletionCondition, Outcome.Completed);
                                CurrentOutcome = tdt.GetTrace(branchTraceGroup);
                            }
                        }
                    }
                    else if (CurrentOutcome.IsOverrideable)
                    {
                        CurrentOutcome = bOutcome;
                    }
                }

                parallelTraceGroup.Steps.Add(branchTraceGroup);
            }

            // If there's at least one good branch and the CompletionCondition is true, we probably succeeded
            if (oneCompleted && _completionCondition)
            {
                this.CurrentOutcome = Outcome.Completed;
            }

            traceGroup.Steps.Add(parallelTraceGroup);
        }
        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);
        }