Пример #1
0
        public override object Clone()
        {
            ForEach clone = (ForEach)base.Clone();

            clone.m_children          = new List <Element>();
            clone.TreeNode.ImageIndex = clone.TreeNode.SelectedImageIndex = 5;

            foreach (var child in m_children)
            {
                clone.Add((Element)child.Clone());
            }

            return(clone);
        }
Пример #2
0
        internal override void Run()
        {
            try
            {
                if (RunResult != null)
                {
                    throw new ApplicationException("Clear the results before running again");
                }

                if (CheckBoxes && !TreeNode.Checked)
                {
                    return;
                }

                int repeatCount = int.MaxValue;

                if (RepeatCount != null)
                {
                    int tmp;
                    if (int.TryParse(RepeatCount, out tmp))
                    {
                        repeatCount = tmp;
                    }
                }

                double repeatDuration = double.MaxValue;

                if (RepeatDuration != null)
                {
                    double tmp;
                    if (double.TryParse(RepeatDuration, out tmp))
                    {
                        repeatDuration = tmp;
                    }
                }


                TestResult result    = null;
                DateTime   startTime = DateTime.Now;

                int            counter = 0;
                int            errors = 0, warnings = 0;
                List <ForEach> innerLists = new List <ForEach>();
                DateTime       maxTime    = repeatDuration == double.MaxValue ? DateTime.MaxValue : startTime.AddSeconds(repeatDuration);

                //set a temporary result to be able to refresh the view of partial results
                RunResult           = new ForEachTestResult(TestResults.Executing);
                RunResult.StartTime = startTime;
                ((ForEachTestResult)RunResult).Steps = innerLists;

                IEnumerable collection = GetProperty(inProperty) as IEnumerable;

                foreach (var o in collection)
                {
                    if (counter >= repeatCount || DateTime.Now > maxTime || IsCancelationPending())
                    {
                        break;
                    }

                    SetProperty(Property, o);

                    ForEach clone = (ForEach)Clone();

                    lock ( innerLists )
                    {
                        innerLists.Add(clone);
                    }

                    ReportFinished();

                    TestResult runResult = clone.RunOnce();
                    clone.RunResult = new ForCursorTestResult(runResult, o);

                    switch (runResult.Type)
                    {
                    case TestResults.Failed: errors++;
                        break;

                    case TestResults.Warning: warnings++;
                        break;
                    }

                    counter++;
                }

                ForEachTestResult forResult;

                if (errors > 0)
                {
                    forResult = new ForEachTestResult(TestResults.Failed);
                }
                else if (warnings > 0)
                {
                    forResult = new ForEachTestResult(TestResults.Warning);
                }
                else
                {
                    forResult = new ForEachTestResult(TestResults.Success);
                }

                forResult.StartTime = startTime;
                forResult.Steps     = innerLists;
                result = forResult;


                RunResult = result;
                ReportFinished();
            }
            finally
            {
                WaitHandle.Set();
            }
        }