public void MethodRemoved()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;
            TestClass           testClass   = projectNode.TestProject.TestClasses["RootNamespace.Tests.MyTestFixture"];

            TestMemberTreeNode methodNode = (TestMemberTreeNode)testFixtureNode.Nodes[0];
            TestMember         testMethod = testClass.TestMembers[0];

            testClass.TestMembers.Remove(testMethod);

            Assert.AreEqual(0, testFixtureNode.Nodes.Count);
            Assert.IsTrue(methodNode.IsDisposed);

            // Make sure the TestMethod.Dispose call removes all
            // event handlers by changing the TestMethod's test
            // result and seeing if the test method node is
            // affected even though we have removed it from the tree.

            // Make sure the test method result is not already a failure.
            testMethod.Result = TestResultType.None;
            testMethod.Result = TestResultType.Failure;
            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun,
                            (TestTreeViewImageListIndex)methodNode.ImageIndex,
                            "Disposed TestMethodTreeNode was affected by TestMethod result change");
        }
        public void EmptyNamespaceNodesRemovedWhenChildNamespaceNodeNotExpanded()
        {
            // Expand the project node.
            TestProjectTreeNode projectNode = (TestProjectTreeNode)pad.TestTreeView.Nodes[0];

            projectNode.Expanding();

            // Add a new class to a non-empty namespace so it gets
            // added to a new namespace node.
            MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture");
            TestClass testClass = new TestClass(mockClass, testFrameworks);

            projectNode.TestProject.TestClasses.Add(testClass);

            // Get the root namespace node.
            TestNamespaceTreeNode rootNamespaceNode = (TestNamespaceTreeNode)projectNode.Nodes[0];

            // Check that the rootNamespaceNode does not consider itself
            // empty.
            Assert.IsFalse(rootNamespaceNode.IsEmpty);

            // Expand RootNamespace tree node.
            rootNamespaceNode.Expanding();

            // Remove the test class from the test project.
            projectNode.TestProject.TestClasses.Remove(testClass);

            Assert.AreEqual(0, projectNode.Nodes.Count,
                            "Namespace nodes should have been removed from project node.");
        }
        public void NewMethodAdded()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;
            TestClass           testClass   = projectNode.TestProject.TestClasses["RootNamespace.Tests.MyTestFixture"];

            MockMethod method = new MockMethod(testClass.Class, "NewMethod");

            method.Attributes.Add(new MockAttribute("Test"));
            testClass.TestMembers.Add(new TestMember(method));

            ExtTreeNode newMethodNode = null;

            foreach (ExtTreeNode node in testFixtureNode.Nodes)
            {
                if (node.Text == "NewMethod")
                {
                    newMethodNode = node;
                    break;
                }
            }

            Assert.AreEqual(2, testFixtureNode.Nodes.Count);
            Assert.IsNotNull(newMethodNode);
            Assert.IsInstanceOf(typeof(TestMemberTreeNode), newMethodNode);
        }
        public void ClassNodeAddedAfterNamespaceNodeExpanded()
        {
            ClassNodeAddedAfterProjectNodeExpanded();

            // Expand the namespace node.
            TestProjectTreeNode   projectNode         = (TestProjectTreeNode)pad.TestTreeView.Nodes[0];
            TestNamespaceTreeNode parentNamespaceNode = (TestNamespaceTreeNode)projectNode.Nodes[0];

            parentNamespaceNode.Expanding();

            // Add a new class to a namespace so it gets
            // added to a new namespace node.
            MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture");
            TestClass testClass = new TestClass(mockClass, testFrameworks);

            projectNode.TestProject.TestClasses.Add(testClass);

            // Get the newly added namespace node.
            TestNamespaceTreeNode namespaceNode = null;

            foreach (ExtTreeNode node in parentNamespaceNode.Nodes)
            {
                namespaceNode = node as TestNamespaceTreeNode;
                if (namespaceNode != null)
                {
                    break;
                }
            }

            Assert.AreEqual(2, parentNamespaceNode.Nodes.Count,
                            "Namespace node should have two child nodes.");
            Assert.IsNotNull(namespaceNode, "Namespace node has not been added");
            Assert.AreEqual("Tests", namespaceNode.Text);
        }
        public void GetTestProjectFromProject()
        {
            TestProjectTreeNode projectNode         = (TestProjectTreeNode)pad.TestTreeView.Nodes[0];
            TestProject         expectedTestProject = projectNode.TestProject;

            Assert.AreSame(expectedTestProject, pad.TestTreeView.GetTestProject(project));
        }
        public void AddNewClass()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            MockClass mockClass = new MockClass(projectContent, "MyNewTestFixture");

            mockClass.Attributes.Add(new MockAttribute("TestFixture"));
            TestClass newTestClass = new TestClass(mockClass, testFrameworks);

            projectNode.TestProject.TestClasses.Add(newTestClass);

            ExtTreeNode newTestClassNode = null;

            foreach (ExtTreeNode node in rootNode.Nodes)
            {
                if (node.Text == "MyNewTestFixture")
                {
                    newTestClassNode = node;
                    break;
                }
            }
            newTestClass.Result = TestResultType.Failure;

            // New test class node should be added to the root node.
            Assert.IsNotNull(newTestClassNode);
            Assert.AreEqual(2, rootNode.Nodes.Count);

            // Make sure the project node image index is affected by the
            // new test class added.
            Assert.AreEqual(TestTreeViewImageListIndex.TestFailed, (TestTreeViewImageListIndex)rootNode.SelectedImageIndex);
        }
        public void ProjectRemoved()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            treeView.RemoveProject(projectNode.TestProject.Project);

            Assert.AreEqual(0, treeView.Nodes.Count);
        }
        public void TestProjectNUnitReferenceRemoved()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            ProjectService.RemoveProjectItem(projectNode.TestProject.Project, nunitFrameworkReferenceItem);

            treeView.ProjectItemRemoved(nunitFrameworkReferenceItem);

            Assert.AreEqual(0, treeView.Nodes.Count);
        }
        public void RemoveClass()
        {
            // Locate the class we are going to remove.
            TestProjectTreeNode projectNode   = (TestProjectTreeNode)rootNode;
            TestClassTreeNode   testClassNode = (TestClassTreeNode)projectNode.Nodes[0];

            testClassNode.Expanding();
            TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"];

            projectNode.TestProject.TestClasses.Remove(testClass);

            ExtTreeNode testClassNodeAfterRemove = null;

            foreach (ExtTreeNode node in rootNode.Nodes)
            {
                if (node.Text == "MyTestFixture")
                {
                    testClassNodeAfterRemove = node;
                    break;
                }
            }

            Assert.IsNull(testClassNodeAfterRemove);
            Assert.AreEqual(0, projectNode.Nodes.Count);
            Assert.IsTrue(testClassNode.IsDisposed);

            // Make sure the TestClassTreeNode.Dispose removes all event
            // handlers.
            // It uses the events:
            // TestClass.ResultChanged
            // TestClassCollection.TestMethodAdded
            // TestClassCollection.TestMethodRemoved

            // Make sure the test class result is not a failure already.
            testClass.Result = TestResultType.None;
            testClass.Result = TestResultType.Failure;
            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun,
                            (TestTreeViewImageListIndex)testClassNode.ImageIndex,
                            "Disposed TestClassTreeNode affected by test class result change.");

            // Add a new test method to the test class
            // and make sure the disposed class node does
            // not add a new child node.
            Assert.AreEqual(0, testClassNode.Nodes.Count);
            MockClass  c          = MockClass.CreateMockClassWithoutAnyAttributes();
            MockMethod mockMethod = new MockMethod(c, "Method");
            TestMember testMethod = new TestMember(mockMethod);

            testClass.Members.Add(testMethod);

            Assert.AreEqual(0, testClassNode.Nodes.Count);
        }
Ejemplo n.º 10
0
        public void ClassOccursBeforeNamespaceOnInitialLoad()
        {
            MockCSharpProject project = new MockCSharpProject();

            project.Name = "TestProject";
            ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project);

            nunitFrameworkReferenceItem.Include = "NUnit.Framework";
            ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem);
            List <IProject> projects = new List <IProject>();

            projects.Add(project);

            // Add a test class with a TestFixture attributes.
            TestClass testClass = CreateTestClass("MyTests.MyTestFixture");

            projectContent.Classes.Add(testClass.Class);

            // Add a second class with no namespace.
            testClass = CreateTestClass("AppleTestFixture");
            projectContent.Classes.Add(testClass.Class);

            // Add another class that exists in a namespace inside
            // MyTests.
            testClass = CreateTestClass("MyTests.ZebraTests.AddZebra");
            projectContent.Classes.Add(testClass.Class);

            // Load the project into the tree.
            treeView.Clear();
            treeView.AddProject(project);
            projectNode = (TestProjectTreeNode)treeView.Nodes[0];
            projectNode.PerformInitialization();

            ExtTreeNode treeNode = (ExtTreeNode)projectNode.LastNode;

            treeNode.PerformInitialization();

            // Get the class node without a root namespace and
            // the my tests namespace node.
            TestClassTreeNode     appleTestFixtureNode = projectNode.FirstNode as TestClassTreeNode;
            TestNamespaceTreeNode myTestsNamespaceNode = projectNode.LastNode as TestNamespaceTreeNode;

            // Get the zebra namespace tree node.
            TestNamespaceTreeNode zebraTestsNamespaceNode = treeNode.LastNode as TestNamespaceTreeNode;

            Assert.IsNotNull(appleTestFixtureNode);
            Assert.AreEqual(appleTestFixtureNode.Text, "AppleTestFixture");
            Assert.IsNotNull(myTestsNamespaceNode);
            Assert.AreEqual(myTestsNamespaceNode.Text, "MyTests");
            Assert.IsNotNull(zebraTestsNamespaceNode);
            Assert.AreEqual(zebraTestsNamespaceNode.Text, "ZebraTests");
        }
        public void RemoveClassAfterDisposingTestsNamespaceNode()
        {
            testsNamespaceNode.Dispose();
            testsNamespaceNode.Remove();

            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            // Make sure the tests namespace node child nodes are
            // unaffected when the test class is removed.
            Assert.AreEqual(1, testsNamespaceNode.Nodes.Count);
            projectNode.TestProject.TestClasses.Remove("RootNamespace.Tests.MyTestFixture");
            Assert.AreEqual(1, testsNamespaceNode.Nodes.Count);
        }
        public void TestMethodResultSetBackToNoneAfterReset()
        {
            TestMethodIgnored();

            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            projectNode.TestProject.ResetTestResults();

            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testFixtureNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)rootNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)testsNamespaceNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)rootNamespaceNode.ImageIndex);
        }
        public void TestMethodIgnored()
        {
            TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.NameExists");

            result.ResultType = TestResultType.Ignored;
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            projectNode.TestProject.UpdateTestResult(result);

            Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)testNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)testFixtureNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)testFixtureNode.SelectedImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestIgnored, (TestTreeViewImageListIndex)rootNamespaceNode.ImageIndex);
        }
        public void ChangeTestClassResultAfterDisposingProjectNode()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            projectNode.Dispose();

            // Make sure the project node image index is
            // unaffected when the test class result is changed.
            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)projectNode.ImageIndex);
            TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"];

            testClass.Result = TestResultType.Failure;
            Assert.AreEqual(TestTreeViewImageListIndex.TestNotRun, (TestTreeViewImageListIndex)projectNode.ImageIndex);
        }
        public void AddTestClassResultAfterDisposingTestsProjectNode()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            projectNode.Dispose();

            // Make sure the project node child nodes are
            // unaffected when the test class is removed.
            Assert.AreEqual(1, projectNode.Nodes.Count);
            TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"];

            projectNode.TestProject.TestClasses.Remove(testClass);
            Assert.AreEqual(1, projectNode.Nodes.Count);
        }
Ejemplo n.º 16
0
        public void TestMethodPasses()
        {
            TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.NameExists");

            result.IsSuccess = true;
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            projectNode.TestProject.UpdateTestResult(result);

            Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)testNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)testFixtureNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)testsNamespaceNode.ImageIndex);
            Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)rootNamespaceNode.ImageIndex);
        }
Ejemplo n.º 17
0
        public void Init()
        {
            // Create a project to display in the test tree view.
            MockCSharpProject project = new MockCSharpProject();

            project.Name = "TestProject";
            ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project);

            nunitFrameworkReferenceItem.Include = "NUnit.Framework";
            ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem);
            List <IProject> projects = new List <IProject>();

            projects.Add(project);

            // Add a test class with a TestFixture attributes.
            projectContent          = new MockProjectContent();
            projectContent.Language = LanguageProperties.None;
            TestClass testClass = CreateTestClass("MyTests.MyTestFixture");

            projectContent.Classes.Add(testClass.Class);

            // Add two methods to the test class only
            // one of which has test attributes.
            MockMethod testMethod = new MockMethod("NameExists");

            testMethod.Attributes.Add(new MockAttribute("Test"));
            testMethod.DeclaringType = testClass.Class;
            testClass.Class.Methods.Add(testMethod);

            // Init mock project content to be returned.
            treeView = new DummyParserServiceTestTreeView();
            treeView.ProjectContentForProject = projectContent;

            // Load the projects into the test tree view.
            treeView.AddProjects(projects);
            projectNode = (TestProjectTreeNode)treeView.Nodes[0];
            testProject = projectNode.TestProject;

            // Initialise the root node so the child nodes are created.
            projectNode.PerformInitialization();
            myTestsNamespaceNode = (TestNamespaceTreeNode)projectNode.FirstNode;

            // Initialise the first namespace node.
            myTestsNamespaceNode.PerformInitialization();
            testFixtureNode = (TestClassTreeNode)myTestsNamespaceNode.FirstNode;

            // Initialise the test method tree nodes.
            testFixtureNode.PerformInitialization();
        }
        public void RemoveTestClassResultAfterDisposingTestsProjectNode()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            projectNode.Dispose();

            // Make sure the project node child nodes are
            // unaffected when the test class is removed.
            Assert.AreEqual(1, projectNode.Nodes.Count);
            MockClass mockClass = new MockClass(projectContent, "MyNewTestClass");
            TestClass testClass = new TestClass(mockClass, testFrameworks);

            projectNode.TestProject.TestClasses.Add(testClass);
            Assert.AreEqual(1, projectNode.Nodes.Count);
        }
        public void ClassNodeAddedAfterProjectNodeExpanded()
        {
            // Expand the project node.
            TestProjectTreeNode projectNode = (TestProjectTreeNode)pad.TestTreeView.Nodes[0];

            projectNode.Expanding();

            // Add a new class to a non-empty namespace so it gets
            // added to a new namespace node.
            MockClass mockClass = new MockClass("RootNamespace.MyTestFixture");
            TestClass testClass = new TestClass(mockClass, testFrameworks);

            projectNode.TestProject.TestClasses.Add(testClass);

            Assert.AreEqual(1, projectNode.Nodes.Count,
                            "Project node should have one child node.");
        }
        public void EmptyNamespaceNodesRemoved()
        {
            // Expand the project node.
            TestProjectTreeNode projectNode = (TestProjectTreeNode)pad.TestTreeView.Nodes[0];

            projectNode.Expanding();

            // Add a new class to a non-empty namespace so it gets
            // added to a new namespace node.
            MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture");
            TestClass testClass = new TestClass(mockClass, testFrameworks);

            projectNode.TestProject.TestClasses.Add(testClass);

            // Expand RootNamespace tree node.
            TestNamespaceTreeNode rootNamespaceNode = (TestNamespaceTreeNode)projectNode.Nodes[0];

            rootNamespaceNode.Expanding();

            // Expand the Tests namespace tree node.
            TestNamespaceTreeNode testsNamespaceNode = (TestNamespaceTreeNode)rootNamespaceNode.Nodes[0];

            testsNamespaceNode.Expanding();

            // Get the test class node.
            TestClassTreeNode classNode = (TestClassTreeNode)testsNamespaceNode.Nodes[0];

            // Remove the test class from the test project.
            projectNode.TestProject.TestClasses.Remove(testClass);

            Assert.AreEqual(0, projectNode.Nodes.Count,
                            "Namespace nodes should have been removed from project node.");

            // Make sure the two namespace nodes are properly disposed.
            Assert.IsTrue(testsNamespaceNode.IsDisposed);
            Assert.IsTrue(rootNamespaceNode.IsDisposed);

            // Make sure the test class node has been disposed.
            Assert.IsTrue(classNode.IsDisposed);

            // Make sure the namespace node Dispose method removes
            // the TestProject.TestClasses.TestClassAdded event handler.
            Assert.AreEqual(0, testsNamespaceNode.Nodes.Count);
            projectNode.TestProject.TestClasses.Add(testClass);
            Assert.AreEqual(0, testsNamespaceNode.Nodes.Count);
        }
        public void TreeNodeContextMenuMatches()
        {
            using (DerivedTestTreeView treeView = new DerivedTestTreeView()) {
                ContextMenuStrip menuStrip = new ContextMenuStrip();
                treeView.ContextMenuStrip = menuStrip;

                // Add a root node to the tree.
                TestProject         project = new TestProject(new MockCSharpProject(), new MockProjectContent(), new MockTestFrameworksWithNUnitFrameworkSupport());
                TestProjectTreeNode node    = new TestProjectTreeNode(project);
                node.AddTo(treeView);

                // Select the tree node.
                treeView.SelectedNode = node;

                // Call the treeView's OnBeforeSelect so the context menu
                // is connected to the tree node.
                treeView.CallOnBeforeSelect(new TreeViewCancelEventArgs(node, false, TreeViewAction.ByMouse));

                // Context menu strip on tree node should match
                // the tree view's context menu strip.
                Assert.IsTrue(Object.ReferenceEquals(menuStrip, node.ContextMenuStrip));
            }
        }
        public void ClassRemoved()
        {
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;
            TestClass           testClass   = projectNode.TestProject.TestClasses["RootNamespace.Tests.MyTestFixture"];
            TestMemberTreeNode  methodNode  = (TestMemberTreeNode)testFixtureNode.Nodes[0];

            testFixtureNode.Expanding();

            // Sanity check - test fixture node should have one method node.
            Assert.AreEqual(1, testFixtureNode.Nodes.Count);

            projectNode.TestProject.TestClasses.Remove(testClass);

            // Method node should be disposed when parent class
            // node is disposed.
            Assert.IsTrue(methodNode.IsDisposed);

            // Make sure the TestClass.Dispose call removes all
            // event handlers.
            testClass.TestMembers.RemoveAt(0);

            Assert.AreEqual(1, testFixtureNode.Nodes.Count,
                            "Should still have one child node.");
        }
        public void RemoveClassWithProjectNodeHavingNonClassNodeChildren()
        {
            // Locate the class we are going to remove.
            TestProjectTreeNode projectNode = (TestProjectTreeNode)rootNode;

            projectNode.Nodes.Insert(0, new ExtTreeNode());
            TestClass testClass = projectNode.TestProject.TestClasses["MyTestFixture"];

            projectNode.TestProject.TestClasses.Remove(testClass);

            ExtTreeNode testClassNode = null;

            foreach (ExtTreeNode node in rootNode.Nodes)
            {
                if (node.Text == "MyTestFixture")
                {
                    testClassNode = node;
                    break;
                }
            }

            Assert.IsNull(testClassNode);
            Assert.AreEqual(1, projectNode.Nodes.Count);
        }
Ejemplo n.º 24
0
        public void TreeViewHasOneRootProjectNodeCalledMyProject()
        {
            TestProjectTreeNode node = treeView.Nodes[0] as TestProjectTreeNode;

            Assert.AreEqual("MyProject", node.Text);
        }