public void MapToProjectsTwoProjectItemsInDifferentProjectsTest()
        {
            // Simulate fileA.ts and fileB.ts being selected in Solution Explorer in multiple.sln.
            string              fileAFullPath = Path.GetFullPath(@"../../artifacts/localinstall/multiple/a/fileA.ts");
            string              fileBFullPath = Path.GetFullPath(@"../../artifacts/localinstall/multiple/b/fileB.ts");
            Solution            solution      = WebLinterPackage.Dte.ToolWindows.SolutionExplorer.UIHierarchyItems.Item(1).Object as Solution;
            ProjectItem         projectItemA  = solution.FindProjectItem(fileAFullPath);
            ProjectItem         projectItemB  = solution.FindProjectItem(fileBFullPath);
            MockUIHierarchyItem mockProjectItemHierarchyItemA = new MockUIHierarchyItem {
                Object = projectItemA
            };
            MockUIHierarchyItem mockProjectItemHierarchyItemB = new MockUIHierarchyItem {
                Object = projectItemB
            };

            UIHierarchyItem[] results = BuildSelectedItems.MapToProjects(
                new UIHierarchyItem[] { mockProjectItemHierarchyItemA, mockProjectItemHierarchyItemB }).ToArray();

            Assert.AreEqual(2, results.Length);
            Project projectObject = results[0].Object as Project;

            Assert.IsNotNull(projectObject);
            Assert.IsTrue(projectObject.FullName
                          .EndsWith("\\src\\WebLinterTest\\artifacts\\localinstall\\multiple\\a\\a.csproj"));
            Project projectObject2 = results[1].Object as Project;

            Assert.IsNotNull(projectObject2);
            Assert.IsTrue(projectObject2.FullName
                          .EndsWith("\\src\\WebLinterTest\\artifacts\\localinstall\\multiple\\b\\b.csproj"));
        }
 protected async System.Threading.Tasks.Task <bool> LintBuildSelection(bool isBuildingSolution)
 {
     try
     {
         Benchmark.Start();
         if (!LinterService.IsLinterEnabled)
         {
             return(false);
         }
         UIHierarchyItem[]           selectedItems = BuildSelectedItems.Get(isBuildingSolution);
         Dictionary <string, string> fileToProjectMap;
         string[] files = WebLinterPackage.Settings.UseTsConfig ?
                          TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap) :
                          LintFileLocations.FindPathsFromSelectedItems(selectedItems, out fileToProjectMap);
         if (!files.Any())
         {
             return(false);
         }
         return(await LinterService.Lint(showErrorList : true, fixErrors : false, callSync : true,
                                         fileNames : files, clearAllErrors : true, fileToProjectMap));
     }
     catch (Exception ex)
     {
         Logger.LogAndWarn(ex);
         Linter.Server.Down();
         return(true);  // Return value is true if we have VS errors
     }
     finally { Benchmark.End(); }
 }
        public void SelectedItemsWhenBuidingSolutionTest()
        {
            UIHierarchyItem[] results = BuildSelectedItems.Get(isBuildingSolution: true);
            Assert.AreEqual(1, results.Length);
            Solution solutionObject = results[0].Object as Solution;

            Assert.IsNotNull(solutionObject);
            Assert.IsTrue(solutionObject.FullName
                          .EndsWith("\\src\\WebLinterTest\\artifacts\\localinstall\\multiple\\multiple.sln"));
        }
        public void MapToProjectsItemNotInProjectTest()
        {
            // package.json in b isn't in a project or solution
            string fileFullPath = Path.GetFullPath(@"../../artifacts/localinstall/multiple/b/package.json");

            Assert.IsTrue(File.Exists(fileFullPath));
            Solution            solution    = WebLinterPackage.Dte.ToolWindows.SolutionExplorer.UIHierarchyItems.Item(1).Object as Solution;
            ProjectItem         projectItem = solution.FindProjectItem(fileFullPath);
            MockUIHierarchyItem mockProjectItemHierarchyItem = new MockUIHierarchyItem {
                Object = projectItem
            };

            UIHierarchyItem[] results = BuildSelectedItems.MapToProjects(new UIHierarchyItem[] { mockProjectItemHierarchyItem }).ToArray();

            Assert.AreEqual(0, results.Length);
        }
        public void MapToProjectsSingleProjectItemTest()
        {
            // Simulate fileA.ts being selected in Solution Explorer in multiple.sln.
            // Ensure a.csproj (which contains fileA.ts) is the item we calculate as building
            string              fileAFullPath = Path.GetFullPath(@"../../artifacts/localinstall/multiple/a/fileA.ts");
            Solution            solution      = WebLinterPackage.Dte.ToolWindows.SolutionExplorer.UIHierarchyItems.Item(1).Object as Solution;
            ProjectItem         projectItem   = solution.FindProjectItem(fileAFullPath);
            MockUIHierarchyItem mockProjectItemHierarchyItem = new MockUIHierarchyItem {
                Object = projectItem
            };

            UIHierarchyItem[] results = BuildSelectedItems.MapToProjects(new UIHierarchyItem[] { mockProjectItemHierarchyItem }).ToArray();

            Assert.AreEqual(1, results.Length);
            Project projectObject = results[0].Object as Project;

            Assert.IsNotNull(projectObject);
            Assert.IsTrue(projectObject.FullName
                          .EndsWith("\\src\\WebLinterTest\\artifacts\\localinstall\\multiple\\a\\a.csproj"));
        }