private void AppendTests(XunitTestClassElement classElement, ITypeInfo typeInfo, IEnumerable <IDeclaredType> types) { foreach (var declaredType in types) { if (declaredType.GetClrName().Equals(PredefinedType.OBJECT_FQN)) { continue; } var typeElement = declaredType.GetTypeElement(); if (typeElement != null) { var methodInfo = new PsiMethodInfoAdapter(); foreach (var method in typeElement.GetMembers().OfType <IMethod>()) { methodInfo.Reset(method, typeInfo); if (MethodUtility.IsTest(methodInfo)) { var element = unitTestElementFactory.GetOrCreateTestMethod(project, classElement, typeElement.GetClrName(), method.ShortName, MethodUtility.GetSkipReason(methodInfo), methodInfo.GetTraits(), false); observer.OnUnitTestElementDisposition(UnitTestElementDisposition.NotYetClear(element)); } } } } }
private void ExploreTestMethod(IProject project, XunitTestClassElement classUnitTestElement, IUnitTestElementsObserver observer, IMethodInfo methodInfo) { var methodUnitTestElement = unitTestElementFactory.GetOrCreateTestMethod(project, classUnitTestElement, new ClrTypeName(methodInfo.TypeName), methodInfo.Name, MethodUtility.GetSkipReason(methodInfo), methodInfo.GetTraits(), false); observer.OnUnitTestElement(methodUnitTestElement); }
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 void ExploreTestMethod(IProject project, XunitTestClassElement classUnitTestElement, UnitTestElementConsumer consumer, IMethodInfo methodInfo) { var methodUnitTestElement = unitTestElementFactory.GetOrCreateTestMethod(project, classUnitTestElement, new ClrTypeName(methodInfo.TypeName), methodInfo.Name, MethodUtility.GetSkipReason(methodInfo), methodInfo.SafelyGetTraits(), false); consumer(methodUnitTestElement); }
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; }
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)); }
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); } }
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; } }