Beispiel #1
0
        public IEnumerable<string> GetSelectedFiles()
        {
            var dte = (DTE2)serviceProvider.GetService(typeof(DTE));
            var items = (Array)dte.ToolWindows.SolutionExplorer.SelectedItems;

            return from item in items.Cast<UIHierarchyItem>()
                   let pi = item.Object as ProjectItem
                   select pi?.FileNames[1];
        }
        private Project GetFirstSelectedProject()
        {
            var dte2             = (DTE2)serviceProvider.GetService(typeof(DTE));
            var solutionProjects = dte2.ActiveSolutionProjects as Array;

            if (solutionProjects.Length == 0)
            {
                throw new Exception(messageManager.GetMessage("ProjectIsNotSelectedOnSolutionExplorer"));
            }

            return(solutionProjects.GetValue(0) as Project);
        }
        public void AddSuppressionWithDefaultParameters_ShouldReceivExpected()
        {
            //Arange
            string suppressName = "suppressName";
            string ruleCategory = "ruleCategory";
            string ruleId       = "ruleId";
            string filePath     = "filePath";

            string expectedString = "[suppressName(\"ruleCategory\", \"ruleId\")]\r\n";

            ProjectItem projectItem = Substitute.For <ProjectItem>();

            projectItem.FileNames[0].Returns(filePath);

            ProjectItems projectItems = Substitute.For <ProjectItems>();

            projectItems.Item(Arg.Any <object>()).Returns(projectItem);

            Project project = Substitute.For <Project>();

            project.ProjectItems.Returns(projectItems);

            Project[] projects = new Project[] { project };
            DTE2      dte      = Substitute.For <DTE2>();

            dte.ActiveSolutionProjects.Returns(projects);
            serviceProvider.GetService(Arg.Any <Type>()).Returns(dte);

            this.iOWrapper.ReadAllText(Arg.Any <string>(), Arg.Any <Encoding>()).Returns("");

            //Act
            this.projectManager.AddSuppression(suppressName, ruleCategory, ruleId);

            //Assert
            this.iOWrapper.Received().WriteAllTextIntoFile(filePath, expectedString, Arg.Any <Encoding>());
        }