public void ProcessBeforeInterior(ITreeNode element)
        {
            var declaration = element as IDeclaration;
            if (declaration == null)
                return;

            var declaredElement = declaration.DeclaredElement;
            if (declaredElement == null || declaredElement.ShortName == SharedImplUtil.MISSING_DECLARATION_NAME)
                return;

            IUnitTestElement testElement = null;
            var testClass = declaredElement as IClass;
            if (testClass != null)
                testElement = ProcessTestClass(testClass);

            var subElements = new List<IUnitTestElement>();

            var testMethod = declaredElement as IMethod;
            if (testMethod != null)
                testElement = ProcessTestMethod(testMethod, subElements);

            if (testElement != null)
            {
                // Ensure that the method has been implemented, i.e. it has a name and a document
                var nameRange = declaration.GetNameDocumentRange().TextRange;
                var documentRange = declaration.GetDocumentRange().TextRange;
                if (nameRange.IsValid && documentRange.IsValid)
                {
                    var disposition = new UnitTestElementDisposition(testElement, file.GetSourceFile().ToProjectFile(),
                                                                     nameRange, documentRange, subElements);
                    consumer(disposition);
                }
            }
        }
        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));
                        }
                    }
                }
            }
        }
Esempio n. 3
0
            public void ProcessBeforeInterior(IElement element)
            {
                var declaration = element as IDeclaration;

                if (declaration == null)
                {
                    return;
                }
                CSUnitElementBase testElement = null;

                var declaredElement = declaration.DeclaredElement;
                var typeElement     = declaredElement as ITypeElement;

                if (typeElement != null && IsTestFixture(typeElement))
                {
                    CSUnitTestFixtureElement fixtureElement;

                    if (!myFixtures.ContainsKey(typeElement))
                    {
                        fixtureElement = new CSUnitTestFixtureElement(myProvider, myProject, typeElement.CLRName, myAssemblyPath);
                        myFixtures.Add(typeElement, fixtureElement);
                        myOrders.Add(typeElement, 0);
                    }
                    else
                    {
                        fixtureElement = myFixtures[typeElement];
                    }

                    testElement = fixtureElement;
                    int order = 0;
                    AppendTests(fixtureElement, typeElement.GetSuperTypes(), ref order);
                }


                var typeMember = declaredElement as ITypeMember;

                if (typeMember != null && IsTestMethod(typeMember))
                {
                    ITypeElement type = typeMember.GetContainingType();
                    if (type != null)
                    {
                        CSUnitTestFixtureElement fixtureElement = myFixtures.TryGetValue(type);
                        if (fixtureElement != null)
                        {
                            int order = myOrders.TryGetValue(type) + 1;
                            myOrders[type] = order;
                            testElement    = new CSUnitTestElement(myProvider, fixtureElement, myProject, type.CLRName, typeMember.ShortName, order);
                        }
                    }
                }

                if (testElement == null)
                {
                    return;
                }
                var disposition = new UnitTestElementDisposition(testElement, myFile.ProjectFile, declaration.GetNameDocumentRange().TextRange, declaration.GetDocumentRange().TextRange);

                myConsumer(disposition);
            }
Esempio n. 4
0
 public void OnUnitTestElementDisposition(UnitTestElementDisposition disposition)
 {
     myElements.Add(disposition.UnitTestElement);
     if (disposition.SubElements != null)
     {
         foreach (var element in disposition.SubElements)
         {
             myElements.Add(element);
         }
     }
 }
        public void ProcessBeforeInterior(ITreeNode element)
        {
            var declaration = element as IDeclaration;

            if (declaration == null)
            {
                return;
            }

            var declaredElement = declaration.DeclaredElement;

            if (declaredElement == null || declaredElement.ShortName == SharedImplUtil.MISSING_DECLARATION_NAME)
            {
                return;
            }

            IUnitTestElement testElement = null;
            var testClass = declaredElement as IClass;

            if (testClass != null)
            {
                testElement = ProcessTestClass(testClass);
            }

            // SubElements are elements that are linked, but not children. We only use them to
            // associate a fake container element that represents a test method in an abstract
            // base class with the real method elements that represent the same test method in
            // any derived class. ReSharper shows a selection of these sub-elements in the gutter
            // icon menu for the test method in the abstract class - we can't run that test method,
            // but we would like to run the associated sub elements
            var subElements = new List <IUnitTestElement>();

            var testMethod = declaredElement as IMethod;

            if (testMethod != null)
            {
                testElement = ProcessTestMethod(testMethod, subElements);
            }

            if (testElement != null)
            {
                // Ensure that the method has been implemented, i.e. it has a name and a document
                var nameRange     = declaration.GetNameDocumentRange().TextRange;
                var documentRange = declaration.GetDocumentRange().TextRange;
                if (nameRange.IsValid && documentRange.IsValid)
                {
                    var disposition = new UnitTestElementDisposition(testElement, file.GetSourceFile().ToProjectFile(),
                                                                     nameRange, documentRange, subElements);
                    observer.OnUnitTestElementDisposition(disposition);
                }
            }
        }
Esempio n. 6
0
        public void ExploreFile(IFile psiFile, UnitTestElementLocationConsumer consumer, CheckForInterrupt interrupted)
        {
            var psiProject = psiFile.GetProject();
            var project    = _environment.GetProject(psiProject.ProjectFile.Location.FullPath);

            var stories = project.GetStories(psiFile.GetProjectFile().Location.ToString());

            foreach (var story in stories)
            {
                var range = new TextRange(0);
                UnitTestElementDisposition disposition = new UnitTestElementDisposition(
                    new StorEvilStoryElement(_provider, null, psiProject, story.Summary, story.Id), psiProject.ProjectFile, range, range);
                consumer(disposition);
            }
        }
        public void ExploreFile(IFile psiFile, UnitTestElementLocationConsumer consumer, CheckForInterrupt interrupted)
        {
            var psiProject = psiFile.GetProject();
            var project = _environment.GetProject(psiProject.ProjectFile.Location.FullPath);

            var stories = project.GetStories(psiFile.GetProjectFile().Location.ToString());

            foreach (var story in stories)
            {
                var range = new TextRange(0);
                UnitTestElementDisposition disposition = new UnitTestElementDisposition(
                    new StorEvilStoryElement(_provider, null, psiProject,story.Summary, story.Id ), psiProject.ProjectFile, range, range);
                consumer(disposition);
            }
        }
Esempio n. 8
0
        private void OnUnitTestElement(IUnitTestElement element, IDeclaration declaration = null)
        {
            if (declaration == null)
            {
                _observer.OnUnitTestElementDisposition(UnitTestElementDisposition.NotYetClear(element));
                return;
            }

            var project         = declaration.GetSourceFile().ToProjectFile();
            var textRange       = declaration.GetNameDocumentRange().TextRange;
            var containingRange = declaration.GetDocumentRange().TextRange;

            var disposition = new UnitTestElementDisposition(element, project, textRange, containingRange);

            _observer.OnUnitTestElementDisposition(disposition);
        }
        public void ProcessBeforeInterior(ITreeNode element)
        {
            var declaration = element as IDeclaration;

            if (declaration == null)
            {
                return;
            }

            var declaredElement = declaration.DeclaredElement;

            if (declaredElement == null || declaredElement.ShortName == SharedImplUtil.MISSING_DECLARATION_NAME)
            {
                return;
            }

            IUnitTestElement testElement = null;
            var testClass = declaredElement as IClass;

            if (testClass != null)
            {
                testElement = ProcessTestClass(testClass);
            }

            var testMethod = declaredElement as IMethod;

            if (testMethod != null)
            {
                testElement = ProcessTestMethod(testMethod);
            }

            if (testElement != null)
            {
                var nameRange     = declaration.GetNameDocumentRange().TextRange;
                var documentRange = declaration.GetDocumentRange().TextRange;
                if (nameRange.IsValid && documentRange.IsValid)
                {
                    var disposition = new UnitTestElementDisposition(testElement, psiFile.GetSourceFile().ToProjectFile(),
                                                                     nameRange, documentRange);
                    consumer(disposition);
                }
            }
        }
Esempio n. 10
0
                public ConsumerAdapter(IUnitTestProvider provider, UnitTestElementLocationConsumer consumer, IFile psiFile)
                    : this(provider, delegate(UnitTestElement element)
                {
#if RESHARPER_31
                    IProjectFile projectFile = psiFile.ProjectItem;
#else
                    IProjectFile projectFile = psiFile.ProjectFile;
#endif
                    if (projectFile.IsValid)
                    {
                        UnitTestElementDisposition disposition = element.GetDisposition();
                        if (disposition.Locations.Count != 0 && disposition.Locations[0].ProjectFile == projectFile)
                        {
                            consumer(disposition);
                        }
                    }
                })
                {
                }
Esempio n. 11
0
        public UnitTestElementDisposition GetDispositionFromFiles(params ITestFile[] testFiles)
        {
            var declarations = testFiles
                               .Select(x => x.TestDeclarations.Search(Identity, y => y.TestDeclarations))
                               .WhereNotNull().ToList();

            var locations = declarations.Select(x => x.GetTestElementLocation()).ToList();

            if (locations.Count != 0)
            {
                return(new UnitTestElementDisposition(locations, this));
            }

            if (_state == UnitTestElementState.Dynamic || _state == UnitTestElementState.PendingDynamic)
            {
                return(UnitTestElementDisposition.NotYetClear(this));
            }

            _state = UnitTestElementState.Invalid;
            return(UnitTestElementDisposition.InvalidDisposition);
        }
 public void OnUnitTestElementDisposition(UnitTestElementDisposition disposition)
 {
     myElements.Add(disposition.UnitTestElement);
     if (disposition.SubElements != null)
         foreach (var element in disposition.SubElements)
             myElements.Add(element);
 }
        public void ProcessBeforeInterior(ITreeNode element)
        {
            var declaration = element as IDeclaration;
            if (declaration == null)
                return;

            var declaredElement = declaration.DeclaredElement;
            if (declaredElement == null || declaredElement.ShortName == SharedImplUtil.MISSING_DECLARATION_NAME)
                return;

            IUnitTestElement testElement = null;
            var testClass = declaredElement as IClass;
            if (testClass != null)
                testElement = ProcessTestClass(testClass);

            var testMethod = declaredElement as IMethod;
            if (testMethod != null)
                testElement = ProcessTestMethod(testMethod);

            if (testElement != null)
            {
                var nameRange = declaration.GetNameDocumentRange().TextRange;
                var documentRange = declaration.GetDocumentRange().TextRange;
                if (nameRange.IsValid && documentRange.IsValid)
                {
                    var disposition = new UnitTestElementDisposition(testElement, psiFile.GetSourceFile().ToProjectFile(),
                                                                     nameRange, documentRange);
                    consumer(disposition);
                }
            }
        }
        public void ProcessBeforeInterior(ITreeNode element)
        {
            var declaration = element as IDeclaration;

            if (declaration == null)
                return;

            IUnitTestElement testElement = null;
            var declaredElement = declaration.DeclaredElement;

            var testClass = declaredElement as IClass;
            if (testClass != null)
                testElement = ProcessTestClass(testClass);

            var testMethod = declaredElement as IMethod;
            if (testMethod != null)
                testElement = ProcessTestMethod(testMethod) ?? testElement;

            if (testElement == null)
                return;

            // Ensure that the method has been implemented, i.e. it has a name and a document
            var nameRange = declaration.GetNameDocumentRange().TextRange;
            var documentRange = declaration.GetDocumentRange().TextRange;
            if (nameRange.IsValid && documentRange.IsValid)
            {
                var disposition = new UnitTestElementDisposition(testElement, projectFile, nameRange, documentRange);
                consumer(disposition);
            }
        }
        public void ProcessBeforeInterior(ITreeNode element)
        {
            var declaration = element as IDeclaration;
            if (declaration == null)
                return;

            var declaredElement = declaration.DeclaredElement;

            IUnitTestElement unitTestElement = null;

            var specificationContainer = declaredElement as IClass;
            if (specificationContainer != null)
                unitTestElement = ProcessSpecificationContainer(specificationContainer);

            var specification = declaredElement as IField;
            if (specification != null)
                unitTestElement = ProcessSpecification(specification) ?? unitTestElement;

            if (unitTestElement == null)
                return;

            var nameRange = declaration.GetNameDocumentRange().TextRange;
            var documentRange = declaration.GetDocumentRange();

            if (!nameRange.IsValid || !documentRange.IsValid())
                return;

            var disposition = new UnitTestElementDisposition(unitTestElement, _psiFile.GetSourceFile().ToProjectFile(),
                                                             nameRange, documentRange.TextRange, unitTestElement.Children.ToList());
            _consumer(disposition);
        }