Beispiel #1
0
        public static GallioTestElement CreateFromTest(TestData test, ICodeElementInfo codeElement, GallioTestProvider provider, GallioTestElement parent)
        {
            if (test == null)
            {
                throw new ArgumentNullException("test");
            }

            // The idea here is to generate a test element object that does not retain any direct
            // references to the code element info and other heavyweight objects.  A test element may
            // survive in memory for quite a long time so we don't want it holding on to all sorts of
            // irrelevant stuff.  Basically we flatten out the test to just those properties that we
            // need to keep.
            var project = ReSharperReflectionPolicy.GetProject(codeElement);
            var element = GetElementById(project, test.Id);

            if (element == null)
            {
                element = new GallioTestElement(provider, parent,
                                                test.Id,
                                                test.Name,
                                                test.Metadata.GetValue(MetadataKeys.TestKind) ?? "Unknown",
                                                test.IsTestCase,
                                                project,
                                                ReSharperReflectionPolicy.GetDeclaredElementResolver(codeElement),
                                                GetAssemblyPath(codeElement),
                                                GetTypeName(codeElement),
                                                GetNamespaceName(codeElement));
            }
            element.State = UnitTestElementState.Valid;

            var categories = test.Metadata[MetadataKeys.Category];

            element.Categories = UnitTestElementCategory.Create(categories);

            var reason = test.Metadata.GetValue(MetadataKeys.IgnoreReason);

            if (reason != null)
            {
                element.Explicit       = true;
                element.ExplicitReason = reason;
            }

            return(element);
        }
 public static AnnotationState CreateFromAnnotation(AnnotationData annotation)
 {
     return(new AnnotationState(annotation.Type,
                                annotation.Message, annotation.Details,
                                ReSharperReflectionPolicy.GetDeclaredElementResolver(annotation.CodeElement)));
 }