Exemple #1
0
        /// <summary>
        /// Creates a work item.
        /// </summary>
        /// <param name="test">The test for which this WorkItem is being created.</param>
        /// <param name="filter">The filter to be used in selecting any child Tests.</param>
        /// <param name="debugger">An <see cref="IDebugger" /> instance.</param>
        /// <param name="recursive">True if child work items should be created and added.</param>
        /// <param name="root"><see langword="true"/> if work item needs to be created unconditionally, if <see langword="false"/> <see langword="null"/> will be returned for tests that don't match the filter.</param>
        /// <returns></returns>
        internal static WorkItem CreateWorkItem(ITest test, ITestFilter filter, IDebugger debugger, bool recursive = false, bool root = true)
        {
            // Run filter on leaf nodes only
            // use the presence of leaf nodes as an indicator that parent need to be created
            // Always create a workitem for the root node
            TestSuite suite = test as TestSuite;

            if (suite == null)
            {
                if (root || filter.Pass(test))
                {
                    return(new SimpleWorkItem((TestMethod)test, filter, debugger));
                }
                return(null);
            }

            CompositeWorkItem work = root ? new CompositeWorkItem(suite, filter): null;

            if (recursive)
            {
                int countOrderedItems = 0;

                foreach (var childTest in suite.Tests)
                {
                    var childItem = CreateWorkItem(childTest, filter, debugger, recursive, root: false);
                    if (childItem == null)
                    {
                        continue;
                    }

                    work ??= new CompositeWorkItem(suite, filter);

                    if (childItem.TargetApartment == ApartmentState.Unknown && work.TargetApartment != ApartmentState.Unknown)
                    {
                        childItem.TargetApartment = work.TargetApartment;
                    }

                    if (childTest.Properties.ContainsKey(PropertyNames.Order))
                    {
                        work.Children.Insert(0, childItem);
                        countOrderedItems++;
                    }
                    else
                    {
                        work.Children.Add(childItem);
                    }
                }

                if (countOrderedItems > 0)
                {
                    work.Children.Sort(0, countOrderedItems, new WorkItemOrderComparer());
                }
            }
            return(work);
        }
Exemple #2
0
        /// <summary>
        /// Creates a work item.
        /// </summary>
        /// <param name="test">The test for which this WorkItem is being created.</param>
        /// <param name="filter">The filter to be used in selecting any child Tests.</param>
        /// <param name="recursive">True if child work items should be created and added.</param>
        /// <returns></returns>
        static public WorkItem CreateWorkItem(ITest test, ITestFilter filter, bool recursive = false)
        {
            TestSuite suite = test as TestSuite;

            if (suite == null)
            {
                return(new SimpleWorkItem((TestMethod)test, filter));
            }

            var work = new CompositeWorkItem(suite, filter);

            if (recursive)
            {
                int countOrderedItems = 0;

                foreach (var childTest in suite.Tests)
                {
                    if (filter.Pass(childTest))
                    {
                        var childItem = CreateWorkItem(childTest, filter, recursive);

#if APARTMENT_STATE
                        if (childItem.TargetApartment == ApartmentState.Unknown && work.TargetApartment != ApartmentState.Unknown)
                        {
                            childItem.TargetApartment = work.TargetApartment;
                        }
#endif

                        if (childTest.Properties.ContainsKey(PropertyNames.Order))
                        {
                            work.Children.Insert(0, childItem);
                            countOrderedItems++;
                        }
                        else
                        {
                            work.Children.Add(childItem);
                        }
                    }
                }

                if (countOrderedItems > 0)
                {
                    work.Children.Sort(0, countOrderedItems, new WorkItemOrderComparer());
                }
            }

            return(work);
        }
        private void SkipChildren(CompositeWorkItem workItem, ResultState resultState, string message)
        {
            foreach (WorkItem child in workItem.Children)
            {
                child.Result.SetResult(resultState, message);
                _suiteResult.AddResult(child.Result);

                // Some runners may depend on getting the TestFinished event
                // even for tests that have been skipped at a higher level.
                Context.Listener.TestFinished(child.Result);

                if (child is CompositeWorkItem)
                {
                    SkipChildren((CompositeWorkItem)child, resultState, message);
                }
            }
        }
 /// <summary>
 /// Construct a OneTimeTearDownWOrkItem wrapping a CompositeWorkItem
 /// </summary>
 /// <param name="originalItem">The CompositeWorkItem being wrapped</param>
 public OneTimeTearDownWorkItem(CompositeWorkItem originalItem)
     : base(originalItem)
 {
     _originalWorkItem = originalItem;
 }