예제 #1
0
            public void TestMethodsCanHaveNonVoidReturnType()
            {
                Type       testClassType = typeof(NonVoidReturnClass);
                MethodInfo methodInfo    = testClassType.GetMethod("NonVoidTest");

                Assert.True(MethodUtility.IsTest(Reflector.Wrap(methodInfo)));
            }
예제 #2
0
            public void TestMethodIsAbstract()
            {
                Type       testClassType = typeof(AbstractMethodClass);
                MethodInfo methodInfo    = testClassType.GetMethod("AbstractMethod");

                Assert.False(MethodUtility.IsTest(Reflector.Wrap(methodInfo)));
            }
예제 #3
0
            public void TestMethodIsStatic()
            {
                Type       testClassType = typeof(StaticTestMethodClass);
                MethodInfo methodInfo    = testClassType.GetMethod("StaticTestMethod");

                Assert.True(MethodUtility.IsTest(Reflector.Wrap(methodInfo)));
            }
예제 #4
0
            public void MethodDoesNotHaveTestAttribute()
            {
                Type       testClassType = typeof(NoTestAttributeClass);
                MethodInfo methodInfo    = testClassType.GetMethod("NoTestAttribute");

                Assert.False(MethodUtility.IsTest(Reflector.Wrap(methodInfo)));
            }
예제 #5
0
        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));
                        }
                    }
                }
            }
        }
예제 #6
0
        private IUnitTestElement ProcessTestMethodInAbstractClass(ITypeInfo typeInfo, IMethod method, IList <IUnitTestElement> subElements)
        {
            var containingType = method.GetContainingType();

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

            IList <XunitTestClassElement> derivedElements;

            if (!derivedTestClassElements.TryGetValue(containingType, out derivedElements))
            {
                return(null);
            }

            var methodInfo = method.AsMethodInfo(typeInfo);

            if (!MethodUtility.IsTest(methodInfo))
            {
                return(null);
            }

            var inheritedTestMethodContainerElement = unitTestElementFactory.GetOrCreateInheritedTestMethodContainer(project,
                                                                                                                     containingType.GetClrName(), method.ShortName);

            foreach (var derivedClassElement in derivedElements)
            {
                XunitTestMethodElement methodInDerivedClass = null;
                foreach (var testMethodElement in derivedClassElement.Children.OfType <XunitTestMethodElement>())
                {
                    if (testMethodElement.Id.Equals(inheritedTestMethodContainerElement.Id))
                    {
                        testMethodElement.State = UnitTestElementState.Valid;
                        methodInDerivedClass    = testMethodElement;
                        break;
                    }
                }

                if (methodInDerivedClass == null)
                {
                    // TODO: Add traits
                    methodInDerivedClass = unitTestElementFactory.GetOrCreateTestMethod(project, derivedClassElement,
                                                                                        containingType.GetClrName().GetPersistent(), method.ShortName, string.Empty,
                                                                                        new OneToSetMap <string, string>(), false);
                }

                subElements.Add(methodInDerivedClass);
            }

            return(inheritedTestMethodContainerElement);
        }
예제 #7
0
        private static bool IsUnitTestMethod(IMethod testMethod)
        {
            if (testMethod == null)
            {
                return(false);
            }
            var containingType = testMethod.GetContainingType() as IClass;

            if (containingType == null)
            {
                return(false);
            }
            return(MethodUtility.IsTest(testMethod.AsMethodInfo(containingType.AsTypeInfo())));
        }
 public bool IsTestMethod(IMethodInfo testMethod)
 {
     return(MethodUtility.IsTest(testMethod));
 }
예제 #9
0
        public static bool IsUnitTest(this IDeclaredElement element)
        {
            var testMethod = element as IMethod;

            return(testMethod != null && MethodUtility.IsTest(testMethod.AsMethodInfo()));
        }