/// <summary> /// A new test class has been added to the project so a new /// tree node is added if the class belongs to this namespace. /// </summary> void TestClassAdded(object source, TestClassEventArgs e) { if (e.TestClass.Namespace == fullNamespace) { // Add test class to our monitored test classes. testClasses.Add(e.TestClass); // Add a new tree node. TestClassTreeNode classNode = new TestClassTreeNode(TestProject, e.TestClass); classNode.AddTo(this); // Sort the nodes. SortChildNodes(); } else if (isInitialized && NamespaceStartsWith(e.TestClass.Namespace)) { // Check if there is a child namespace node for the class. string childNamespace = TestClass.GetChildNamespace(e.TestClass.Namespace, fullNamespace); if (!NamespaceNodeExists(childNamespace)) { // Add a new namespace node. TestNamespaceTreeNode node = new TestNamespaceTreeNode(TestProject, fullNamespace, childNamespace); node.AddTo(this); // Sort the nodes. SortChildNodes(); } } }
/// <summary> /// Removes the corresponding tree node that is a child of /// this project tree node if the class has no root namespace. /// </summary> void TestClassRemoved(object source, TestClassEventArgs e) { if (e.TestClass.Namespace == String.Empty) { foreach (ExtTreeNode node in Nodes) { TestClassTreeNode classNode = node as TestClassTreeNode; if (classNode != null && classNode.Text == e.TestClass.Name) { classNode.Remove(); classNode.Dispose(); break; } } } }
/// <summary> /// Adds the test class nodes for this namespace when the /// node is expanded. /// </summary> protected override void Initialize() { if (dummyNode != null) { Nodes.Clear(); } // Add class nodes for this namespace. foreach (TestClass c in testClasses) { TestClassTreeNode classNode = new TestClassTreeNode(TestProject, c); classNode.AddTo(this); } // Sort the nodes. SortChildNodes(); }
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(); }
/// <summary> /// A test class has been removed from the project so the /// corresponding tree node is removed if it belongs to this /// namespace. /// </summary> void TestClassRemoved(object source, TestClassEventArgs e) { if (e.TestClass.Namespace == fullNamespace) { // Remove test class from our monitored test classes. testClasses.Remove(e.TestClass); // Remove the corresponding tree node. foreach (ExtTreeNode node in Nodes) { TestClassTreeNode classNode = node as TestClassTreeNode; if (classNode != null && classNode.Text == e.TestClass.Name) { classNode.Remove(); classNode.Dispose(); break; } } // Remove this namespace node if there are no more child nodes. RemoveIfEmpty(); } }
/// <summary> /// Adds a new TestClassTreeNode to this node. /// </summary> void AddClassNode(TestClass c) { TestClassTreeNode node = new TestClassTreeNode(TestProject, c); node.AddTo(this); }
public void AddNewClassNodeWhenTestClassPassed() { testClass.Result = TestResultType.Success; TestClassTreeNode node = new TestClassTreeNode(testProject, testClass); Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex); }