public void GetEnumeratorNullTest() { ProjectCollection target = new ProjectCollection(); IEnumerator actual; actual = target.GetEnumerator(); Assert.IsNull(actual); }
public void VsGetEnumeratorSelectedProjectsTest() { ProjectCollection target = new ProjectCollection(); Mock<IEnumerable> mockEnumerable = new Mock<IEnumerable>(); Mock<IEnumerator> mockEnumerator = new Mock<IEnumerator>(); IEnumerator expected = mockEnumerator.Instance; mockEnumerable.ImplementExpr(e => e.GetEnumerator(), expected); target.SelectedProjects = mockEnumerable.Instance; IEnumerator actual; actual = target.GetEnumerator(); Assert.AreEqual(expected, actual); }
/// <summary> /// Creates the list of project files to be analyzed. /// </summary> /// <param name="core"><see cref="T:StyleCopCore">Core object</see> that hosts the environment.</param> /// <param name="type">The analyze type being performed.</param> /// <returns>Returns the list of projects.</returns> internal static IList<CodeProject> GetProjectList(StyleCopCore core, AnalysisType type) { Param.AssertNotNull(core, "core"); Param.Ignore(type); // Create a list to store the list of code projects to be analyzed. List<CodeProject> codeProjects = new List<CodeProject>(); DTE applicationObject = GetDTE(); if (type == AnalysisType.Solution || type == AnalysisType.Project) { // Create a project enumerator for the correct VS project list. ProjectCollection enumerator = new ProjectCollection(); if (type == AnalysisType.Solution) { enumerator.SolutionProjects = applicationObject.Solution.Projects; } else { enumerator.SelectedProjects = (System.Collections.IEnumerable)applicationObject.ActiveSolutionProjects; } // Enumerate through the VS projects. foreach (Project project in enumerator) { if (project != null) { EnumerateProject( project, new ProjectInvoker(AddCodeProject), new ProjectItemInvoker(AddFileToProject), codeProjects, null); } } } else if (type == AnalysisType.Item || type == AnalysisType.Folder) { GetSelectedItemFiles(codeProjects); } else if (type == AnalysisType.File) { Document document = applicationObject.ActiveDocument; if (document != null) { CodeProject codeProject = null; string projectPath = GetProjectPath(document.ProjectItem.ContainingProject); if (projectPath != null) { codeProject = new CodeProject( projectPath.GetHashCode(), projectPath, GetProjectConfiguration(document.ProjectItem.ContainingProject)); } else if (document.FullName != null && document.FullName.Length > 0) { codeProject = new CodeProject( document.FullName.GetHashCode(), Path.GetDirectoryName(document.FullName), new StyleCop.Configuration(null)); } if (codeProject != null) { core.Environment.AddSourceCode(codeProject, document.FullName, document); codeProjects.Add(codeProject); } } } else { Debug.Fail("Unknown analysis type requested."); } return codeProjects; }
/// <summary> /// Determines whether the StyleCop menu items should be shown. /// </summary> /// <param name="helper">The analysis helper instance.</param> /// <param name="type">Indicates the type of solution artifacts to search.</param> /// <returns>The type of solution node selected.</returns> internal static bool SupportsStyleCop(AnalysisHelper helper, AnalysisType type) { Param.Ignore(helper, type); DTE applicationObject = GetDTE(); if (type == AnalysisType.Solution || type == AnalysisType.Project) { // Create a project enumerator for the correct VS project list. ProjectCollection enumerator = new ProjectCollection(); if (type == AnalysisType.Solution) { enumerator.SolutionProjects = applicationObject.Solution.Projects; } else { enumerator.SelectedProjects = (System.Collections.IEnumerable)applicationObject.ActiveSolutionProjects; } // Enumerate through the VS projects. foreach (Project project in enumerator) { if (project != null) { if (EnumerateProject( project, new ProjectInvoker(IsKnownProjectTypeVisitor), new ProjectItemInvoker(IsKnownFileTypeVisitor), helper, null) != null) { return true; } } } } else if (type == AnalysisType.Item || type == AnalysisType.Folder) { if (AreSelectedFilesKnownFileTypes(helper)) { return true; } } else if (type == AnalysisType.File) { Document document = applicationObject.ActiveDocument; if (document != null && !string.IsNullOrEmpty(document.FullName)) { string fileExtension = Path.GetExtension(document.FullName); if (fileExtension.Length > 0 && fileExtension.StartsWith(".", StringComparison.Ordinal)) { fileExtension = fileExtension.Substring(1, fileExtension.Length - 1); } if (IsKnownFileExtension(fileExtension, helper.Core)) { return true; } } } return false; }
public void VsSolutionProjectsTest() { ProjectCollection target = new ProjectCollection(); Mock<Projects> mockProjects = new Mock<Projects>(); Projects expected = mockProjects.Instance; Projects actual; target.SolutionProjects = expected; actual = target.SolutionProjects; Assert.AreEqual(expected, actual); }
public void VsSelectedProjectsTest() { ProjectCollection target = new ProjectCollection(); IEnumerable expected = new Mock<IEnumerable>().Instance; IEnumerable actual; target.SelectedProjects = expected; actual = target.SelectedProjects; Assert.AreEqual(expected, actual); }
/// <summary> /// Creates the list of project files to be analyzed. /// </summary> /// <param name="core"><see cref="T:StyleCopCore">Core object</see> that hosts the environment.</param> /// <param name="type">The analyze type being performed.</param> /// <param name="analysisFilePath">The path to the initial file we are analyzing.</param> /// <param name="analysisHelper">The analysis helper.</param> /// <returns>Returns the list of projects.</returns> internal static IList<CodeProject> GetProjectList(StyleCopCore core, AnalysisType type, out string analysisFilePath, AnalysisHelper analysisHelper) { Param.AssertNotNull(core, "core"); Param.Ignore(type); // Create a list to store the list of code projects to be analyzed. List<CodeProject> codeProjects = new List<CodeProject>(); DTE applicationObject = GetDTE(); analysisFilePath = null; switch (type) { case AnalysisType.Project: case AnalysisType.Solution: // Create a project enumerator for the correct VS project list. ProjectCollection enumerator = new ProjectCollection(); if (type == AnalysisType.Solution) { enumerator.SolutionProjects = applicationObject.Solution.Projects; } else { enumerator.SelectedProjects = (IEnumerable)applicationObject.ActiveSolutionProjects; } // Enumerate through the VS projects. foreach (Project project in enumerator) { // We continue if we know the project type or if its a misc item or a solution folder if (project != null && (IsKnownProjectType(project, analysisHelper) || project.Kind == Constants.vsProjectKindMisc || project.Kind == Constants.vsProjectKindSolutionItems)) { EnumerateProject(project, AddCodeProject, AddFileToProject, codeProjects, null); } } break; case AnalysisType.Folder: case AnalysisType.Item: analysisFilePath = GetSelectedItemFiles(codeProjects); break; case AnalysisType.File: var document = applicationObject.ActiveDocument; if (document != null) { CodeProject codeProject = null; string projectPath = GetProjectPath(document.ProjectItem.ContainingProject); if (projectPath != null) { codeProject = new CodeProject(projectPath.GetHashCode(), projectPath, GetProjectConfiguration(document.ProjectItem.ContainingProject), TargetFrameworkVersion(document.ProjectItem.ContainingProject)); } else if (!string.IsNullOrEmpty(document.FullName)) { codeProject = new CodeProject(document.FullName.GetHashCode(), Path.GetDirectoryName(document.FullName), new StyleCop.Configuration(null)); } if (codeProject != null) { // If this is a designer.cs file (and so a dependant of another file) then we need to add it but also its parent and siblings. analysisFilePath = document.FullName; var allFilesForProjectItem = GetAllFilesForProjectItem(document.ProjectItem); foreach (var path in allFilesForProjectItem) { core.Environment.AddSourceCode(codeProject, path, null); } codeProjects.Add(codeProject); } } break; default: Debug.Fail("Unknown analysis type requested."); break; } return codeProjects; }
/// <summary> /// Determines whether the StyleCop menu items should be shown. /// </summary> /// <param name="helper">The analysis helper instance.</param> /// <param name="type">Indicates the type of solution artifacts to search.</param> /// <returns>The type of solution node selected.</returns> internal static bool SupportsStyleCop(AnalysisHelper helper, AnalysisType type) { Param.Ignore(helper, type); DTE applicationObject = GetDTE(); if (type == AnalysisType.Solution || type == AnalysisType.Project) { // Create a project enumerator for the correct VS project list. ProjectCollection enumerator = new ProjectCollection(); if (type == AnalysisType.Solution) { enumerator.SolutionProjects = applicationObject.Solution.Projects; } else { enumerator.SelectedProjects = (IEnumerable)applicationObject.ActiveSolutionProjects; } // Enumerate through the VS projects. foreach (Project project in enumerator) { if (project != null) { // If we've already cached a value for whether this project supports StyleCop, use it, since it is very // expensive to constantly scan massive unmanaged project trees through COM. This used to render Visual // Studio unusable in largely unmanaged solutions (#6662). bool isEnabled; if (ProjectEnabledCache.ContainsKey(project.UniqueName)) { isEnabled = ProjectEnabledCache[project.UniqueName]; } else { isEnabled = EnumerateProject(project, IsKnownProjectTypeVisitor, IsKnownFileTypeVisitor, helper, null) != null; ProjectEnabledCache.Add(project.UniqueName, isEnabled); } if (isEnabled) { return true; } } } return false; } else if (type == AnalysisType.Item || type == AnalysisType.Folder) { if (AreSelectedFilesKnownFileTypes(helper)) { return true; } } else if (type == AnalysisType.File) { Document document = applicationObject.ActiveDocument; if (document != null && !string.IsNullOrEmpty(document.FullName)) { string fileExtension = Path.GetExtension(document.FullName); if (fileExtension.Length > 0 && fileExtension.StartsWith(".", StringComparison.Ordinal)) { fileExtension = fileExtension.Substring(1, fileExtension.Length - 1); } if (IsKnownFileExtension(fileExtension, helper.Core)) { return true; } } } return false; }