private static void MenuItemCallback(object sender, EventArgs e) { RunTestsMenuCommand command = (RunTestsMenuCommand)sender; UIHierarchy uih = command.Dte2.ToolWindows.SolutionExplorer; Array selectedItems = (Array)uih.SelectedItems; UIHierarchyItem selectedItem = selectedItems.GetValue(0) as UIHierarchyItem; Solution solution = command.Dte2.Solution; Solution selectedSolution = selectedItem.Object as Solution; if (LaunchCommand.Instance.Launcher.BuildBeforeLaunch) { solution.SolutionBuild.Build(true); } if (selectedSolution != null) { //System.Diagnostics.Debug.WriteLine("RunTestsMenuCommand.MenuItemCallback() running all test projects for the solution"); foreach (Project p in selectedSolution.Projects) { if (RunTestsMenu.IsTestProject(p)) { RunTestProject(p, solution); } } return; } Project project = selectedItem.Object as Project; if (project != null) { //System.Diagnostics.Debug.WriteLine("RunTestsMenuCommand.MenuItemCallback() running a single test project"); RunTestProject(project, solution); } }
/// <summary> /// Initializes a new instance of the <see cref="RunTestsMenu"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private RunTestsMenu(Package package) { if (package == null) { throw new ArgumentNullException("package"); } this.package = package; OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (commandService != null) { CommandID menuCommandID = new CommandID(CommandSet, cmdidRunTestsCommand); OleMenuCommand menuItem = new RunTestsMenuCommand(menuCommandID, (DTE2)this.ServiceProvider.GetService(typeof(DTE))); commandService.AddCommand(menuItem); } }