protected override ICollection<IUnitTestElement> GetUnitTestElements(IProject testProject, string assemblyLocation) { var elements = base.GetUnitTestElements(testProject, assemblyLocation).ToList(); var services = testProject.GetComponent<XunitServiceProvider>(); var unitTestElementFactory = new UnitTestElementFactory(services, null); var theoryElement = unitTestElementFactory.GetOrCreateTestTheory(testProject, (XunitTestMethodElement) elements[1], "TestMethod(value: 42)"); elements.Add(theoryElement); return elements; }
internal static IUnitTestElement ReadFromXml(XmlElement parent, IUnitTestElement parentElement, IProject project, string id, UnitTestElementFactory unitTestElementFactory) { var methodElement = parentElement as XunitTestMethodElement; if (methodElement == null) { throw new InvalidOperationException("parentElement should be xUnit.net test method"); } var name = parent.GetAttribute("name"); return(unitTestElementFactory.GetOrCreateTestTheory(id, project, methodElement, name)); }
private IUnitTestElement GetDynamicTheoryElement(Dictionary <string, IUnitTestElement> tasks, XunitTestTheoryTask theoryTask) { IUnitTestElement parentElement; if (!tasks.TryGetValue(theoryTask.UncollapsedParentTaskId, out parentElement)) { return(null); } var methodElement = parentElement as XunitTestMethodElement; if (methodElement == null) { return(null); } using (ReadLockCookie.Create()) { var project = methodElement.Id.GetProject(); if (project == null) { return(null); } // 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 var services = project.GetSolution().GetComponent <XunitServiceProvider>(); var unitTestElementFactory = new UnitTestElementFactory(services, null, false); var element = unitTestElementFactory.GetOrCreateTestTheory(methodElement.Id.Project, methodElement, theoryTask.TheoryName); element.State = UnitTestElementState.Dynamic; return(element); } }
private IUnitTestElement GetDynamicTheoryElement(Dictionary<string, IUnitTestElement> tasks, XunitTestTheoryTask theoryTask) { IUnitTestElement parentElement; if (!tasks.TryGetValue(theoryTask.UncollapsedParentTaskId, out parentElement)) return null; var methodElement = parentElement as XunitTestMethodElement; if (methodElement == null) return null; using (ReadLockCookie.Create()) { var project = methodElement.Id.GetProject(); if (project == null) return null; // 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 var services = project.GetSolution().GetComponent<XunitServiceProvider>(); var unitTestElementFactory = new UnitTestElementFactory(services, null, false); var element = unitTestElementFactory.GetOrCreateTestTheory(methodElement.Id.Project, methodElement, theoryTask.TheoryName); element.State = UnitTestElementState.Dynamic; return element; } }