public void ExploreFile(IFile psiFile, IUnitTestElementsObserver observer, Func<bool> interrupted) { if (!IsProjectFile(psiFile)) return; var elementFactory = new UnitTestElementFactory(services, observer.OnUnitTestElementChanged); psiFile.ProcessDescendants(new XunitPsiFileExplorer(elementFactory, observer, psiFile, interrupted, searchDomainFactory)); observer.OnCompleted(); }
public XunitTestMetadataExplorer(XunitTestProvider provider, UnitTestElementFactory unitTestElementFactory, UnitTestingAssemblyLoader assemblyLoader) { this.provider = provider; this.unitTestElementFactory = unitTestElementFactory; // Hmm. Not sure I like this here - needs to be here so that ReSharper will load // the runner assembly from the external process, so that assumes this was done assemblyLoader.RegisterAssembly(typeof(XunitTaskRunner).Assembly); }
public XunitTestFileExplorer(XunitTestProvider provider, UnitTestProviders providers, UnitTestElementFactory unitTestElementFactory, SearchDomainFactory searchDomainFactory) { this.provider = provider; this.unitTestElementFactory = unitTestElementFactory; this.searchDomainFactory = searchDomainFactory; this.providers = providers; }
internal static IUnitTestElement ReadFromXml(XmlElement parent, IUnitTestElement parentElement, IProject project, string id, UnitTestElementFactory elementFactory) { var typeName = parent.GetAttribute("typeName"); var assemblyLocation = parent.GetAttribute("assemblyLocation"); // TODO: Save and load traits. Might not be necessary - they are reset when scanning the file return(elementFactory.GetOrCreateTestClass(id, project, new ClrTypeName(typeName), assemblyLocation, new OneToSetMap <string, string>())); }
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; }
public void ExploreFile(IFile psiFile, IUnitTestElementsObserver observer, Func <bool> interrupted) { if (!IsProjectFile(psiFile)) { return; } var elementFactory = new UnitTestElementFactory(services, observer.OnUnitTestElementChanged); psiFile.ProcessDescendants(new XunitPsiFileExplorer(elementFactory, observer, psiFile, interrupted, searchDomainFactory)); observer.OnCompleted(); }
protected override ICollection<IUnitTestElement> GetUnitTestElements(IProject testProject, string assemblyLocation) { var elements = base.GetUnitTestElements(testProject, assemblyLocation).ToList(); var element = elements.Single(e => e.ShortName == "HasRunWith") as XunitTestClassElement; var services = testProject.GetComponent<XunitServiceProvider>(); var unitTestElementFactory = new UnitTestElementFactory(services, null); var theoryElement = unitTestElementFactory.GetOrCreateTestMethod(testProject, element, element.TypeName, "TestMethodWithExistingTask", string.Empty, new OneToSetMap<string, string>(), isDynamic: true); elements.Add(theoryElement); return elements; }
// TODO: The nunit code uses UnitTestAttributeCache public XunitPsiFileExplorer(UnitTestElementFactory unitTestElementFactory, IUnitTestElementsObserver observer, IFile file, Func <bool> interrupted, SearchDomainFactory searchDomainFactory) { this.observer = observer; this.unitTestElementFactory = unitTestElementFactory; this.file = file; this.interrupted = interrupted; this.searchDomainFactory = searchDomainFactory; projectFile = file.GetSourceFile().ToProjectFile(); project = file.GetProject(); assemblyPath = project.GetOutputFilePath().FullPath; }
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)); }
public IUnitTestElement DeserializeElement(XmlElement parent, string id, IUnitTestElement parentElement, IProject project) { if (!parent.HasAttribute("type")) throw new ArgumentException("Element is not xunit"); ReadFromXmlFunc func; if (DeserialiseMap.TryGetValue(parent.GetAttribute("type"), out func)) { var unitTestElementFactory = new UnitTestElementFactory(services, null); return func(parent, parentElement, project, id, unitTestElementFactory); } throw new ArgumentException("Element is not xunit"); }
private IUnitTestElement GetDynamicMethodElement(Dictionary <RemoteTask, IUnitTestElement> tasks, XunitTestMethodTask methodTask) { var classElement = (from kvp in tasks where kvp.Key is XunitTestClassTask && IsParentClassTask((XunitTestClassTask)kvp.Key, methodTask) select kvp.Value).FirstOrDefault() as XunitTestClassElement; if (classElement == null) { return(null); } using (ReadLockCookie.Create()) { var project = classElement.GetProject(); if (project == null) { return(null); } var element = UnitTestElementFactory.GetTestMethod(project, classElement, new ClrTypeName(methodTask.TypeName), methodTask.MethodName); // As for theories, make sure we always return an element 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 = classElement; } return(element); } // Dynamic methods - RunWith support // Don't need to give a skip reason - we're adding this during a run, so // we'll be notified if it's skipped // TODO: Add traits var declaredElementProvider = project.GetSolution().GetComponent <DeclaredElementProvider>(); return(UnitTestElementFactory.CreateTestMethod(this, project, declaredElementProvider, classElement, new ClrTypeName(methodTask.TypeName), methodTask.MethodName, string.Empty, EmptyArray <UnitTestElementCategory> .Instance, isDynamic: true)); } }
public IUnitTestElement DeserializeElement(XmlElement parent, string id, IUnitTestElement parentElement, IProject project) { if (!parent.HasAttribute("type")) { throw new ArgumentException("Element is not xunit"); } ReadFromXmlFunc func; if (DeserialiseMap.TryGetValue(parent.GetAttribute("type"), out func)) { var unitTestElementFactory = new UnitTestElementFactory(services, null); return(func(parent, parentElement, project, id, unitTestElementFactory)); } throw new ArgumentException("Element is not xunit"); }
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)); } }
// TODO: The nunit code uses UnitTestAttributeCache public XunitPsiFileExplorer(XunitTestProvider provider, UnitTestElementFactory unitTestElementFactory, UnitTestElementLocationConsumer consumer, IFile file, Func<bool> interrupted, SearchDomainFactory searchDomainFactory) { if (file == null) throw new ArgumentNullException("file"); if (provider == null) throw new ArgumentNullException("provider"); this.consumer = consumer; this.unitTestElementFactory = unitTestElementFactory; this.file = file; this.interrupted = interrupted; this.searchDomainFactory = searchDomainFactory; projectFile = file.GetSourceFile().ToProjectFile(); project = file.GetProject(); assemblyPath = project.GetOutputFilePath().FullPath; }
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 GetDynamicMethodElement(Dictionary <string, IUnitTestElement> tasks, XunitTestMethodTask methodTask) { IUnitTestElement parentElement; if (!tasks.TryGetValue(methodTask.UncollapsedParentTaskId, out parentElement)) { return(null); } var classElement = parentElement as XunitTestClassElement; if (classElement == null) { return(null); } using (ReadLockCookie.Create()) { var project = classElement.Id.GetProject(); if (project == null) { return(null); } // As for theories, make sure we always return an element // TODO: Handle traits, notify unit test element manager var services = project.GetSolution().GetComponent <XunitServiceProvider>(); var unitTestElementFactory = new UnitTestElementFactory(services, null, enableCache: false); var element = unitTestElementFactory.GetOrCreateTestMethod(classElement.Id.Project, classElement, new ClrTypeName(methodTask.TypeName), methodTask.MethodName, string.Empty, new OneToSetMap <string, string>(), isDynamic: true); element.State = UnitTestElementState.Dynamic; return(element); } }
internal static IUnitTestElement ReadFromXml(XmlElement parent, IUnitTestElement parentElement, ISolution solution, UnitTestElementFactory unitTestElementFactory) { var projectId = parent.GetAttribute("projectId"); var typeName = parent.GetAttribute("typeName"); var project = (IProject)ProjectUtil.FindProjectElementByPersistentID(solution, projectId); if (project == null) { return(null); } var assemblyLocation = project.GetOutputFilePath().FullPath; // TODO: Save and load traits. Might not be necessary - they are reset when scanning the file return(unitTestElementFactory.GetOrCreateTestClass(project, new ClrTypeName(typeName), assemblyLocation, new MultiValueDictionary <string, string>())); }
private IUnitTestElement GetDynamicMethodElement(Dictionary<string, IUnitTestElement> tasks, XunitTestMethodTask methodTask) { IUnitTestElement parentElement; if (!tasks.TryGetValue(methodTask.UncollapsedParentTaskId, out parentElement)) return null; var classElement = parentElement as XunitTestClassElement; if (classElement == null) return null; using (ReadLockCookie.Create()) { var project = classElement.Id.GetProject(); if (project == null) return null; // As for theories, make sure we always return an element // TODO: Handle traits, notify unit test element manager var services = project.GetSolution().GetComponent<XunitServiceProvider>(); var unitTestElementFactory = new UnitTestElementFactory(services, null, enableCache: false); var element = unitTestElementFactory.GetOrCreateTestMethod(classElement.Id.Project, classElement, new ClrTypeName(methodTask.TypeName), methodTask.MethodName, string.Empty, new OneToSetMap<string, string>(), isDynamic: true); element.State = UnitTestElementState.Dynamic; return element; } }
public XunitTestMetadataExplorer(UnitTestElementFactory unitTestElementFactory) { this.unitTestElementFactory = unitTestElementFactory; }
internal static IUnitTestElement ReadFromXml(XmlElement parent, IUnitTestElement parentElement, ISolution solution, UnitTestElementFactory unitTestElementFactory) { var testClass = parentElement as XunitTestClassElement; if (testClass == null) { throw new InvalidOperationException("parentElement should be xUnit.net test class"); } var typeName = parent.GetAttribute("typeName"); var methodName = parent.GetAttribute("methodName"); var projectId = parent.GetAttribute("projectId"); var skipReason = parent.GetAttribute("skipReason"); var isDynamic = parent.GetAttribute("dynamic", false); var project = (IProject)ProjectUtil.FindProjectElementByPersistentID(solution, projectId); if (project == null) { return(null); } // TODO: Save and load traits. Not sure it's really necessary, they get updated when the file is scanned return(unitTestElementFactory.GetOrCreateTestMethod(project, testClass, new ClrTypeName(typeName), methodName, skipReason, new MultiValueDictionary <string, string>(), isDynamic)); }
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; } }
internal static IUnitTestElement ReadFromXml(XmlElement parent, IUnitTestElement parentElement, IProject project, string id, UnitTestElementFactory unitTestElementFactory) { var testClass = parentElement as XunitTestClassElement; if (testClass == null) { throw new InvalidOperationException("parentElement should be xUnit.net test class"); } var typeName = parent.GetAttribute("typeName"); var methodName = parent.GetAttribute("methodName"); var skipReason = parent.GetAttribute("skipReason"); var isDynamic = parent.GetAttribute("dynamic", false); // TODO: Save and load traits. Not sure it's really necessary, they get updated when the file is scanned return(unitTestElementFactory.GetOrCreateTestMethod(id, project, testClass, new ClrTypeName(typeName), methodName, skipReason, new OneToSetMap <string, string>(), isDynamic)); }
public XunitTestElementSerializer(XunitTestProvider provider, UnitTestElementFactory unitTestElementFactory, ISolution solution) { this.provider = provider; this.unitTestElementFactory = unitTestElementFactory; this.solution = solution; }