private void propertiesMenuItem_Click(object sender, System.EventArgs e)
        {
            TestSuiteTreeNode targetNode = explicitlySelectedNode != null ? explicitlySelectedNode : (TestSuiteTreeNode)SelectedNode;

            if (targetNode != null)
            {
                ShowPropertiesDialog(targetNode);
            }
        }
        /// <summary>
        /// When Collapse context menu item is clicked, collapse the node
        /// </summary>
        private void collapseMenuItem_Click(object sender, System.EventArgs e)
        {
            TestSuiteTreeNode targetNode = explicitlySelectedNode != null ? explicitlySelectedNode : (TestSuiteTreeNode)SelectedNode;

            if (targetNode != null)
            {
                targetNode.Collapse();
            }
        }
 /// <summary>
 /// Remove a node from the tree itself and the hashtable
 /// </summary>
 /// <param name="treeNode">Node to remove</param>
 private void RemoveNode(TestSuiteTreeNode treeNode)
 {
     if (explicitlySelectedNode == treeNode)
     {
         explicitlySelectedNode = null;
     }
     RemoveFromMap(treeNode);
     treeNode.Remove();
 }
        //private TestSuiteTreeNode AddTreeNodes( IList nodes, TestResult rootResult, bool highlight )
        //{
        //	TestSuiteTreeNode node = new TestSuiteTreeNode( rootResult );
        //	AddToMap( node );

        //	nodes.Add( node );

        //	if ( rootResult.HasResults )
        //	{
        //		foreach( TestResult result in rootResult.Results )
        //			AddTreeNodes( node.Nodes, result, highlight );
        //	}

        //	node.UpdateImageIndex();

        //	return node;
        //}

        private void RemoveFromMap(TestSuiteTreeNode node)
        {
            foreach (TestSuiteTreeNode child in node.Nodes)
            {
                RemoveFromMap(child);
            }

            treeMap.Remove(node.Test.Id);
        }
        private void FindCheckedNodes(TestSuiteTreeNode node, bool topLevel)
        {
            if (node.Checked)
            {
                checkedTests.Add(new CheckedTestInfo(node.Test, topLevel));
                topLevel = false;
            }

            FindCheckedNodes(node.Nodes, topLevel);
        }
        private TestSuiteTreeNode FindNode(TestNode test)
        {
            TestSuiteTreeNode node = treeMap[test.Id] as TestSuiteTreeNode;

            if (node == null)
            {
                node = FindNodeByName(test.FullName);
            }

            return(node);
        }
 public override void Visit(TestSuiteTreeNode node)
 {
     if (!node.Test.IsSuite &&
         node.HasResult &&
         node.Result.Outcome.Status == TestStatus.Failed)
     {
         node.Checked = true;
         node.EnsureVisible();
     }
     else
     {
         node.Checked = false;
     }
 }
        private void failedAssumptionsMenuItem_Click(object sender, System.EventArgs e)
        {
            TestSuiteTreeNode targetNode = explicitlySelectedNode != null ? explicitlySelectedNode : (TestSuiteTreeNode)SelectedNode;
            TestSuiteTreeNode theoryNode = targetNode != null?targetNode.GetTheoryNode() : null;

            if (theoryNode != null)
            {
                MenuItem item = (MenuItem)sender;

                BeginUpdate();
                item.Checked = !item.Checked;
                theoryNode.ShowFailedAssumptions = item.Checked;
                EndUpdate();
            }
        }
        /// <summary>
        /// Gets the Theory node associated with the current
        /// node. If the current node is a Theory, then the
        /// current node is returned. Otherwise, if the current
        /// node is a test case under a theory node, then that
        /// node is returned. Otherwise, null is returned.
        /// </summary>
        /// <returns></returns>
        public TestSuiteTreeNode GetTheoryNode()
        {
            if (this.Test.Type == "Theory")
            {
                return(this);
            }

            TestSuiteTreeNode parent = this.Parent as TestSuiteTreeNode;

            if (parent != null && parent.Test.Type == "Theory")
            {
                return(parent);
            }

            return(null);
        }
        /// <summary>
        /// Build treeview context menu dynamically on popup
        /// </summary>
        private void ContextMenu_Popup(object sender, System.EventArgs e)
        {
            this.ContextMenu.MenuItems.Clear();

            TestSuiteTreeNode targetNode = explicitlySelectedNode != null ? explicitlySelectedNode : (TestSuiteTreeNode)SelectedNode;

            if (targetNode == null)
            {
                return;
            }

            // TODO: handle in Starting event
            if (Model.IsTestRunning)
            {
                runCommandEnabled = false;
            }

            MenuItem runMenuItem = new MenuItem("&Run", new EventHandler(runMenuItem_Click));

            runMenuItem.DefaultItem = runMenuItem.Enabled = runCommandEnabled && targetNode.Included &&
                                                            (targetNode.Test.RunState == RunState.Runnable || targetNode.Test.RunState == RunState.Explicit);
            this.ContextMenu.MenuItems.Add(runMenuItem);
            this.ContextMenu.MenuItems.Add("-");

            TestSuiteTreeNode theoryNode = targetNode.GetTheoryNode();

            if (theoryNode != null)
            {
                MenuItem failedAssumptionsMenuItem = new MenuItem("Show Failed Assumptions", new EventHandler(failedAssumptionsMenuItem_Click));
                failedAssumptionsMenuItem.Checked = theoryNode.ShowFailedAssumptions;
                this.ContextMenu.MenuItems.Add(failedAssumptionsMenuItem);

                this.ContextMenu.MenuItems.Add("-");
            }

            MenuItem showCheckBoxesMenuItem = new MenuItem("Show CheckBoxes", new EventHandler(showCheckBoxesMenuItem_Click));

            showCheckBoxesMenuItem.Checked = this.CheckBoxes;
            this.ContextMenu.MenuItems.Add(showCheckBoxesMenuItem);
            this.ContextMenu.MenuItems.Add("-");

            MenuItem propertiesMenuItem = new MenuItem(
                "&Properties", new EventHandler(propertiesMenuItem_Click));

            this.ContextMenu.MenuItems.Add(propertiesMenuItem);
        }
        /// <summary>
        /// Helper collapses all fixtures under a node
        /// </summary>
        /// <param name="node">Node under which to collapse fixtures</param>
        private void HideTestsUnderNode(TestSuiteTreeNode node)
        {
            if (node.Test.IsSuite)
            {
                if (node.Test.Type == "TestFixture")
                {
                    node.Collapse();
                }
                else
                {
                    node.Expand();

                    foreach (TestSuiteTreeNode child in node.Nodes)
                    {
                        HideTestsUnderNode(child);
                    }
                }
            }
        }
 private void ShowPropertiesDialog(TestSuiteTreeNode node)
 {
     if (propertiesDialog == null)
     {
         Form owner = this.FindForm();
         propertiesDialog               = new TestPropertiesDialog(node);
         propertiesDialog.Owner         = owner;
         propertiesDialog.Font          = owner.Font;
         propertiesDialog.StartPosition = FormStartPosition.Manual;
         propertiesDialog.Left          = Math.Max(0, owner.Left + (owner.Width - propertiesDialog.Width) / 2);
         propertiesDialog.Top           = Math.Max(0, owner.Top + (owner.Height - propertiesDialog.Height) / 2);
         propertiesDialog.Show();
         propertiesDialog.Closed += new EventHandler(OnPropertiesDialogClosed);
     }
     else
     {
         propertiesDialog.DisplayProperties(node);
     }
 }
        /// <summary>
        /// Add the result of a test to the tree
        /// </summary>
        /// <param name="result">The result of the test</param>
        public void SetTestResult(ResultNode result)
        {
            TestSuiteTreeNode node = this[result];

            if (node == null)
            {
                Debug.WriteLine("Test not found in tree: " + result.FullName);
            }
            else
            {
                node.Result = result;

                if (result.Type == "Theory")
                {
                    node.RepopulateTheoryNode();
                }

                Invalidate(node.Bounds);
                Update();
            }
        }
        /// <summary>
        /// Add nodes to the tree constructed from a test
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection to which the new node should  be added</param>
        /// <param name="testNode">The test for which a node is to be built</param>
        /// <param name="highlight">If true, highlight the text for this node in the tree</param>
        /// <returns>A newly constructed TestSuiteTreeNode, possibly with descendant nodes</returns>
        private TestSuiteTreeNode AddTreeNodes(IList nodes, TestNode testNode, bool highlight)
        {
            TestSuiteTreeNode treeNode = new TestSuiteTreeNode(testNode);

            if (highlight)
            {
                treeNode.ForeColor = Color.Blue;
            }
            treeMap.Add(treeNode.Test.Id, treeNode);

            nodes.Add(treeNode);

            if (testNode.IsSuite)
            {
                foreach (TestNode child in testNode.Children)
                {
                    AddTreeNodes(treeNode.Nodes, child, highlight);
                }
            }

            return(treeNode);
        }
        /// <summary>
        /// Handles right mouse button down by
        /// remembering the proper context item
        /// and implements multiple select with the left button.
        /// </summary>
        /// <param name="e">MouseEventArgs structure with information about the mouse position and button state</param>
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                CheckPropertiesDialog();
                TreeNode theNode = GetNodeAt(e.X, e.Y);
                explicitlySelectedNode = theNode as TestSuiteTreeNode;
            }
            //else if (e.Button == MouseButtons.Left)
            //{
            //    if (Control.ModifierKeys == Keys.Control)
            //    {
            //        TestSuiteTreeNode theNode = GetNodeAt(e.X, e.Y) as TestSuiteTreeNode;
            //        if (theNode != null)
            //            theNode.IsSelected = true;
            //    }
            //    else
            //    {
            //        ClearSelected();
            //    }
            //}

            base.OnMouseDown(e);
        }
 public abstract void Visit(TestSuiteTreeNode node);
        public void InitializeView(ITestModel model, TestCentricPresenter presenter)
        {
            Model        = model;
            Presenter    = presenter;
            UserSettings = model.Services.UserSettings;

            LoadAlternateImages();

            Model.Events.TestLoaded += (TestNodeEventArgs e) =>
            {
                CheckPropertiesDialog();
                Presenter.EnableRunCommand(true);
                runCommandEnabled = true;
            };

            Model.Events.TestReloaded += (TestNodeEventArgs e) =>
            {
                if (e.Test != null)
                {
                    Invoke(new LoadHandler(Reload), new object[] { e.Test });
                }
            };

            Model.Events.TestsUnloading += (TestEventArgs e) =>
            {
                ClosePropertiesDialog();

                if (UserSettings.Gui.TestTree.SaveVisualState)
                {
                    try
                    {
                        new VisualState(this).Save(VisualState.GetVisualStateFileName(Model.TestFiles[0]));
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Unable to save visual state.");
                        Debug.WriteLine(ex);
                    }
                }

                Clear();
                explicitlySelectedNode = null;
                runCommandEnabled      = false;
            };

            Model.Events.RunStarting += (RunStartingEventArgs e) =>
            {
                CheckPropertiesDialog();

#if ACCUMULATE_RESULTS
                if (runningTests != null)
                {
                    foreach (ITest test in runningTests)
                    {
                        this[test].ClearResults();
                    }
                }
#else
                ClearAllResults();
#endif

                runCommandEnabled = false;
            };

            Model.Events.RunFinished += (TestResultEventArgs e) =>
            {
                if (runningTests != null)
                {
                    foreach (TestNode test in runningTests)
                    {
                        this[test.Id].Expand();
                    }
                }

                if (propertiesDialog != null)
                {
                    propertiesDialog.Invoke(new PropertiesDisplayHandler(propertiesDialog.DisplayProperties));
                }

                runningTests      = null;
                runCommandEnabled = true;
            };

            Model.Events.TestFinished += (TestResultEventArgs e) =>
            {
                SetTestResult(e.Result);
            };

            Model.Events.SuiteFinished += (TestResultEventArgs e) =>
            {
                SetTestResult(e.Result);
            };

            //Services.UserSettings.Changed += (object sender, SettingsEventArgs e) =>
            //{
            //    if (args.SettingName == "Gui.TestTree.AlternateImageSet")
            //    {
            //        LoadAlternateImages();
            //        Invalidate();
            //    }
            //};

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

            //    if (Model.SelectedCategories.Length > 0)
            //    {
            //        filter = new CategoryFilter(Model.SelectedCategories);
            //        if (Model.ExcludeSelectedCategories)
            //            filter = new NotFilter(filter);
            //    }

            //    TreeFilter = filter;
            //};
        }
 public override void Visit(TestSuiteTreeNode node)
 {
     node.Checked = false;
 }
 public override void Visit(TestSuiteTreeNode node)
 {
     node.Included = filter.Pass(node.Test);
 }