private IUnitTestElement ProcessTestClass(IClass testClass)
        {
            if (testClass.IsAbstract)
                return ProcessAbstractTestClass(testClass);

            var typeInfo = testClass.AsTypeInfo();
            if (!IsValidTestClass(testClass))
                return null;

            XunitTestClassElement testElement;

            if (!classes.TryGetValue(testClass, out testElement))
            {
                var clrTypeName = testClass.GetClrName();
                testElement = unitTestElementFactory.GetOrCreateTestClass(project, clrTypeName, assemblyPath, typeInfo.GetTraits());

                classes.Add(testClass, testElement);
            }

            if (testElement != null)
            {
                foreach (var testMethod in IsInThisFile(testElement.Children))
                    testMethod.State = UnitTestElementState.Pending;

                // TODO: I think this might be an edge case with RunWith
                // We'll add Fact based methods for classes with RunWith + Facts in base classes
                AppendTests(testElement, typeInfo, testClass.GetAllSuperTypes());
            }

            return testElement;
        }
        private IUnitTestElement ProcessAbstractTestClass(IClass testClass)
        {
            var typeInfo = testClass.AsTypeInfo();

            if (!TypeUtility.ContainsTestMethods(typeInfo))
            {
                return(null);
            }

            var solution           = testClass.GetSolution();
            var inheritorsConsumer = new InheritorsConsumer();

            solution.GetPsiServices().Finder.FindInheritors(testClass, searchDomainFactory.CreateSearchDomain(solution, true),
                                                            inheritorsConsumer, NullProgressIndicator.Instance);

            var elements = new List <XunitTestClassElement>();

            foreach (var element in inheritorsConsumer.FoundElements)
            {
                var declaration = element.GetDeclarations().FirstOrDefault();
                if (declaration != null)
                {
                    var elementProject      = declaration.GetProject();
                    var elementAssemblyPath = assemblyPath;
                    if (!Equals(project, elementProject))
                    {
                        elementAssemblyPath = elementProject.GetOutputFilePath().FullPath;
                    }

                    var classElement = unitTestElementFactory.GetOrCreateTestClass(elementProject, element.GetClrName().GetPersistent(), elementAssemblyPath, typeInfo.GetTraits());
                    AppendTests(classElement, typeInfo, element.GetAllSuperTypes());

                    elements.Add(classElement);
                }
            }

            derivedTestClassElements[testClass] = elements;

            return(null);
        }
        private IUnitTestElement ProcessTestClass(IClass testClass)
        {
            if (IsAbstractClass(testClass))
            {
                return(ProcessAbstractTestClass(testClass));
            }

            var typeInfo = testClass.AsTypeInfo();

            if (!IsValidTestClass(testClass))
            {
                return(null);
            }

            XunitTestClassElement testElement;

            if (!classes.TryGetValue(testClass, out testElement))
            {
                var clrTypeName = testClass.GetClrName();
                testElement = unitTestElementFactory.GetOrCreateTestClass(project, clrTypeName, assemblyPath, typeInfo.GetTraits());

                classes.Add(testClass, testElement);
            }

            if (testElement != null)
            {
                foreach (var testMethod in IsInThisFile(testElement.Children))
                {
                    testMethod.State = UnitTestElementState.Pending;
                }

                AppendTests(testElement, typeInfo, testClass.GetAllSuperTypes());
            }

            return(testElement);
        }
 private static bool IsDirectUnitTestClass(IClass @class)
 {
     return @class != null && IsExportedType(@class) && TypeUtility.IsTestClass(@class.AsTypeInfo());
 }
 private static bool IsValidTestClass(IClass testClass)
 {
     return UnitTestElementIdentifier.IsUnitTestContainer(testClass) && !HasUnsupportedRunWith(testClass.AsTypeInfo());
 }
Exemple #6
0
 private static bool IsDirectUnitTestClass(IClass @class)
 {
     return(@class != null && IsExportedType(@class) && TypeUtility.IsTestClass(@class.AsTypeInfo()));
 }