private void WireUpEvents() { _model.TestLoaded += (ea) => InitializeRunCommands(); _model.TestReloaded += (ea) => InitializeRunCommands(); _model.TestUnloaded += (ea) => InitializeRunCommands(); _model.RunStarting += (ea) => InitializeRunCommands(); _model.RunFinished += (ea) => InitializeRunCommands(); _view.Load += (s, e) => _view.DisplayFormat.SelectedItem = _displayFormat; // Run button and dropdowns _view.RunButton.Execute += () => { // Necessary test because we don't disable the button click if (_model.HasTests && !_model.IsTestRunning) { _model.RunTests(TestFilter.Empty); } }; _view.RunAllCommand.Execute += () => _model.RunTests(TestFilter.Empty); _view.RunSelectedCommand.Execute += () => _model.RunSelectedTest(); _view.RunFailedCommand.Execute += () => _model.RunTests(TestFilter.Empty); // NYI _view.StopRunCommand.Execute += () => _model.CancelTestRun(); // Change of display format _view.DisplayFormat.SelectionChanged += () => { _displayFormat = _view.DisplayFormat.SelectedItem; _model.Settings.Gui.TestTree.DisplayFormat = _displayFormat; // Replace the existing display, which functions as an // adjunct to the presenter by handling certain events. _display = CreateDisplayStrategy(_displayFormat); _view.FormatButton.ToolStripItem.ToolTipText = _display.Description; _display.Reload(); }; }
private void WireUpEvents() { #region Model Events _model.Events.TestsLoading += (TestFilesLoadingEventArgs e) => { UpdateViewCommands(testLoading: true); var message = e.TestFilesLoading.Count == 1 ? $"Loading Assembly: {e.TestFilesLoading[0]}" : $"Loading {e.TestFilesLoading.Count} Assemblies..."; _longOpDisplay = _view.LongOperationDisplay(message); }; _model.Events.TestLoaded += (TestNodeEventArgs e) => { if (_longOpDisplay != null) { _longOpDisplay.Dispose(); _longOpDisplay = null; } UpdateViewCommands(); var files = _model.TestFiles; if (files.Count == 1) { _view.SetTitleBar(files.First()); } }; _model.Events.TestsUnloading += (TestEventArgse) => { UpdateViewCommands(); }; _model.Events.TestUnloaded += (TestEventArgs e) => { _view.RunSummary.Text = null; UpdateViewCommands(); }; _model.Events.TestsReloading += (TestEventArgs e) => { UpdateViewCommands(); _longOpDisplay = _view.LongOperationDisplay("Reloading..."); }; _model.Events.TestReloaded += (TestNodeEventArgs e) => { if (_longOpDisplay != null) { _longOpDisplay.Dispose(); _longOpDisplay = null; } //SetTitleBar(TestProject.Name); if (_settings.Gui.ClearResultsOnReload) { _view.RunSummary.Text = null; } UpdateViewCommands(); }; _model.Events.RunStarting += (RunStartingEventArgs e) => { UpdateViewCommands(); }; _model.Events.RunFinished += (TestResultEventArgs e) => { UpdateViewCommands(); ResultSummary summary = ResultSummaryCreator.FromResultNode(e.Result); _view.RunSummary.Text = string.Format( "Passed: {0} Failed: {1} Errors: {2} Inconclusive: {3} Invalid: {4} Ignored: {5} Skipped: {6} Time: {7}", summary.PassCount, summary.FailedCount, summary.ErrorCount, summary.InconclusiveCount, summary.InvalidCount, summary.IgnoreCount, summary.SkipCount, summary.Duration); if (summary.RunCount == 0) { } //string resultPath = Path.Combine(TestProject.BasePath, "TestResult.xml"); // TODO: Use Work Directory string resultPath = "TestResult.xml"; _model.SaveResults(resultPath); //try //{ // _model.SaveResults(resultPath); // //log.Debug("Saved result to {0}", resultPath); //} //catch (Exception ex) //{ // //log.Warning("Unable to save result to {0}\n{1}", resultPath, ex.ToString()); //} //if (e.Result.Outcome.Status == TestStatus.Failed) // _view.Activate(); }; _settings.Changed += (s, e) => { if (e.SettingName == "Gui.Options.DisplayFormat") { InitializeDisplay(); } }; _model.Events.UnhandledException += (UnhandledExceptionEventArgs e) => { var display = new MessageDisplay("TestCentric - Internal Error"); display.Error($"{e.Message}\n\n{e.StackTrace}"); }; #endregion #region View Events _view.Load += (s, e) => { InitializeDisplay(_settings.Gui.DisplayFormat); var settings = _model.PackageOverrides; if (_options.ProcessModel != null) { _view.ProcessModel.SelectedItem = _options.ProcessModel; } if (_options.DomainUsage != null) { _view.DomainUsage.SelectedItem = _options.DomainUsage; } if (_options.MaxAgents >= 0) { _model.Services.UserSettings.Engine.Agents = _options.MaxAgents; } _view.RunAsX86.Checked = _options.RunAsX86; }; _view.Shown += (s, e) => { Application.DoEvents(); // Load test specified on command line or // the most recent one if options call for it if (_options.InputFiles.Count != 0) { LoadTests(_options.InputFiles); } else if (_settings.Gui.LoadLastProject && !_options.NoLoad) { foreach (string entry in _recentFiles.Entries) { if (entry != null && File.Exists(entry)) { LoadTests(entry); break; } } } //if ( guiOptions.include != null || guiOptions.exclude != null) //{ // testTree.ClearSelectedCategories(); // bool exclude = guiOptions.include == null; // string[] categories = exclude // ? guiOptions.exclude.Split(',') // : guiOptions.include.Split(','); // if ( categories.Length > 0 ) // testTree.SelectCategories( categories, exclude ); //} // Run loaded test automatically if called for if (_model.IsPackageLoaded && _options.RunAllTests) { RunAllTests(); } }; _view.Move += (s, e) => { if (!_view.Maximized) { var location = _view.Location; switch (_view.DisplayFormat.SelectedItem) { case "Full": default: _settings.Gui.MainForm.Location = location; _settings.Gui.MainForm.Maximized = false; break; case "Mini": _settings.Gui.MiniForm.Location = location; _settings.Gui.MiniForm.Maximized = false; break; } } }; _view.Resize += (s, e) => { if (!_view.Maximized) { if (_view.DisplayFormat.SelectedItem == "Full") { _settings.Gui.MainForm.Size = _view.Size; } else { _settings.Gui.MiniForm.Size = _view.Size; } } }; _view.SplitterPositionChanged += (s, e) => { _settings.Gui.MainForm.SplitPosition = _view.SplitterPosition; }; _view.FormClosing += (s, e) => { if (_model.IsPackageLoaded) { if (_model.IsTestRunning) { DialogResult dialogResult = _view.MessageDisplay.Ask( "A test is running, do you want to stop the test and exit?"); if (dialogResult == DialogResult.No) { e.Cancel = true; return; } _model.CancelTestRun(true); } if (CloseProject() == DialogResult.Cancel) { e.Cancel = true; } } }; _view.RunButton.Execute += () => RunSelectedTests(); _view.StopButton.Execute += () => CancelRun(); _view.FileMenu.Popup += () => { bool isPackageLoaded = _model.IsPackageLoaded; bool isTestRunning = _model.IsTestRunning; _view.OpenCommand.Enabled = !isTestRunning; _view.CloseCommand.Enabled = isPackageLoaded && !isTestRunning; _view.ReloadTestsCommand.Enabled = isPackageLoaded && !isTestRunning; var frameworks = _model.AvailableRuntimes; var runtimeMenu = _view.RuntimeMenu; runtimeMenu.Visible = frameworks.Count > 1; if (runtimeMenu.Visible && runtimeMenu.Enabled && runtimeMenu.MenuItems.Count == 0) { var defaultMenuItem = new MenuItem("Default"); defaultMenuItem.Name = "defaultMenuItem"; defaultMenuItem.Tag = "DEFAULT"; defaultMenuItem.Checked = true; runtimeMenu.MenuItems.Add(defaultMenuItem); // TODO: Disable selections that are not supported for the target? foreach (IRuntimeFramework framework in frameworks) { MenuItem item = new MenuItem(framework.DisplayName); item.Tag = framework.Id; runtimeMenu.MenuItems.Add(item); } _view.SelectedRuntime.Refresh(); } _view.RecentFilesMenu.Enabled = !isTestRunning; //if (!isTestRunning) //{ // _recentProjectsMenuHandler.Load(); //} }; _view.OpenCommand.Execute += () => OpenProject(); _view.CloseCommand.Execute += () => CloseProject(); _view.AddTestFilesCommand.Execute += () => AddTestFiles(); _view.ReloadTestsCommand.Execute += () => ReloadTests(); _view.SelectedRuntime.SelectionChanged += () => { ChangePackageSettingAndReload(EnginePackageSettings.RuntimeFramework, _view.SelectedRuntime.SelectedItem); }; _view.ProcessModel.SelectionChanged += () => { ChangePackageSettingAndReload(EnginePackageSettings.ProcessModel, _view.ProcessModel.SelectedItem); }; _view.DomainUsage.SelectionChanged += () => { ChangePackageSettingAndReload(EnginePackageSettings.DomainUsage, _view.DomainUsage.SelectedItem); }; _view.RunAsX86.CheckedChanged += () => { var key = EnginePackageSettings.RunAsX86; if (_view.RunAsX86.Checked) { ChangePackageSettingAndReload(key, true); } else { ChangePackageSettingAndReload(key, null); } }; _view.RecentFilesMenu.Popup += () => { var menuItems = _view.RecentFilesMenu.MenuItems; // Test for null, in case we are running tests with a mock if (menuItems == null) { return; } menuItems.Clear(); int num = 0; foreach (string entry in _model.Services.RecentFiles.Entries) { var menuText = string.Format("{0} {1}", ++num, entry); var menuItem = new MenuItem(menuText); menuItem.Click += (sender, ea) => { string path = ((MenuItem)sender).Text.Substring(2); _model.LoadTests(new[] { path }); }; menuItems.Add(menuItem); if (num >= _settings.Gui.RecentProjects.MaxFiles) { break; } } }; _view.ExitCommand.Execute += () => _view.Close(); _view.DisplayFormat.SelectionChanged += () => { _settings.Gui.DisplayFormat = _view.DisplayFormat.SelectedItem; InitializeDisplay(_view.DisplayFormat.SelectedItem); }; _view.IncreaseFontCommand.Execute += () => { applyFont(IncreaseFont(_settings.Gui.Font)); }; _view.DecreaseFontCommand.Execute += () => { applyFont(DecreaseFont(_settings.Gui.Font)); }; _view.ChangeFontCommand.Execute += () => { Font currentFont = _settings.Gui.Font; Font newFont = _view.DialogManager.SelectFont(currentFont); if (newFont != _settings.Gui.Font) { applyFont(newFont); } }; _view.DialogManager.ApplyFont += (font) => applyFont(font); _view.RestoreFontCommand.Execute += () => { applyFont(Form.DefaultFont); }; _view.IncreaseFixedFontCommand.Execute += () => { _settings.Gui.FixedFont = IncreaseFont(_settings.Gui.FixedFont); }; _view.DecreaseFixedFontCommand.Execute += () => { _settings.Gui.FixedFont = DecreaseFont(_settings.Gui.FixedFont); }; _view.RestoreFixedFontCommand.Execute += () => { _settings.Gui.FixedFont = new Font(FontFamily.GenericMonospace, 8.0f); }; _view.StatusBarCommand.CheckedChanged += () => { _view.StatusBarView.Visible = _view.StatusBarCommand.Checked; }; _view.RunAllCommand.Execute += () => RunAllTests(); _view.RunSelectedCommand.Execute += () => RunSelectedTests(); _view.RunFailedCommand.Execute += () => RunFailedTests(); _view.StopRunCommand.Execute += () => CancelRun(); _view.SaveResultsCommand.Execute += () => SaveResults(); _view.OpenWorkDirectoryCommand.Execute += () => System.Diagnostics.Process.Start(_model.WorkDirectory); _view.ExtensionsCommand.Execute += () => { using (var extensionsDialog = new ExtensionDialog(_model.Services.ExtensionService)) { extensionsDialog.Font = _settings.Gui.Font; extensionsDialog.ShowDialog(); } }; _view.SettingsCommand.Execute += () => { SettingsDialog.Display(this, _model); }; _view.TestCentricHelpCommand.Execute += () => { _view.MessageDisplay.Error("Not Yet Implemented"); }; _view.NUnitHelpCommand.Execute += () => { System.Diagnostics.Process.Start("https://github.com/nunit/docs/wiki/NUnit-Documentation"); }; _view.AboutCommand.Execute += () => { using (AboutBox aboutBox = new AboutBox()) { aboutBox.ShowDialog(); } }; _view.ResultTabs.SelectionChanged += () => { _settings.Gui.SelectedTab = _view.ResultTabs.SelectedIndex; }; #endregion }
private void WireUpEvents() { #region Model Events _model.Events.TestsLoading += (TestFilesLoadingEventArgs e) => { UpdateViewCommands(testLoading: true); _longOpDisplay = _view.LongOperationDisplay("Loading..."); }; _model.Events.TestLoaded += (TestNodeEventArgs e) => { if (_longOpDisplay != null) { _longOpDisplay.Dispose(); _longOpDisplay = null; } foreach (var assembly in _model.TestAssemblies) { if (assembly.RunState == RunState.NotRunnable) { _view.MessageDisplay.Error(assembly.GetProperty("_SKIPREASON")); } } UpdateViewCommands(); }; _model.Events.TestsUnloading += (TestEventArgse) => { UpdateViewCommands(); }; _model.Events.TestUnloaded += (TestEventArgs e) => { _view.RunSummary.Text = null; UpdateViewCommands(); }; _model.Events.TestsReloading += (TestEventArgs e) => { UpdateViewCommands(); _longOpDisplay = _view.LongOperationDisplay("Reloading..."); }; _model.Events.TestReloaded += (TestNodeEventArgs e) => { if (_longOpDisplay != null) { _longOpDisplay.Dispose(); _longOpDisplay = null; } //SetTitleBar(TestProject.Name); if (_settings.Gui.ClearResultsOnReload) { _view.RunSummary.Text = null; } UpdateViewCommands(); }; _model.Events.RunStarting += (RunStartingEventArgs e) => { UpdateViewCommands(); }; _model.Events.RunFinished += (TestResultEventArgs e) => { UpdateViewCommands(); ResultSummary summary = ResultSummaryCreator.FromResultNode(e.Result); _view.RunSummary.Text = string.Format( "Passed: {0} Failed: {1} Errors: {2} Inconclusive: {3} Invalid: {4} Ignored: {5} Skipped: {6} Time: {7}", summary.PassCount, summary.FailedCount, summary.ErrorCount, summary.InconclusiveCount, summary.InvalidCount, summary.IgnoreCount, summary.SkipCount, summary.Duration); //string resultPath = Path.Combine(TestProject.BasePath, "TestResult.xml"); // TODO: Use Work Directory string resultPath = "TestResult.xml"; _model.SaveResults(resultPath); //try //{ // _model.SaveResults(resultPath); // //log.Debug("Saved result to {0}", resultPath); //} //catch (Exception ex) //{ // //log.Warning("Unable to save result to {0}\n{1}", resultPath, ex.ToString()); //} if (e.Result.Outcome.Status == TestStatus.Failed) { _view.Activate(); } }; _settings.Changed += (s, e) => { if (e.SettingName == "Gui.Options.DisplayFormat") { InitializeDisplay(); } }; #endregion #region View Events _view.Load += (s, e) => { InitializeDisplay(_settings.Gui.DisplayFormat); // Temporary call, so long as IViewControl is used InitializeControls((Control)_view); }; _view.Shown += (s, e) => { Application.DoEvents(); // Load test specified on command line or // the most recent one if options call for it if (_options.InputFiles.Count != 0) { LoadTests(_options.InputFiles); } else if (_settings.Gui.LoadLastProject && !_options.NoLoad) { foreach (string entry in _recentFiles.Entries) { if (entry != null && File.Exists(entry)) { LoadTests(entry); break; } } } //if ( guiOptions.include != null || guiOptions.exclude != null) //{ // testTree.ClearSelectedCategories(); // bool exclude = guiOptions.include == null; // string[] categories = exclude // ? guiOptions.exclude.Split(',') // : guiOptions.include.Split(','); // if ( categories.Length > 0 ) // testTree.SelectCategories( categories, exclude ); //} // Run loaded test automatically if called for if (_model.IsPackageLoaded && _options.RunAllTests) { // TODO: Temporary fix to avoid problem when /run is used // with ReloadOnRun turned on. Refactor TestModel so // we can just do a run without reload. bool reload = _settings.Gui.ReloadOnRun; try { _settings.Gui.ReloadOnRun = false; RunAllTests(); } finally { _settings.Gui.ReloadOnRun = reload; } } }; _view.Move += (s, e) => { if (!_view.Maximized) { var location = _view.Location; switch (_view.DisplayFormat.SelectedItem) { case "Full": default: _settings.Gui.MainForm.Left = location.X; _settings.Gui.MainForm.Top = location.Y; _settings.Gui.MainForm.Maximized = false; break; case "Mini": _settings.Gui.MiniForm.Left = location.X; _settings.Gui.MiniForm.Top = location.Y; _settings.Gui.MiniForm.Maximized = false; break; } } }; _view.Resize += (s, e) => { if (!_view.Maximized) { var size = _view.Size; if (_view.DisplayFormat.SelectedItem == "Full") { _settings.Gui.MainForm.Width = size.Width; _settings.Gui.MainForm.Height = size.Height; } else { _settings.Gui.MiniForm.Width = size.Width; _settings.Gui.MiniForm.Height = size.Height; } } }; _view.SplitterPosition.Changed += () => { _settings.Gui.MainForm.SplitPosition = _view.SplitterPosition.Value; }; _view.FormClosing += (s, e) => { if (_model.IsPackageLoaded) { if (_model.IsTestRunning) { DialogResult dialogResult = _view.MessageDisplay.Ask( "A test is running, do you want to stop the test and exit?"); if (dialogResult == DialogResult.No) { e.Cancel = true; return; } _model.CancelTestRun(); } if (CloseProject() == DialogResult.Cancel) { e.Cancel = true; } } }; _view.RunButton.Execute += () => RunSelectedTests(); _view.StopButton.Execute += () => CancelRun(); _view.FileMenu.Popup += () => { bool isPackageLoaded = _model.IsPackageLoaded; bool isTestRunning = _model.IsTestRunning; _view.OpenCommand.Enabled = !isTestRunning; _view.CloseCommand.Enabled = isPackageLoaded && !isTestRunning; _view.ReloadTestsCommand.Enabled = isPackageLoaded && !isTestRunning; var frameworks = _model.AvailableRuntimes; var runtimeMenu = _view.RuntimeMenu; runtimeMenu.Visible = frameworks.Count > 1; if (runtimeMenu.Visible && runtimeMenu.Enabled && runtimeMenu.MenuItems.Count == 0) { var defaultMenuItem = new MenuItem("Default"); defaultMenuItem.Name = "defaultMenuItem"; defaultMenuItem.Tag = "DEFAULT"; defaultMenuItem.Checked = true; runtimeMenu.MenuItems.Add(defaultMenuItem); // TODO: Disable selections that are not supported for the target? foreach (IRuntimeFramework framework in frameworks) { MenuItem item = new MenuItem(framework.DisplayName); item.Tag = framework.Id; runtimeMenu.MenuItems.Add(item); } _view.SelectedRuntime.Refresh(); } _view.RecentFilesMenu.Enabled = !isTestRunning; //if (!isTestRunning) //{ // _recentProjectsMenuHandler.Load(); //} }; _view.OpenCommand.Execute += () => OpenProject(); _view.CloseCommand.Execute += () => CloseProject(); _view.AddTestFileCommand.Execute += () => AddTestFile(); _view.ReloadTestsCommand.Execute += () => ReloadTests(); _view.SelectedRuntime.SelectionChanged += () => { ChangePackageSetting(EnginePackageSettings.RuntimeFramework, _view.SelectedRuntime.SelectedItem); }; _view.RecentFilesMenu.Popup += () => { var menuItems = _view.RecentFilesMenu.MenuItems; // Test for null, in case we are running tests with a mock if (menuItems == null) { return; } menuItems.Clear(); int num = 0; foreach (string entry in _model.Services.RecentFiles.Entries) { var menuText = string.Format("{0} {1}", ++num, entry); var menuItem = new MenuItem(menuText); menuItem.Click += (sender, ea) => { string path = ((MenuItem)sender).Text.Substring(2); _model.LoadTests(new[] { path }); }; menuItems.Add(menuItem); } }; _view.ExitCommand.Execute += () => _view.Close(); _view.DisplayFormat.SelectionChanged += () => { _settings.Gui.DisplayFormat = _view.DisplayFormat.SelectedItem; InitializeDisplay(_view.DisplayFormat.SelectedItem); }; _view.TreeMenu.Popup += () => { TreeNode selectedNode = _view.TreeView.SelectedNode; _view.CheckboxesCommand.Checked = _settings.Gui.TestTree.ShowCheckBoxes; if (selectedNode != null && selectedNode.Nodes.Count > 0) { bool isExpanded = selectedNode.IsExpanded; _view.CollapseCommand.Enabled = isExpanded; _view.ExpandCommand.Enabled = !isExpanded; } else { _view.CollapseCommand.Enabled = _view.ExpandCommand.Enabled = false; } }; _view.CheckboxesCommand.CheckedChanged += () => { _settings.Gui.TestTree.ShowCheckBoxes = _view.TreeView.CheckBoxes = _view.CheckboxesCommand.Checked; }; _view.ExpandCommand.Execute += () => { _view.TreeView.SelectedNode.Expand(); }; _view.CollapseCommand.Execute += () => { _view.TreeView.SelectedNode.Collapse(); }; _view.ExpandAllCommand.Execute += () => { _view.TreeView.ExpandAll(); }; _view.CollapseAllCommand.Execute += () => { _view.TreeView.CollapseAll(); }; _view.HideTestsCommand.Execute += () => { _view.TreeView.HideTests(); }; _view.PropertiesCommand.Execute += () => { if (_view.TreeView.SelectedNode != null) { _view.TreeView.ShowPropertiesDialog((TestSuiteTreeNode)_view.TreeView.SelectedNode); } }; _view.IncreaseFontCommand.Execute += () => { applyFont(IncreaseFont(_settings.Gui.Font)); }; _view.DecreaseFontCommand.Execute += () => { applyFont(DecreaseFont(_settings.Gui.Font)); }; _view.ChangeFontCommand.Execute += () => { FontDialog fontDialog = new FontDialog(); fontDialog.FontMustExist = true; fontDialog.Font = _settings.Gui.Font; fontDialog.MinSize = 6; fontDialog.MaxSize = 12; fontDialog.AllowVectorFonts = false; fontDialog.ScriptsOnly = true; fontDialog.ShowEffects = false; fontDialog.ShowApply = true; fontDialog.Apply += (s, e) => { applyFont(((FontDialog)s).Font); }; if (fontDialog.ShowDialog() == DialogResult.OK) { applyFont(fontDialog.Font); } }; _view.RestoreFontCommand.Execute += () => { applyFont(Form.DefaultFont); }; _view.IncreaseFixedFontCommand.Execute += () => { _settings.Gui.FixedFont = IncreaseFont(_settings.Gui.FixedFont); }; _view.DecreaseFixedFontCommand.Execute += () => { _settings.Gui.FixedFont = DecreaseFont(_settings.Gui.FixedFont); }; _view.RestoreFixedFontCommand.Execute += () => { _settings.Gui.FixedFont = new Font(FontFamily.GenericMonospace, 8.0f); }; _view.StatusBarCommand.CheckedChanged += () => { _view.StatusBarView.Visible = _view.StatusBarCommand.Checked; }; _view.RunAllCommand.Execute += () => RunAllTests(); _view.RunSelectedCommand.Execute += () => RunSelectedTests(); _view.RunFailedCommand.Execute += () => RunFailedTests(); _view.StopRunCommand.Execute += () => CancelRun(); _view.ToolsMenu.Popup += () => { _view.ProjectEditorCommand.Enabled = File.Exists(_model.ProjectEditorPath); }; _view.ProjectEditorCommand.Execute += () => { string editorPath = _settings.Gui.ProjectEditorPath; if (editorPath != null && File.Exists(editorPath)) { System.Diagnostics.Process.Start(editorPath); } }; _view.SaveResultsCommand.Execute += () => SaveResults(); _view.ExtensionsCommand.Execute += () => { using (var extensionsDialog = new ExtensionDialog(_model.Services.ExtensionService)) { extensionsDialog.Font = _settings.Gui.Font; extensionsDialog.ShowDialog(); } }; _view.SettingsCommand.Execute += () => { SettingsDialog.Display(this, _model); }; _view.TestCentricHelpCommand.Execute += () => { _view.MessageDisplay.Error("Not Yet Implemented"); }; _view.NUnitHelpCommand.Execute += () => { System.Diagnostics.Process.Start("https://github.com/nunit/docs/wiki/NUnit-Documentation"); }; _view.AboutCommand.Execute += () => { using (AboutBox aboutBox = new AboutBox()) { aboutBox.ShowDialog(); } }; _view.ResultTabs.SelectionChanged += () => { _settings.Gui.SelectedTab = _view.ResultTabs.SelectedIndex; }; #endregion }
private void WireUpEvents() { // Model actions _model.TestLoaded += (ea) => { _strategy.OnTestLoaded(ea.Test); InitializeRunCommands(); InitializeCategories(ea.Categories); _view.ShowCheckBoxesCommand.Checked = Settings.ShowCheckboxes; }; _model.TestReloaded += (ea) => { _strategy.OnTestLoaded(ea.Test); InitializeRunCommands(); ApplyCategoryFilter(_view.Category.SelectedCategories.Items, _view.Category.ExcludeCommand.Checked); }; _model.TestUnloaded += (ea) => { _strategy.OnTestUnloaded(); InitializeRunCommands(); }; _model.RunStarting += (ea) => InitializeRunCommands(); _model.RunFinished += (ea) => InitializeRunCommands(); _model.TestFinished += (ea) => _strategy.OnTestFinished(ea.Result); _model.SuiteFinished += (ea) => _strategy.OnTestFinished(ea.Result); // View actions - Initial Load _view.Load += (s, e) => SetDefaultDisplayStrategy(); // View context commands _view.Tree.ContextMenu.Popup += () => _view.RunCheckedCommand.Visible = _view.Tree.CheckBoxes && _view.Tree.CheckedNodes.Count > 0; _view.CollapseAllCommand.Execute += () => _view.CollapseAll(); _view.ExpandAllCommand.Execute += () => _view.ExpandAll(); _view.CollapseToFixturesCommand.Execute += () => _strategy.CollapseToFixtures(); _view.ShowCheckBoxesCommand.CheckedChanged += () => { _view.RunSelectedCommand.Enabled = false; _view.Tree.CheckBoxes = _view.CheckAllTestsCommand.Visible = _view.UncheckAllTestsCommand.Visible = _view.CheckFailedTestsCommand.Visible = Settings.ShowCheckboxes = _view.ShowCheckBoxesCommand.Checked; }; _view.CheckAllTestsCommand.Execute += () => { var treeView = _view.Tree?.Control; if (treeView != null) { ToggleNodeCheck(treeView.Nodes, true, true); } }; _view.UncheckAllTestsCommand.Execute += () => { var treeView = _view.Tree?.Control; if (treeView != null) { ToggleNodeCheck(treeView.Nodes, false, true); } }; _view.CheckFailedTestsCommand.Execute += () => { var treeView = _view.Tree?.Control; if (treeView != null) { ToggleNodeCheck(_strategy.GetFailedNodes(), true, true); } }; _view.RunContextCommand.Execute += () => _model.RunTests(_selectedTestItem); _view.RunCheckedCommand.Execute += RunCheckedTests; // Node selected in tree _view.Tree.SelectedNodeChanged += (tn) => { _selectedTestItem = tn.Tag as ITestItem; _view.RunContextCommand.Enabled = (_selectedTestItem as TestNode)?.CanRun() ?? true; _model.NotifySelectedItemChanged(_selectedTestItem); }; // Run button and dropdowns _view.RunButton.Execute += () => _model.RunAllTests(); _view.RunAllCommand.Execute += () => _model.RunAllTests(); _view.RunSelectedCommand.Execute += () => _model.RunTests(_selectedTestItem); _view.RunFailedCommand.Execute += () => RunFailedTest(); _view.StopRunCommand.Execute += () => _model.CancelTestRun(); // Change of display format _view.DisplayFormat.SelectionChanged += () => { SetDisplayStrategy(_view.DisplayFormat.SelectedItem); _strategy.Reload(); ApplyCategoryFilter(_view.Category.SelectedCategories.Items, _view.Category.ExcludeCommand.Checked); }; _view.Category.SelectedCategories.ItemsChanged += (sender, ae) => ApplyCategoryFilter(ae.Value, _view.Category.ExcludeCommand.Checked); _view.Category.ExcludeCommand.CheckedChanged += () => ApplyCategoryFilter(_view.Category.SelectedCategories.Items, _view.Category.ExcludeCommand.Checked); }
private void WireUpEvents() { // Model actions _model.Events.TestLoaded += (ea) => { _strategy.OnTestLoaded(ea.Test); InitializeRunCommands(); }; _model.Events.TestReloaded += (ea) => { _strategy.OnTestLoaded(ea.Test); InitializeRunCommands(); }; _model.Events.TestUnloaded += (ea) => { _strategy.OnTestUnloaded(); InitializeRunCommands(); }; _model.Events.RunStarting += (ea) => InitializeRunCommands(); _model.Events.RunFinished += (ea) => InitializeRunCommands(); _model.Events.TestFinished += (ea) => _strategy.OnTestFinished(ea.Result); _model.Events.SuiteFinished += (ea) => _strategy.OnTestFinished(ea.Result); _model.Services.UserSettings.Changed += (s, e) => { if (e.SettingName == "Gui.TestTree.AlternateImageSet") { _view.AlternateImageSet = Settings.AlternateImageSet; } }; // View actions - Initial Load _view.Load += (s, e) => { SetDefaultDisplayStrategy(); }; // View context commands _view.Tree.ContextMenu.Popup += delegate { bool checkedRunAvailable = _view.Tree.CheckBoxes && _view.Tree.CheckedNodes.Count > 0; _view.RunCheckedCommand.Visible = checkedRunAvailable; _view.DebugCheckedCommand.Visible = checkedRunAvailable; }; _view.CollapseAllCommand.Execute += () => _view.CollapseAll(); _view.ExpandAllCommand.Execute += () => _view.ExpandAll(); _view.CollapseToFixturesCommand.Execute += () => _strategy.CollapseToFixtures(); _view.ShowCheckBoxes.CheckedChanged += () => _view.Tree.CheckBoxes = _view.ShowCheckBoxes.Checked;; _view.RunContextCommand.Execute += () => { if (_selectedTestItem != null) { _model.RunTests(_selectedTestItem); } }; _view.RunCheckedCommand.Execute += RunCheckedTests; _view.DebugContextCommand.Execute += () => { if (_selectedTestItem != null) { _model.DebugTests(_selectedTestItem); } }; _view.DebugCheckedCommand.Execute += DebugCheckedTests; // Node selected in tree _view.Tree.SelectedNodeChanged += (tn) => { _selectedTestItem = tn.Tag as ITestItem; _model.NotifySelectedItemChanged(_selectedTestItem); }; // Run button and dropdowns _view.RunButton.Execute += () => { // Necessary test because we don't disable the button click if (_model.HasTests && !_model.IsTestRunning) { RunAllTests(); } }; _view.RunAllCommand.Execute += () => RunAllTests(); _view.RunSelectedCommand.Execute += () => RunTests(_selectedTestItem); _view.RunFailedCommand.Execute += () => RunAllTests(); // RunFailed NYI _view.StopRunCommand.Execute += () => _model.CancelTestRun(); // Debug button and dropdowns _view.DebugButton.Execute += () => { // Necessary test because we don't disable the button click if (_model.HasTests && !_model.IsTestRunning) { _model.DebugAllTests(); } }; _view.DebugAllCommand.Execute += () => _model.DebugAllTests(); _view.DebugSelectedCommand.Execute += () => _model.DebugTests(_selectedTestItem); _view.DebugFailedCommand.Execute += () => _model.DebugAllTests(); // NYI // Change of display format _view.DisplayFormat.SelectionChanged += () => { SetDisplayStrategy(_view.DisplayFormat.SelectedItem); _strategy.Reload(); }; }
private void WireUpEvents() { // Model actions _model.Events.TestLoaded += (ea) => { _strategy.OnTestLoaded(ea.Test); InitializeRunCommands(); }; _model.Events.TestReloaded += (ea) => { _strategy.OnTestLoaded(ea.Test); InitializeRunCommands(); }; _model.Events.TestUnloaded += (ea) => { _strategy.OnTestUnloaded(); InitializeRunCommands(); }; _model.Events.RunStarting += (ea) => InitializeRunCommands(); _model.Events.RunFinished += (ea) => InitializeRunCommands(); _model.Events.TestFinished += (ea) => _strategy.OnTestFinished(ea.Result); _model.Events.SuiteFinished += (ea) => _strategy.OnTestFinished(ea.Result); _model.Settings.Changed += (s, e) => { if (e.SettingName == "Gui.TestTree.AlternateImageSet") { _view.AlternateImageSet = Settings.AlternateImageSet; } }; // View actions - Initial Load _view.Load += (s, e) => { SetDefaultDisplayStrategy(); }; // View context commands // Test for null is a hack that allows us to avoid // a problem under Linux creating a ContextMenuStrip // when no display is present. if (_view.Tree.ContextMenuStrip != null) { _view.Tree.ContextMenuStrip.Opening += (s, e) => InitializeContextMenu(); } _view.CollapseAllCommand.Execute += () => _view.CollapseAll(); _view.ExpandAllCommand.Execute += () => _view.ExpandAll(); _view.CollapseToFixturesCommand.Execute += () => _strategy.CollapseToFixtures(); _view.ShowCheckBoxes.CheckedChanged += () => { _view.RunCheckedCommand.Visible = _view.DebugCheckedCommand.Visible = _view.Tree.CheckBoxes = _view.ShowCheckBoxes.Checked; }; _view.RunContextCommand.Execute += () => { if (_selectedTestItem != null) { _model.RunTests(_selectedTestItem); } }; _view.RunCheckedCommand.Execute += RunCheckedTests; _view.DebugContextCommand.Execute += () => { if (_selectedTestItem != null) { _model.DebugTests(_selectedTestItem); } }; _view.DebugCheckedCommand.Execute += DebugCheckedTests; // Node selected in tree _view.Tree.SelectedNodeChanged += (tn) => { _selectedTestItem = tn.Tag as ITestItem; _model.NotifySelectedItemChanged(_selectedTestItem); }; // Run button and dropdowns _view.RunButton.Execute += () => { // Necessary test because we don't disable the button click if (_model.HasTests && !_model.IsTestRunning) { RunAllTests(); } }; _view.RunAllCommand.Execute += () => RunAllTests(); _view.RunSelectedCommand.Execute += () => RunTests(_selectedTestItem); _view.RunFailedCommand.Execute += () => RunAllTests(); // RunFailed NYI _view.StopRunCommand.Execute += () => _model.CancelTestRun(true); _view.TestParametersCommand.Execute += () => { using (var dlg = new TestParametersDialog()) { dlg.Font = _model.Settings.Gui.Font; dlg.StartPosition = FormStartPosition.CenterParent; if (_model.PackageOverrides.ContainsKey("TestParametersDictionary")) { var testParms = _model.PackageOverrides["TestParametersDictionary"] as IDictionary <string, string>; foreach (string key in testParms.Keys) { dlg.Parameters.Add(key, testParms[key]); } } if (dlg.ShowDialog(_view as IWin32Window) == DialogResult.OK) { ChangePackageSettingAndReload("TestParametersDictionary", dlg.Parameters); } } }; // Debug button and dropdowns _view.DebugButton.Execute += () => { // Necessary test because we don't disable the button click if (_model.HasTests && !_model.IsTestRunning) { _model.DebugAllTests(); } }; _view.DebugAllCommand.Execute += () => _model.DebugAllTests(); _view.DebugSelectedCommand.Execute += () => _model.DebugTests(_selectedTestItem); _view.DebugFailedCommand.Execute += () => _model.DebugAllTests(); // NYI // Change of display format _view.DisplayFormat.SelectionChanged += () => { SetDisplayStrategy(_view.DisplayFormat.SelectedItem); _strategy.Reload(); }; }