Exemplo n.º 1
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);
        }
        private IUnitTestElement ProcessTestMethodInAbstractClass(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 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 == 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 MultiValueDictionary<string, string>(), false);
                }

                subElements.Add(methodInDerivedClass);
            }

            return inheritedTestMethodContainerElement;
        }