Пример #1
0
        private void UpdateCategorySelection()
        {
            var categories = new List <string>();

            foreach (string category in _view.SelectedList.Items)
            {
                categories.Add(category);
            }

            _model.SelectCategories(categories, _view.ExcludeCategories.Checked);
        }
Пример #2
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);
                }
            };
        }
Пример #3
0
        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);
                }
            };
        }
Пример #4
0
        public void InitializeView(ITestModel model)
        {
            Model = model;

            model.Events.TestLoaded += (TestNodeEventArgs e) =>
            {
                availableList.Items.Clear();
                selectedList.Items.Clear();

                availableList.SuspendLayout();
                foreach (string category in model.AvailableCategories)
                {
                    availableList.Items.Add(category);
                }

                // We need to ensure the tree loads first and restore the
                // visual state before checking the seleted categories.
                tests.LoadTests(e.Test);

                if (model.Services.UserSettings.Gui.TestTree.SaveVisualState)
                {
                    string fileName = VisualState.GetVisualStateFileName(Model.TestFiles[0]);
                    if (File.Exists(fileName))
                    {
                        var visualState = VisualState.LoadFrom(fileName);
                        tests.RestoreVisualState(visualState);
                        model.SelectCategories(visualState.SelectedCategories, visualState.ExcludeCategories);
                    }
                }

                // Reflect any changes in the controls
                if (model.SelectedCategories != null && model.SelectedCategories.Length > 0)
                {
                    selectedList.Items.AddRange(model.SelectedCategories);
                    excludeCheckbox.Checked = model.ExcludeSelectedCategories;

                    foreach (string cat in model.SelectedCategories)
                    {
                        if (model.AvailableCategories.Contains(cat))
                        {
                            availableList.Items.Remove(cat);
                            excludeCheckbox.Enabled = true;
                        }
                    }

                    UpdateCategorySelection();
                }

                availableList.ResumeLayout();
            };

            model.Events.TestReloaded += (TestNodeEventArgs e) =>
            {
                // Remove any selected items that are no longer available
                int index = selectedList.Items.Count;
                selectedList.SuspendLayout();
                while (--index >= 0)
                {
                    string category = selectedList.Items[index].ToString();
                    if (!model.AvailableCategories.Contains(category))
                    {
                        selectedList.Items.RemoveAt(index);
                    }
                }
                selectedList.ResumeLayout();

                // Clear check box if there are no more selected items.
                if (selectedList.Items.Count == 0)
                {
                    excludeCheckbox.Checked = excludeCheckbox.Enabled = false;
                }

                // Put any unselected available items on availableList
                availableList.Items.Clear();
                availableList.SuspendLayout();
                foreach (string category in model.AvailableCategories)
                {
                    if (selectedList.FindStringExact(category) < 0)
                    {
                        availableList.Items.Add(category);
                    }
                }
                availableList.ResumeLayout();

                // Tell the tree what is selected
                UpdateCategorySelection();
            };

            model.Events.TestUnloaded += (TestEventArgs e) =>
            {
                availableList.Items.Clear();
                selectedList.Items.Clear();
                excludeCheckbox.Checked = false;
                excludeCheckbox.Enabled = false;
            };
        }