public void AddNewClassNodeWhenTestClassPassed()
        {
            testClass.Result = TestResultType.Success;
            TestClassTreeNode node = new TestClassTreeNode(testProject, testClass);

            Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex);
        }
Esempio n. 2
0
        public void AddClassWithNoRootNamespace()
        {
            TestClass testClass = CreateTestClass("AppleTest");

            testProject.TestClasses.Add(testClass);

            TestClassTreeNode classNode = projectNode.FirstNode as TestClassTreeNode;

            Assert.AreEqual(classNode.Text, "AppleTest");
        }
Esempio n. 3
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 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);
        }
Esempio n. 5
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 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);
        }
Esempio n. 7
0
 private void RefreshTree()
 {
     // update..
     this.treeProject.BeginUpdate();
     try
     {
         this.treeProject.Nodes.Clear();
         foreach (TestClass c in BakingController.Current.ActiveProject.Classes)
         {
             var node = new TestClassTreeNode(c);
             this.treeProject.Nodes.Add(node);
         }
     }
     finally
     {
         this.treeProject.EndUpdate();
     }
 }