private void WireUpEvents()
        {
            _model.Events.TestsLoading += (e) =>
            {
                _view.RunCommand.Enabled = false;
            };

            _model.Events.TestLoaded += (e) =>
            {
                _view.RunCommand.Enabled = true;
                _view.CheckPropertiesDialog();

                if (e.Test.Children.Count == 1)
                {
                    _view.LoadTests(e.Test.Children[0]);
                }
                else
                {
                    _view.LoadTests(e.Test);
                }


                if (_model.Services.UserSettings.Gui.TestTree.SaveVisualState)
                {
                    string fileName = VisualState.GetVisualStateFileName(_model.TestFiles[0]);
                    if (File.Exists(fileName) && new FileInfo(fileName).Length > 0)
                    {
                        try
                        {
                            var visualState = VisualState.LoadFrom(fileName);
                            _view.RestoreVisualState(visualState);
                            _model.SelectCategories(visualState.SelectedCategories, visualState.ExcludeCategories);
                        }
                        catch (Exception exception)
                        {
                            var messageDisplay = new MessageDisplay();
                            messageDisplay.Error($"There was an error loading the Visual State from {fileName}");
                        }
                    }
                }
            };

            _model.Events.TestsReloading += (e) =>
            {
                _view.RunCommand.Enabled = false;
            };

            _model.Events.TestReloaded += (e) =>
            {
                _view.Reload(e.Test);

                if (!_settings.Gui.ClearResultsOnReload)
                {
                    RestoreResults(e.Test);
                }

                _view.RunCommand.Enabled = true;
            };

            _model.Events.TestsUnloading += (e) =>
            {
                _view.RunCommand.Enabled = false;

                _view.ClosePropertiesDialog();

                if (_settings.Gui.TestTree.SaveVisualState)
                {
                    try
                    {
                        var visualState = _view.GetVisualState();
                        visualState.SelectedCategories = _model.SelectedCategories;
                        visualState.ExcludeCategories  = _model.ExcludeSelectedCategories;
                        visualState.Save(VisualState.GetVisualStateFileName(_model.TestFiles[0]));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Unable to save visual state.");
                        Debug.WriteLine(ex);
                    }
                }

                _view.Clear();
            };

            _model.Events.TestUnloaded += (e) =>
            {
                _view.RunCommand.Enabled = false;
            };

            _model.Events.RunStarting += (e) =>
            {
                _view.RunCommand.Enabled = false;
                _view.CheckPropertiesDialog();
            };

            _model.Events.RunFinished += (e) =>
            {
                _view.RunCommand.Enabled = true;
            };

            _model.Events.TestFinished += (e) =>
            {
                _view.SetTestResult(e.Result);
            };

            _model.Events.SuiteFinished += (e) =>
            {
                _view.SetTestResult(e.Result);
            };

            //_settings.Changed += (s, e) =>
            //{
            //    if (e.SettingName == "Gui.TestTree.AlternateImageSet")
            //   {
            //       _view.LoadAlternateImages();
            //       _view.Invalidate();
            //   }
            //};

            _model.Events.CategorySelectionChanged += (TestEventArgs e) =>
            {
                TestNodeFilter filter = TestNodeFilter.Empty;

                if (_model.SelectedCategories.Count > 0)
                {
                    filter = new CategoryFilter(_model.SelectedCategories);
                    if (_model.ExcludeSelectedCategories)
                    {
                        filter = new NotFilter(filter);
                    }
                }

                _view.TreeFilter = filter;
            };

            _view.FileDrop += _model.LoadTests;

            _view.RunCommand.Execute += () =>
            {
                if (_settings.Gui.ReloadOnRun)
                {
                    _model.ClearResults();
                }

                if (_view.ContextNode != null)
                {
                    _model.RunTests(_view.ContextNode.Test);
                }
                else
                {
                    _model.RunTests(new TestSelection(_view.SelectedTests));
                }
            };

            _view.ShowCheckBoxes.CheckedChanged += () =>
            {
                _settings.Gui.TestTree.ShowCheckBoxes = _view.CheckBoxes = _view.ShowCheckBoxes.Checked;
            };

            _view.ShowFailedAssumptions.CheckedChanged += () =>
            {
                TestSuiteTreeNode targetNode = _view.ContextNode ?? (TestSuiteTreeNode)_view.SelectedNode;
                TestSuiteTreeNode theoryNode = targetNode?.GetTheoryNode();
                if (theoryNode != null)
                {
                    theoryNode.ShowFailedAssumptions = _view.ShowFailedAssumptions.Checked;
                }
            };

            _view.PropertiesCommand.Execute += () =>
            {
                TestSuiteTreeNode targetNode = _view.ContextNode ?? (TestSuiteTreeNode)_view.SelectedNode;
                if (targetNode != null)
                {
                    _view.ShowPropertiesDialog(targetNode);
                }
            };
        }
Example #2
0
 public void RunAllTests()
 {
     _model.ClearResults();
     _model.RunAllTests();
 }
Example #3
0
        private void WireUpEvents()
        {
            _model.Events.TestsLoading += (e) => _view.RunCommand.Enabled = false;

            _model.Events.TestLoaded += (e) =>
            {
                _view.RunCommand.Enabled = true;
                _view.CheckPropertiesDialog();

                LoadTests(GetTopDisplayNode(e.Test));

                if (_model.Services.UserSettings.Gui.TestTree.SaveVisualState)
                {
                    string fileName = VisualState.GetVisualStateFileName(_model.TestFiles[0]);
                    if (File.Exists(fileName) && new FileInfo(fileName).Length > 0)
                    {
                        try
                        {
                            var visualState = VisualState.LoadFrom(fileName);
                            visualState.RestoreVisualState(_view, _treeMap);
                            _model.SelectCategories(visualState.SelectedCategories, visualState.ExcludeCategories);
                        }
                        catch (Exception ex)
                        {
                            new MessageDisplay().Error(
                                $"Unable to load visual state from {fileName}{Environment.NewLine}{ex.Message}");
                        }
                    }
                }
            };

            _model.Events.TestsReloading += (e) => _view.RunCommand.Enabled = false;

            _model.Events.TestReloaded += (e) =>
            {
                ReloadTests(GetTopDisplayNode(e.Test));

                if (!_settings.Gui.ClearResultsOnReload)
                {
                    RestoreResults(e.Test);
                }

                _view.RunCommand.Enabled = true;
            };

            _model.Events.TestsUnloading += (e) =>
            {
                _view.RunCommand.Enabled = false;

                _view.ClosePropertiesDialog();

                if (_settings.Gui.TestTree.SaveVisualState)
                {
                    try
                    {
                        var visualState = VisualState.LoadFrom(_view);
                        visualState.SelectedCategories = _model.SelectedCategories;
                        visualState.ExcludeCategories  = _model.ExcludeSelectedCategories;
                        visualState.Save(VisualState.GetVisualStateFileName(_model.TestFiles[0]));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Unable to save visual state.");
                        Debug.WriteLine(ex);
                    }
                }

                _view.Clear();
                _treeMap.Clear();
            };

            _model.Events.TestUnloaded += (e) => _view.RunCommand.Enabled = false;

            _model.Events.RunStarting += (e) =>
            {
                _view.RunCommand.Enabled = false;
                _view.CheckPropertiesDialog();
            };

            _model.Events.RunFinished += (e) => _view.RunCommand.Enabled = true;

            _model.Events.TestFinished += (e) => SetTestResult(e.Result);

            _model.Events.SuiteFinished += (e) => SetTestResult(e.Result);

            _model.Events.CategorySelectionChanged += (TestEventArgs e) =>
            {
                TestNodeFilter filter = TestNodeFilter.Empty;

                if (_model.SelectedCategories.Count > 0)
                {
                    filter = new CategoryFilter(_model.SelectedCategories);
                    if (_model.ExcludeSelectedCategories)
                    {
                        filter = new NotFilter(filter);
                    }
                }

                _view.TreeFilter = filter;
            };

            _settings.Changed += (s, e) =>
            {
                if (e.SettingName == "Gui.TestTree.AlternateImageSet")
                {
                    _view.AlternateImageSet = _settings.Gui.TestTree.AlternateImageSet;
                }
                else if (e.SettingName == "Gui.TestTree.ShowCheckBoxes")
                {
                    var showCheckBoxes = _settings.Gui.TestTree.ShowCheckBoxes;

                    // When turning off checkboxes with a non-empty tree, the
                    // structure of what is expanded and collapsed is lost.
                    // We save that structure as a VisualState and then restore it.
                    VisualState visualState = !showCheckBoxes && _view.Tree.TopNode != null
                        ? VisualState.LoadFrom(_view)
                        : null;

                    _view.CheckBoxes = showCheckBoxes;

                    if (visualState != null)
                    {
                        visualState.ShowCheckBoxes = showCheckBoxes;
                        visualState.RestoreVisualState(_view, _treeMap);
                    }
                }
            };

            _view.FileDrop += _model.LoadTests;

            _view.RunCommand.Execute += () =>
            {
                if (_settings.Gui.ReloadOnRun)
                {
                    _model.ClearResults();
                }

                if (_view.ContextNode != null)
                {
                    _model.RunTests(_view.ContextNode.Test);
                }
                else
                {
                    _model.RunTests(new TestSelection(_view.SelectedTests));
                }
            };

            _view.ShowCheckBoxes.CheckedChanged += () => _view.CheckBoxes = _view.ShowCheckBoxes.Checked;

            _view.ClearAllCheckBoxes.Execute += () => ClearAllCheckBoxes(_view.Tree.TopNode);

            _view.CheckFailedTests.Execute += () => CheckFailedTests(_view.Tree.TopNode);

            _view.ShowFailedAssumptions.CheckedChanged += () =>
            {
                TestSuiteTreeNode targetNode = _view.ContextNode ?? (TestSuiteTreeNode)_view.Tree.SelectedNode;
                TestSuiteTreeNode theoryNode = targetNode?.GetTheoryNode();
                if (theoryNode != null)
                {
                    theoryNode.ShowFailedAssumptions = _view.ShowFailedAssumptions.Checked;
                }
            };

            _view.ExpandAllCommand.Execute += () => _view.Tree.ExpandAll();

            _view.CollapseAllCommand.Execute += () => _view.Tree.CollapseAll();

            _view.HideTestsCommand.Execute += () => HideTestsUnderNode(_model.Tests);

            _view.PropertiesCommand.Execute += () =>
            {
                TestSuiteTreeNode targetNode = _view.ContextNode ?? (TestSuiteTreeNode)_view.Tree.SelectedNode;
                if (targetNode != null)
                {
                    _view.ShowPropertiesDialog(targetNode);
                }
            };
        }