예제 #1
0
        public TestClassElement GetOrCreateTestClass(
            IProject project,
            IClrTypeName typeName,
            string assemblyLocation)
        {
            var id      = GetClassElementId(project, typeName);
            var element = unitTestManager.GetElementById(project, id);

            if (element != null)
            {
                element.State = UnitTestElementState.Valid;
                var classElement = element as TestClassElement;
                return(classElement);
            }

            return(new TestClassElement(
                       provider,
                       new ProjectModelElementEnvoy(project),
                       declaredElementProvider,
                       id,
                       typeName.GetPersistent(),
                       assemblyLocation));
        }
        public XunitTestClassElement GetOrCreateTestClass(IProject project, IClrTypeName typeName, string assemblyLocation, MultiValueDictionary <string, string> traits)
        {
            var categories = GetCategories(traits);

            // dotCover displays the ids of covering tests, rather than a more presentable
            // name. That makes the "xunit" and project identifiers rather ugly. Fortunately,
            // dotCover will ignore any text in square brackets
            var id      = string.Format("[xunit:{0}]{1}", project.GetPersistentID(), typeName.FullName);
            var element = unitTestManager.GetElementById(project, id);

            if (element != null)
            {
                element.State = UnitTestElementState.Valid;
                var classElement = element as XunitTestClassElement;
                if (classElement != null)                             // Shouldn't be null, unless someone else has the same id
                {
                    classElement.AssemblyLocation = assemblyLocation; // In case it's changed, e.g. someone's switched from Debug to Release
                    classElement.SetCategories(categories);
                }
                return(classElement);
            }

            return(new XunitTestClassElement(provider, new ProjectModelElementEnvoy(project), declaredElementProvider, id, typeName.GetPersistent(), assemblyLocation, categories));
        }