예제 #1
0
        internal override IEnumerable <TestActivity> GetChildren()
        {
            List <TestFlowConditional> conditionals = new List <TestFlowConditional>();
            List <TestFlowSwitchBase>  switches     = new List <TestFlowSwitchBase>();
            List <TestActivity>        activities   = new List <TestActivity>();

            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 != null)
                {
                    activities.Add(((TestFlowStep)current).ActionActivity);
                }
                current = current.GetNextElement();
            }

            ResetConditionalsIterationCounter(conditionals);
            ResetSwitchesIterationCounter(switches);
            return(activities);
        }
예제 #2
0
 protected void AddFlowElement(TestFlowElement item)
 {
     if (_startElement == null)
     {
         SetStartNode(item);
     }
     ((Flowchart)ProductActivity).Nodes.Add(item.GetProductElement());
 }
예제 #3
0
 // This overload is for more complicated scenarios
 private TestFlowElement AddTestFlowLink(TestFlowElement flowchartElement)
 {
     if (!_elements.Contains(flowchartElement))
     {
         _elements.Add(flowchartElement);
     }
     return(flowchartElement);
 }
예제 #4
0
        /// <summary>
        /// Return the node that the given FlowSwitch will execute based on the hint and cases set.
        ///
        /// Note that this function works only for FlowSwitch that is NOT in a loop.
        /// </summary>
        public TestFlowElement GetFlowSwitchChosenNode(TestFlowSwitchBase flowSwitch)
        {
            TestFlowElement chosenCase = flowSwitch.GetNextElement();

            ResetSwitchesIterationCounter(new List <TestFlowSwitchBase>()
            {
                flowSwitch
            });                                                                            // reset the iteration counter to erase the side-effect caused by GetNextElement();
            return(chosenCase);
        }
예제 #5
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);
        }
예제 #6
0
        /// <summary>
        /// Modify the FlowStep's Next to point to a different node.
        ///
        /// This function is useful when we try to swap nodes because GetFlowStepContainingActionActivity()
        /// use the GetNextElement() to loop through all elements, as a result, it won't be able to loop
        /// through all the this.Elements in the middle of swapping.
        /// </summary>
        /// <param name="flowStep">FlowStep to be updated</param>
        /// <param name="newNextNode">new node 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, TestFlowElement newNextNode, bool removeOldNextNode = true)
        {
            // remove old Next node from Flowchart
            if (removeOldNextNode)
            {
                this.Elements.Remove(flowStep.NextElement);
            }

            // add new Next node to Flowchart
            if (newNextNode != null)
            {
                this.AddTestFlowLink(newNextNode);
            }

            // set new Next node
            flowStep.NextElement = newNextNode;
        }
예제 #7
0
        /// <summary>
        /// Update the activity to execute of the given caseExpression/caseIndex
        /// </summary>
        /// <param name="caseExpression">used for locating the case in the product</param>
        /// <param name="caseIndex">used for locating the case in the test object</param>
        /// <param name="newElement">new node to be added to FlowSwitch</param>
        internal void UpdateCase(T caseExpression, int caseIndex, TestFlowElement newElement)
        {
            if (caseIndex < 0 || caseIndex >= this.caseElements.Count)
            {
                throw new ArgumentException("Given caseIndex is out of range.");
            }

            if (caseExpression == null)
            {
                throw new ArgumentException("Given caseExpression is null.");
            }

            if (!(this.productFlowSwitch as FlowSwitch <T>).Cases.ContainsKey(caseExpression))
            {
                throw new ArgumentException("Given caseExpression cannot be found in the set of cases.");
            }

            (this.productFlowSwitch as FlowSwitch <T>).Cases[caseExpression] = (newElement == null) ? null : newElement.GetProductElement();

            this.caseElements.RemoveAt(caseIndex);
            this.caseElements.Insert(caseIndex, newElement);
        }
예제 #8
0
        protected Outcome GetTrace <T>(TraceGroup traceGroup)
        {
            Outcome outcome = Outcome.Completed;

            switch (expressionType)
            {
            case ExpressionType.Activity:
                outcome = this.expressionActivity.GetTrace(traceGroup);

                if (outcome.DefaultPropogationState != OutcomeState.Completed)
                {
                    return(outcome);
                }
                break;

            case ExpressionType.Literal:
                new TestDummyTraceActivity(typeof(Literal <T>), Outcome.Completed).GetTrace(traceGroup);
                break;

            case ExpressionType.VisualBasicValue:
                new TestDummyTraceActivity(typeof(LambdaValue <T>), Outcome.Completed).GetTrace(traceGroup);
                break;

            case ExpressionType.VariableValue:
                new TestDummyTraceActivity(typeof(VariableValue <T>), Outcome.Completed).GetTrace(traceGroup);
                break;

            default: break;
            }

            TestFlowElement element = GetNextElement();

            if (element != null)
            {
                return(element.GetTrace(traceGroup));
            }
            return(Outcome.Completed);
        }
예제 #9
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);
        }
예제 #10
0
 protected bool RemoveFlowElementItem(TestFlowElement item)
 {
     return(((Flowchart)ProductActivity).Nodes.Remove(item.GetProductElement()));
 }
예제 #11
0
 private void SetStartNode(TestFlowElement startElement)
 {
     _startElement = startElement;
     ((Flowchart)ProductActivity).StartNode = startElement.GetProductElement();
 }
예제 #12
0
 public TestFlowElement AddConditionalLink(TestActivity sourceActivity, TestFlowConditional flowConditional, TestFlowElement trueFlowElement, TestFlowElement falseFlowElement)
 {
     AddConditionalLink(sourceActivity, flowConditional, (TestActivity)null, (TestActivity)null);
     flowConditional.TrueAction  = trueFlowElement;
     flowConditional.FalseAction = falseFlowElement;
     AddTestFlowLink(trueFlowElement);
     AddTestFlowLink(falseFlowElement);
     return(flowConditional);
 }
예제 #13
0
 internal void AddCase(T expression, TestFlowElement element)
 {
     (this.productFlowSwitch as FlowSwitch <T>).Cases.Add(expression, element == null ? null : element.GetProductElement());
     this.caseElements.Add(element);
 }