Beispiel #1
0
        private IProject ResolveTargetTestProject([NotNull] ITreeNode contextNode, [NotNull] ISolution solution, [NotNull] ReSharperHelperSettings helperSettings)
        {
            // Get project by assembly attribute (if present).
            var projectName = solution.GetPsiServices()
                              .Symbols
                              .GetModuleAttributes(contextNode.GetPsiModule())
                              .GetAttributeInstances(AssemblyMetadataAttributeName, false)
                              .Select(TryExtractProjectNameFromAssemblyMetadataAttribute)
                              .FirstNotNull();

            // Check whether we have configured global test project.
            if (string.IsNullOrEmpty(projectName))
            {
                projectName = helperSettings.TestsProjectName;
            }

            if (!string.IsNullOrEmpty(projectName))
            {
                return(solution.GetProjectByName(projectName));
            }

            // Try to guess project specific test project.
            var currentProjectName = contextNode.GetProject()?.Name;

            if (currentProjectName == null)
            {
                return(null);
            }

            var candidates = TestProjectSuffixes
                             .SelectMany(suffix => solution.GetProjectsByName(currentProjectName + suffix))
                             .WhereNotNull()
                             .ToArray();

            if (candidates.Length > 0)
            {
                if (candidates.Length == 1)
                {
                    return(candidates[0]);
                }

                return(null);
            }

            // Try to guess global test project.
            candidates = solution.GetAllProjects()
                         .Where(proj => TestProjectSuffixes.Any(suffix => proj.Name.EndsWith(suffix, StringComparison.Ordinal)))
                         .ToArray();

            if (candidates.Length == 1)
            {
                return(candidates[0]);
            }

            return(null);
        }
Beispiel #2
0
 public static void NavigateToTypeNodeByFqn(this ISolution solution, string projectName, string fileName, string typeName)
 {
     solution.Locks.TryExecuteWithReadLock(() =>
     {
         var project = solution.GetProjectByName(projectName);
         var file    = project.GetCSharpFile(fileName);
         var node    = file.GetTypeTreeNodeByFqn(typeName);
         node.NavigateToTreeNode(true);
     });
 }