Exemplo n.º 1
0
 public MoveFileBulbItem(TestFileNameSpaceWarning highlight)
 {
     _highlight = highlight;
 }
        private void CheckClassNamespaceOfTestMatchesClassUnderTest(ICSharpTypeDeclaration thisDeclaration, List <IClrDeclaredElement> declaredElements)
        {
            var thisProject = thisDeclaration.GetProject();

            if (thisProject == null)
            {
                return;
            }

            var associatedProject = thisProject.GetAssociatedProjects(CurrentSourceFile.ToProjectFile()).FirstOrDefault();

            if (associatedProject == null)
            {
                return;
            }
            ResharperHelper.RemoveElementsNotInProjects(declaredElements, new [] { associatedProject.Project });

            var thisProjectsDefaultNamespace = thisProject.GetDefaultNamespace();

            if (string.IsNullOrEmpty(thisProjectsDefaultNamespace))
            {
                return;
            }

            var associatedProjectsDefaultNameSpace = associatedProject.Project.GetDefaultNamespace();

            if (string.IsNullOrEmpty(associatedProjectsDefaultNameSpace))
            {
                return;
            }

            //var nsToBeFoundShouldBe = associatedProject.Project.GetDefaultNamespace()+associatedProject.SubNamespace;
            var nsToBeFoundShouldBe = associatedProject.FullNamespace();

            //Lookup the namespaces of the declaredElements we've found that possibly match this test
            IList <string> foundNameSpaces = new List <string>();

            foreach (var declaredTestElement in declaredElements)
            {
                var cls = declaredTestElement as TypeElement;
                if (cls == null)
                {
                    continue;
                }
                var ns = cls.OwnerNamespaceDeclaration();

                if (nsToBeFoundShouldBe == ns)
                {
                    return;//found a match !
                }
                foundNameSpaces.Add(ns);
            }

            foreach (var ns in foundNameSpaces)
            {
                if (ns.StartsWith(associatedProjectsDefaultNameSpace))
                {
                    //TODO: Review this can be probably be replaced with associatedProject method calls
                    var    targetsubNameSpace = ns.Substring(associatedProjectsDefaultNameSpace.Length).TrimStart(new[] { '.' });
                    string suggestedNameSpace = thisProjectsDefaultNamespace.AppendIfNotNull(".", targetsubNameSpace);

                    var targetFolder = thisProject.Location.Combine(targetsubNameSpace.Replace(".", @"\"));

                    var highlight = new TestFileNameSpaceWarning(CurrentSourceFile.ToProjectFile(), thisDeclaration, suggestedNameSpace
                                                                 , thisProject, targetFolder);

                    AddHighlighting(thisDeclaration.GetNameDocumentRange(), highlight);
                }
            }
        }