Beispiel #1
0
 public TestFlowElement AddConditionalLink(TestActivity sourceActivity, TestFlowConditional flowConditional, TestFlowElement trueFlowElement, TestActivity falseActivity)
 {
     AddConditionalLink(sourceActivity, flowConditional, (TestActivity)null, falseActivity);
     flowConditional.TrueAction = trueFlowElement;
     AddTestFlowLink(trueFlowElement);
     return(flowConditional);
 }
Beispiel #2
0
        public TestFlowElement AddStartLink(TestActivity targetActivity)
        {
            TestFlowStep flowStep = new TestFlowStep(targetActivity);

            SetStartNode(flowStep);
            return(AddTestFlowLink(flowStep));
        }
        internal void GetCancellationTrace(TraceGroup traceGroup)
        {
            // This handler should only be invoked once (unless the CA is in a loop).
            _currentIterationCount++;
            if (_currentIterationCount > _hintIterationCount)
            {
                return;
            }

            // Attempt to process through the provided compensation activity to pick up the traces
            if (_cancellation != null)
            {
                _cancellation.GetTrace(traceGroup);
            }

            // Additionally, if there are any hints, trace these as well...
            // Scenario1: There are just hints but no compensation activity -- hints control all the work
            // Scenario2: There is a compensation activity which does work but there is work remaining afterwards -- hints control the remaining work
            foreach (Directive directive in this.CompensationHint)
            {
                TestActivity target = FindChildActivity(directive.Name);

                TestCompensableActivity.ProcessDirective(target, directive, Directive.Compensate, traceGroup);
            }
        }
Beispiel #4
0
 public TestFlowElement AddConditionalLink(TestActivity sourceActivity, TestFlowConditional flowConditional, TestActivity trueActivity, TestFlowElement falseFlowElement)
 {
     AddConditionalLink(sourceActivity, flowConditional, trueActivity, (TestActivity)null);
     flowConditional.FalseAction = falseFlowElement;
     AddTestFlowLink(falseFlowElement);
     return(flowConditional);
 }
Beispiel #5
0
        public TestFlowElement AddLink(TestActivity sourceActivity, TestActivity targetActivity)
        {
            //Search in the elements collection if the flowstep exists and just needs to be
            //connected to next element
            TestFlowStep sourceStep = GetFlowStepContainingActionActivity(sourceActivity);
            TestFlowStep targetStep = GetFlowStepContainingActionActivity(targetActivity);

            if (sourceStep == null)
            {
                sourceStep = new TestFlowStep(sourceActivity);
                SetStartNode(sourceStep);
                AddTestFlowLink(sourceStep);
            }

            if (targetStep == null)
            {
                targetStep = new TestFlowStep(targetActivity);
            }
            sourceStep.NextElement = targetStep;
            AddTestFlowLink(targetStep);

            //We need to return the source step since the IsFaulting has to be set in case
            //of fault
            return(sourceStep);
        }
Beispiel #6
0
        public TestFlowElement AddSwitchLink <T>(TestActivity sourceActivity, Dictionary <T, TestActivity> cases, List <int> hintsExecutingActivityIndex, Expression <Func <ActivityContext, T> > lambdaExpression, params TestActivity[] defaultActivity)
        {
            TestFlowSwitch <T> flowSwitch = CreateSwitchElement <T>(sourceActivity, cases, hintsExecutingActivityIndex, defaultActivity, true) as TestFlowSwitch <T>;

            flowSwitch.LambdaExpression = lambdaExpression;
            return(AddTestFlowLink(flowSwitch));
        }
Beispiel #7
0
        public TestFlowElement AddSwitchLink <T>(TestActivity sourceActivity, Dictionary <T, TestActivity> cases, List <int> hintsExecutingActivityIndex, TestActivity expressionActivity, params TestActivity[] defaultActivity)
        {
            TestFlowSwitch <T> flowSwitch = CreateSwitchElement <T>(sourceActivity, cases, hintsExecutingActivityIndex, defaultActivity, true) as TestFlowSwitch <T>;

            flowSwitch.ExpressionActivity = expressionActivity;
            return(AddTestFlowLink(flowSwitch));
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public TestFlowElement AddConditionalLink(TestActivity sourceActivity, TestFlowConditional flowConditional, TestActivity trueActivity, TestActivity falseActivity)
        {
            if (sourceActivity != null)
            {
                TestFlowStep flowStep = GetFlowStepContainingActionActivity(sourceActivity);
                if (flowStep == null)
                {
                    flowStep = new TestFlowStep(sourceActivity)
                    {
                        NextElement = flowConditional
                    };
                    AddTestFlowLink(flowStep);
                    SetStartNode(flowStep);
                }
                else
                {
                    flowStep.NextElement = flowConditional;
                }
            }
            AddTestFlowLink(flowConditional);

            if (trueActivity != null)
            {
                //For loops we need to check if the element already exists with the target activity
                TestFlowStep trueStep = GetFlowStepContainingActionActivity(trueActivity);
                if (trueStep != null)
                {
                    flowConditional.TrueAction = trueStep;
                }
                else
                {
                    flowConditional.TrueAction = new TestFlowStep(trueActivity);
                }
                AddTestFlowLink(flowConditional.TrueAction);
            }
            if (falseActivity != null)
            {
                //For loops we need to check if the element already exists with the target activity
                TestFlowStep falseStep = GetFlowStepContainingActionActivity(falseActivity);
                if (falseStep != null)
                {
                    flowConditional.FalseAction = falseStep;
                }
                else
                {
                    flowConditional.FalseAction = new TestFlowStep(falseActivity);
                }
                AddTestFlowLink(flowConditional.FalseAction);
            }

            if (_startElement == null)
            {
                SetStartNode(flowConditional);
                AddTestFlowLink(flowConditional);
            }
            return(flowConditional);
        }
        public TestWhile(TestActivity condition)
        {
            if (!(condition.ProductActivity is Activity <bool> prodActivity))
            {
                throw new ArgumentNullException("ProductActivity");
            }

            this.body            = condition;
            this.ProductActivity = new While(prodActivity);
        }
Beispiel #11
0
        private void HandleError(TraceGroup traceGroup)
        {
            // Use the expected hints to get the compensation traces for each
            foreach (Directive directive in this.CompensationHint)
            {
                TestActivity target = FindChildActivity(directive.Name);

                TestCompensableActivity.ProcessDirective(target, directive, Directive.Compensate, traceGroup);
            }
        }
Beispiel #12
0
 public TestFlowStep(TestActivity actionActivity)
     : this()
 {
     if (actionActivity == null)
     {
         return;
     }
     _actionActivity         = actionActivity;
     _productFlowStep.Action = actionActivity.ProductActivity;
 }
Beispiel #13
0
        public TestDoWhile(TestActivity condition)
        {
            if (!(condition.ProductActivity is Activity <bool> prodActivity))
            {
                throw new Exception("DoWhile can only be constructed with Activity<bool> condition");
            }

            this.body            = condition;
            this.ProductActivity = new DoWhile(prodActivity);
        }
Beispiel #14
0
        public TestFlowElement AddSwitchLink <T>(TestActivity sourceActivity, Dictionary <T, TestFlowElement> cases, List <int> hintsExecutingActivityIndex, T expression, params TestActivity[] defaultActivity)
        {
            TestFlowSwitch <T> flowSwitch = CreateSwitchElement <T>(sourceActivity, null, hintsExecutingActivityIndex, defaultActivity, true) as TestFlowSwitch <T>;

            flowSwitch.Expression = expression;

            foreach (KeyValuePair <T, TestFlowElement> flowCase in cases)
            {
                flowSwitch.AddCase(flowCase.Key, flowCase.Value);
                AddTestFlowLink(flowCase.Value);
            }
            return(AddTestFlowLink(flowSwitch));
        }
Beispiel #15
0
        public void AddNullCase(TestActivity activity)
        {
            TestFlowStep step = null;
            FlowNode     node = null;

            if (activity != null)
            {
                step = new TestFlowStep(activity);
                node = step.GetProductElement();
            }
            (this.productFlowSwitch as FlowSwitch <T>).Cases.Add(default(T), node);
            this.caseElements.Add(step);
        }
Beispiel #16
0
        /// <summary>
        /// Modify the FlowStep's Next to point to a different node
        /// </summary>
        /// <param name="flowStep">FlowStep to be updated</param>
        /// <param name="newNextActivity">new activity to be executed next</param>
        /// <param name="removeOldNextNode">wehther we want to remove the old Next node from Flowchart</param>
        public void ChangeFlowStepNextNode(TestFlowStep flowStep, TestActivity newNextActivity, bool removeOldNextNode = true)
        {
            TestFlowStep newNextNode = null;

            if (newNextActivity != null)
            {
                newNextNode = this.GetFlowStepContainingActionActivity(newNextActivity);
                if (newNextNode == null)
                {
                    newNextNode = new TestFlowStep(newNextActivity);
                }
            }

            this.ChangeFlowStepNextNode(flowStep, newNextNode, removeOldNextNode);
        }
Beispiel #17
0
        public TestFlowElement AddLink(TestActivity sourceActivity, TestFlowElement flowElement)
        {
            TestFlowStep sourceStep = GetFlowStepContainingActionActivity(sourceActivity);

            if (sourceStep == null)
            {
                sourceStep = new TestFlowStep(sourceActivity);
                SetStartNode(sourceStep);
                AddTestFlowLink(sourceStep);
            }

            sourceStep.NextElement = flowElement;
            AddTestFlowLink(flowElement);

            return(sourceStep);
        }
Beispiel #18
0
        internal static void ProcessDirective(TestActivity target, Directive directive, string defaultAction, TraceGroup traceGroup)
        {
            // A directive's action of "*" == "don't care" == "use default action"
            string action = (directive.Action == Directive.Wildcard) ? defaultAction : directive.Action;

            switch (action)
            {
                case Directive.Compensate:
                    target.GetCompensationTrace(traceGroup);
                    break;
                case Directive.Confirm:
                    target.GetConfirmationTrace(traceGroup);
                    break;
                default:
                    throw new Exception(string.Format("Invalid directive {0}", directive));
            }
        }
Beispiel #19
0
        public TestIf(TestActivity condition, params HintThenOrElse[] thenOrElseHint)
        {
            if (!(condition.ProductActivity is Activity <bool> prodActivity))
            {
                throw new ArgumentNullException("ProductActivity");
            }
            this.ProductActivity = new If(prodActivity);

            if (thenOrElseHint == null)
            {
                _thenOrElse = null;
            }
            else
            {
                _thenOrElse = new List <HintThenOrElse>(thenOrElseHint);
            }
        }
Beispiel #20
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);
            }
        }
Beispiel #21
0
        private bool TryFindChildActivity(string targetDisplayName, out TestActivity found)
        {
            if (this.DisplayName == targetDisplayName)
            {
                found = this;
                return(true);
            }

            foreach (TestActivity candidate in this.GetChildren())
            {
                if (candidate.TryFindChildActivity(targetDisplayName, out found))
                {
                    return(true);
                }
            }

            found = null;
            return(false);
        }
 protected override void GetActivitySpecificTrace(TraceGroup traceGroup)
 {
     // Use the anchor as the starting point for the child search
     if (_anchor != null && !_disableTrace)
     {
         // If the target was valid, use that one. Otherwise we need the hints to determine what to do
         if (_target != null)
         {
             TestActivity target = _anchor.Activity.FindChildActivity(_target.Name);
             target.GetConfirmationTrace(traceGroup);
         }
         else
         {
             foreach (Directive directive in _confirmationHint)
             {
                 TestActivity target = _anchor.Activity.FindChildActivity(directive.Name);
                 target.GetConfirmationTrace(traceGroup);
             }
         }
     }
 }
Beispiel #23
0
        internal Outcome GetTriggerTrace(TraceGroup traceGroup)
        {
            Outcome outcome = this.ExpectedOutcome;

            for (int i = 0; i < HintTriggerIterationCount; i++)
            {
                TestActivity trigger = this.Trigger;
                if (this.Trigger == null)
                {
                    trigger = this.Source.NullTrigger;
                }
                outcome = trigger.GetTrace(traceGroup);
            }

            if (HintTriggerScheduled == true)
            {
                traceGroup.Steps.Add(new ActivityTrace(this.Trigger.DisplayName, ActivityInstanceState.Executing));
            }

            _triggerIterationNumber++;
            return(outcome);
        }
Beispiel #24
0
        private TestFlowStep GetFlowStepContainingActionActivity(TestActivity activity)
        {
            if (_startElement == null || activity == null)
            {
                return(null);
            }

            List <TestFlowConditional> conditionals = new List <TestFlowConditional>();
            List <TestFlowSwitchBase>  switches     = new List <TestFlowSwitchBase>();
            TestFlowElement            current      = _startElement;

            while (current != null)
            {
                if (current is TestFlowConditional && !conditionals.Contains((TestFlowConditional)current))
                {
                    conditionals.Add((TestFlowConditional)current);
                }
                else if (current is TestFlowSwitchBase && !switches.Contains((TestFlowSwitchBase)current))
                {
                    switches.Add((TestFlowSwitchBase)current);
                }
                else if (current is TestFlowStep && ((TestFlowStep)current).ActionActivity.DisplayName == activity.DisplayName)
                {
                    //Need to reset the iteration numbers of
                    //flowconditionals and flowSwitched since they will be increment
                    //on GetNextElement()
                    ResetConditionalsIterationCounter(conditionals);
                    ResetSwitchesIterationCounter(switches);
                    return(current as TestFlowStep);
                }
                current = current.GetNextElement();
            }

            ResetConditionalsIterationCounter(conditionals);
            ResetSwitchesIterationCounter(switches);
            return(null);
        }
Beispiel #25
0
 public void SetTargetObjectActivity <T>(TestActivity activity)
 {
     this.ProductInvokeMethod.TargetObject = new InArgument <T>((Activity <T>)activity.ProductActivity);
 }
Beispiel #26
0
 public void SetResultActivity <T>(TestActivity activity)
 {
     this.ProductInvokeMethod.Result = new OutArgument <T>((Activity <Location <T> >)activity.ProductActivity);
 }
Beispiel #27
0
        /// <summary>
        /// Modify FlowSwitch's Case to point to a different activity
        /// </summary>
        /// <param name="flowSwitch">FlowSwitch to be updated</param>
        /// <param name="flowSwitchCase">case whose action to be updated</param>
        /// <param name="newCaseActivity">new activity to be executed in the given FlowSwitch Case</param>
        /// <param name="removeOldCaseNode">wehther we want to remove the old Case node from Flowchart</param>
        public void ChangeFlowSwitchCaseAction <T>(TestFlowSwitch <T> flowSwitch, T caseExpression, int caseIndex, TestActivity oldCaseActivity, TestActivity newCaseActivity, bool removeOldCaseNode = true)
        {
            TestFlowStep oldCaseNode = null;
            TestFlowStep newCaseNode = null;

            // remove old Case node from Flowchart
            if (removeOldCaseNode)
            {
                oldCaseNode = this.GetFlowStepContainingActionActivity(oldCaseActivity);
                if (oldCaseNode == null)
                {
                    throw new ArgumentException("Failed to find the node corresponding to the given oldCaseActivity.");
                }
                this.Elements.Remove(oldCaseNode);
            }

            // add new Case node to Flowchart
            if (newCaseActivity != null)
            {
                newCaseNode = this.GetFlowStepContainingActionActivity(newCaseActivity);
                if (newCaseNode == null)
                {
                    newCaseNode = new TestFlowStep(newCaseActivity);
                }

                this.AddTestFlowLink(newCaseNode);
            }

            // set new Case action
            flowSwitch.UpdateCase(caseExpression, caseIndex, newCaseNode);
        }
Beispiel #28
0
 /// <summary>
 /// Modify the FlowSwitch's Expression activity and its corresponding hint.
 /// </summary>
 public void ChangeFlowSwitchExpression <T>(TestFlowSwitch <T> flowSwitch, TestActivity newExpressionActivity, List <int> newHint)
 {
     flowSwitch.ExpressionActivity = newExpressionActivity;
     flowSwitch.SetHints(newHint);
 }
Beispiel #29
0
        private TestFlowSwitchBase CreateSwitchElement <T>(TestActivity sourceActivity, Dictionary <T, TestActivity> cases, List <int> hintsExecutingActivityIndex, TestActivity[] defaultActivity, bool genericSwitch = false)
        {
            TestFlowStep        flowStep      = null;
            List <TestFlowStep> newAddedSteps = new List <TestFlowStep>();

            TestFlowSwitchBase flowSwitch;

            flowSwitch = new TestFlowSwitch <T>();

            flowSwitch.SetHints(hintsExecutingActivityIndex);

            if (sourceActivity != null)
            {
                flowStep = GetFlowStepContainingActionActivity(sourceActivity);
                if (flowStep == null)
                {
                    flowStep = new TestFlowStep(sourceActivity);
                    AddTestFlowLink(flowStep);
                }
            }

            if (cases != null)
            {
                foreach (KeyValuePair <T, TestActivity> flowCase in cases)
                {
                    TestFlowStep targetStep = GetFlowStepContainingActionActivity(flowCase.Value);
                    if (targetStep == null && flowCase.Value != null)
                    {
                        //Need this to find identical FlowSteps in the cases locally as they are not
                        //added yet to the linked list
                        if ((targetStep = FindMatchingCase(newAddedSteps, flowCase.Value.DisplayName)) == null)
                        {
                            targetStep = new TestFlowStep(flowCase.Value);
                            newAddedSteps.Add(targetStep);
                        }
                        AddTestFlowLink(targetStep);
                    }

                    (flowSwitch as TestFlowSwitch <T>).AddCase(flowCase.Key, targetStep);
                }
            }

            if (defaultActivity != null && defaultActivity.Length != 0)
            {
                TestFlowStep defaultStep = GetFlowStepContainingActionActivity(defaultActivity[0]);
                if (defaultStep == null)
                {
                    if ((defaultStep = FindMatchingCase(newAddedSteps, defaultActivity[0].DisplayName)) == null)
                    {
                        defaultStep = new TestFlowStep(defaultActivity[0]);
                    }
                }

                (flowSwitch as TestFlowSwitch <T>).Default = defaultStep;
                AddTestFlowLink(defaultStep);
            }

            if (flowStep != null)
            {
                flowStep.NextElement = flowSwitch;
            }
            else
            {
                SetStartNode(flowSwitch);
            }

            return(flowSwitch);
        }
Beispiel #30
0
        /// <summary>
        /// Modify the FlowDecision's True or False path to point to a different node
        /// </summary>
        /// <param name="flowConditional">FlowDecision to be updated</param>
        /// <param name="changeTrueAction">true if TrueAction to be changed, false if FalseAction to be changed</param>
        /// <param name="newAction">new activity to be executed on the specified FlowDecision's path</param>
        /// <param name="removeOldNode">wehther we want to remove the old node from Flowchart</param>
        public void ChangeFlowDecisionAction(TestFlowConditional flowConditional, bool changeTrueAction, TestActivity newAction, bool removeOldNode = true)
        {
            // remove old node from Flowchart
            if (removeOldNode)
            {
                if (changeTrueAction)
                {
                    this.Elements.Remove(flowConditional.TrueAction);
                }
                else
                {
                    this.Elements.Remove(flowConditional.FalseAction);
                }
            }

            // add new node to Flowchart
            TestFlowStep newNode = null;

            if (newAction != null)
            {
                newNode = this.GetFlowStepContainingActionActivity(newAction);
                if (newNode == null)
                {
                    newNode = new TestFlowStep(newAction);
                }

                this.AddTestFlowLink(newNode);
            }

            // set new Action
            if (changeTrueAction)
            {
                flowConditional.TrueAction = newNode;
            }
            else
            {
                flowConditional.FalseAction = newNode;
            }
        }