DisplayStrategy is the abstract base for the various strategies used to display tests in the tree control. It works primarily as a traditional strategy, with methods called by the TreeViewPresenter, but may also function as a presenter in it's own right, since it is created with references to the view and mode. We currently support three different strategies: NunitTreeDisplay, TestListDisplay and FixtureListDisplay.
        public TreeViewPresenter(ITestTreeView treeView, ITestModel model)
        {
            _view = treeView;
            _model = model;

            // Create the initial display, which assists the presenter
            // both by providing public methods and by handling events.
            _displayFormat = _model.Settings.Gui.TestTree.DisplayFormat;
            _display = CreateDisplayStrategy(_displayFormat);
            _view.FormatButton.ToolStripItem.ToolTipText = _display.Description;

            InitializeRunCommands();
            WireUpEvents();
        }
Exemple #2
0
        public TreeViewPresenter(ITestTreeView treeView, ITestModel model)
        {
            _view  = treeView;
            _model = model;

            // Create the initial display, which assists the presenter
            // both by providing public methods and by handling events.
            _displayFormat = _model.Settings.Gui.TestTree.DisplayFormat;
            _display       = CreateDisplayStrategy(_displayFormat);
            _view.FormatButton.ToolStripItem.ToolTipText = _display.Description;

            InitializeRunCommands();
            WireUpEvents();
        }
Exemple #3
0
        private void CreateDisplayStrategy(string format)
        {
            switch (format.ToUpperInvariant())
            {
            default:
            case "NUNIT_TREE":
                _strategy = new NUnitTreeDisplayStrategy(_view, _model);
                break;

            case "FIXTURE_LIST":
                _strategy = new FixtureListDisplayStrategy(_view, _model);
                break;

            case "TEST_LIST":
                _strategy = new TestListDisplayStrategy(_view, _model);
                break;
            }

            _view.FormatButton.ToolTipText   = _strategy.Description;
            _view.DisplayFormat.SelectedItem = format;
        }
Exemple #4
0
        public override void OnTestFinished(ResultNode result)
        {
            var imageIndex = DisplayStrategy.CalcImageIndex(result.Outcome);

            if (imageIndex >= TestTreeView.SuccessIndex)
            {
                var treeNodes = _displayStrategy.GetTreeNodesForTest(result);
                foreach (var treeNode in treeNodes)
                {
                    var parentNode = treeNode.Parent;
                    if (parentNode != null)
                    {
                        var group = parentNode.Tag as TestGroup;
                        if (group != null && imageIndex > group.ImageIndex)
                        {
                            parentNode.SelectedImageIndex = parentNode.ImageIndex = group.ImageIndex = imageIndex;
                        }
                    }
                }
            }
        }
Exemple #5
0
        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 CreateDisplayStrategy(string format)
        {
            switch (format.ToUpperInvariant())
            {
                default:
                case "NUNIT_TREE":
                    _strategy = new NUnitTreeDisplayStrategy(_view, _model);
                    break;
                case "FIXTURE_LIST":
                    _strategy = new FixtureListDisplayStrategy(_view, _model);
                    break;
                case "TEST_LIST":
                    _strategy = new TestListDisplayStrategy(_view, _model);
                    break;
            }

            _view.FormatButton.ToolTipText = _strategy.Description;
            _view.DisplayFormat.SelectedItem = format;
        }
Exemple #7
0
        public void ChangeGroupsBasedOnTestResult(ResultNode result, bool updateImages)
        {
            var treeNodes = _displayStrategy.GetTreeNodesForTest(result);

            // Result may be for a TestNode not shown in the tree
            if (treeNodes.Count == 0)
            {
                return;
            }

            // This implementation ignores any but the first node
            // since changing of groups is currently only needed
            // for groupings that display each node once.
            var treeNode  = treeNodes[0];
            var oldParent = treeNode.Parent;
            var oldGroup  = oldParent.Tag as TestGroup;

            // We only have to proceed for tests that are direct
            // descendants of a group node.
            if (oldGroup == null)
            {
                return;
            }

            var newGroup = SelectGroups(result)[0];

            // If the group didn't change, we can get out of here
            if (oldGroup == newGroup)
            {
                return;
            }

            var newParent = newGroup.TreeNode;

            _displayStrategy.Tree.InvokeIfRequired(() =>
            {
                oldGroup.RemoveId(result.Id);
                // TODO: Insert in order
                newGroup.Add(result);

                // Remove test from tree
                treeNode.Remove();

                // If it was last test in group, remove group
                if (oldGroup.Count == 0)
                {
                    oldParent.Remove();
                }
                else // update old group
                {
                    oldParent.Text = _displayStrategy.GroupDisplayName(oldGroup);
                    if (updateImages)
                    {
                        oldParent.ImageIndex = oldParent.SelectedImageIndex = oldGroup.ImageIndex =
                            _displayStrategy.CalcImageIndexForGroup(oldGroup);
                    }
                }

                newParent.Nodes.Add(treeNode);
                newParent.Text = _displayStrategy.GroupDisplayName(newGroup);
                newParent.Expand();

                if (updateImages)
                {
                    var imageIndex = DisplayStrategy.CalcImageIndex(result.Outcome);
                    if (imageIndex >= TestTreeView.SuccessIndex && imageIndex > newGroup.ImageIndex)
                    {
                        newParent.ImageIndex = newParent.SelectedImageIndex = newGroup.ImageIndex = imageIndex;
                    }
                }

                if (newGroup.Count == 1)
                {
                    _displayStrategy.Tree.Clear();
                    TreeNode topNode = null;
                    foreach (var group in Groups)
                    {
                        if (group.Count > 0)
                        {
                            _displayStrategy.Tree.Add(group.TreeNode);
                            if (topNode == null)
                            {
                                topNode = group.TreeNode;
                            }
                        }
                    }

                    if (topNode != null)
                    {
                        topNode.EnsureVisible();
                    }
                }
            });
        }
        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();
            };
        }