public XunitTestTheoryElement GetOrCreateTestTheory(IProject project, XunitTestMethodElement methodElement,
                                                            string name)
        {
            var id = string.Format("{0}.{1}", methodElement.Id.Id, GetTestTheoryShortName(name, methodElement));

            return(GetOrCreateTestTheory(id, project, methodElement, name));
        }
        public static XunitTestTheoryElement GetTestTheory(IProject project, XunitTestMethodElement methodElement, string name)
        {
            var id = GetTestTheoryId(methodElement, GetTestTheoryShortName(name, methodElement));
            var unitTestElementManager = project.GetSolution().GetComponent <IUnitTestElementManager>();

            return(unitTestElementManager.GetElementById(project, id) as XunitTestTheoryElement);
        }
        private static string GetTestTheoryShortName(string theoryName, XunitTestMethodElement methodElement)
        {
            // It's safe to pass in an existing shortname here
            var prefix = methodElement.TypeName.FullName + ".";
            var name   = theoryName.StartsWith(prefix) ? theoryName.Substring(prefix.Length) : theoryName;

            return(DisplayNameUtil.Escape(name));
        }
 public XunitTestTheoryElement(IUnitTestProvider provider, XunitTestMethodElement methodElement,
                               ProjectModelElementEnvoy projectModelElementEnvoy, string id,
                               string shortName)
     : base(provider, methodElement, id, projectModelElementEnvoy, new JetHashSet <string>())
 {
     SetState(UnitTestElementState.Dynamic);
     ShortName      = shortName;
     ExplicitReason = string.Empty;
 }
 public XunitTestTheoryElement(IUnitTestProvider provider, XunitTestMethodElement methodElement,
                               ProjectModelElementEnvoy projectModelElementEnvoy, string id,
                               string shortName, IEnumerable <UnitTestElementCategory> categories)
     : base(provider, methodElement, id, projectModelElementEnvoy, categories)
 {
     SetState(UnitTestElementState.Dynamic);
     ShortName      = shortName;
     ExplicitReason = string.Empty;
 }
        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;
        }
        public XunitTestTheoryElement GetOrCreateTestTheory(string id, IProject project,
                                                            XunitTestMethodElement methodElement, string name)
        {
            lock (lockObject)
            {
                var elementId = services.CreateId(project, id);
                var element   = GetElementById <XunitTestTheoryElement>(elementId);
                if (element == null)
                {
                    var shortName = GetTestTheoryShortName(name, methodElement);
                    element = new XunitTestTheoryElement(services, elementId, methodElement.TypeName, shortName);
                    CacheElement(elementId, element);
                }

                element.Parent = methodElement;
                element.State  = UnitTestElementState.Valid;

                // Traits don't have their own categories, but can inherit from method and class
                UpdateCategories(element, EmptyArray <UnitTestElementCategory> .Instance);

                return(element);
            }
        }
        public XunitTestMethodElement GetOrCreateTestMethod(string id, IProject project,
                                                            XunitTestClassElement testClassElement,
                                                            IClrTypeName typeName, string methodName,
                                                            string skipReason, OneToSetMap <string, string> traits,
                                                            bool isDynamic)
        {
            lock (lockObject)
            {
                var elementId = services.CreateId(project, id);
                var element   = GetElementById <XunitTestMethodElement>(elementId);
                if (element == null)
                {
                    element = new XunitTestMethodElement(services, elementId, typeName, methodName, skipReason, isDynamic);
                    CacheElement(elementId, element);
                }

                element.Parent = testClassElement;
                element.State  = UnitTestElementState.Valid;

                UpdateCategories(element, traits);

                return(element);
            }
        }
 private static string GetTestTheoryId(XunitTestMethodElement methodElement, string shortName)
 {
     return(string.Format("{0}.{1}", methodElement.Id, shortName));
 }
        private static string GetTestTheoryShortName(string theoryName, XunitTestMethodElement methodElement)
        {
            var prefix = methodElement.TypeName.FullName + ".";

            return(theoryName.StartsWith(prefix) ? theoryName.Substring(prefix.Length) : theoryName);
        }
        public XunitTestTheoryElement GetOrCreateTestTheory(IProject project, XunitTestMethodElement methodElement, string name)
        {
            var element = GetTestTheory(project, methodElement, name);

            return(element ?? CreateTestTheory(provider, project, methodElement, name));
        }
        public static XunitTestTheoryElement CreateTestTheory(IUnitTestProvider provider, IProject project, XunitTestMethodElement methodElement, string name)
        {
            var shortName = GetTestTheoryShortName(name, methodElement);
            var id        = GetTestTheoryId(methodElement, shortName);

            return(new XunitTestTheoryElement(provider, methodElement, new ProjectModelElementEnvoy(project), id, shortName));
        }