Exemple #1
0
        private IUnitTestElement GetDynamicTheoryElement(Dictionary <RemoteTask, IUnitTestElement> tasks, XunitTestTheoryTask theoryTask)
        {
            var methodElement = (from kvp in tasks
                                 where kvp.Key is XunitTestMethodTask &&
                                 IsParentMethodTask((XunitTestMethodTask)kvp.Key, theoryTask)
                                 select kvp.Value).FirstOrDefault() as XunitTestMethodElement;

            if (methodElement == null)
            {
                return(null);
            }

            using (ReadLockCookie.Create())
            {
                var project = methodElement.GetProject();
                if (project == null)
                {
                    return(null);
                }

                var element = UnitTestElementFactory.GetTestTheory(project, methodElement, theoryTask.TheoryName);

                // Make sure we return an element, even if the system already knows about it. If it's
                // part of the test run, it will already have been added in GetTaskSequence, and this
                // method (GetDynamicElement) doesn't get called. But if you try and run just a single
                // theory, xunit will run ALL theories for that method, and will need the elements
                // for those theories not included in the task sequence. This is necessary because if
                // one of those theories throws an exception, UnitTestLaunch.TaskException doesn't
                // have an element to report against, and displays a message box
                if (element != null)
                {
                    // If the element is invalid, it's been removed from its parent, so add it back,
                    // and reset the state
                    if (element.State == UnitTestElementState.Invalid)
                    {
                        element.State  = UnitTestElementState.Dynamic;
                        element.Parent = methodElement;
                    }

                    element.SetCategories(methodElement.Categories);
                    return(element);
                }

                return(UnitTestElementFactory.CreateTestTheory(this, project, methodElement, theoryTask.TheoryName));
            }
        }