Browse Source

Fixed SD2-1219. New namespace, class and method tree nodes added to the Unit Tests tree are now sorted.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2170 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
bb4814b719
  1. 1
      src/AddIns/Misc/UnitTesting/Src/TestClassTreeNode.cs
  2. 9
      src/AddIns/Misc/UnitTesting/Src/TestNamespaceTreeNode.cs
  3. 5
      src/AddIns/Misc/UnitTesting/Src/TestProjectTreeNode.cs
  4. 10
      src/AddIns/Misc/UnitTesting/Src/TestTreeNode.cs
  5. 256
      src/AddIns/Misc/UnitTesting/Test/Tree/TreeNodeSortingTestFixture.cs
  6. 1
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj

1
src/AddIns/Misc/UnitTesting/Src/TestClassTreeNode.cs

@ -83,6 +83,7 @@ namespace ICSharpCode.UnitTesting @@ -83,6 +83,7 @@ namespace ICSharpCode.UnitTesting
void TestMethodAdded(object source, TestMethodEventArgs e)
{
AddTestMethodTreeNode(e.TestMethod);
SortChildNodes();
}
/// <summary>

9
src/AddIns/Misc/UnitTesting/Src/TestNamespaceTreeNode.cs

@ -142,6 +142,9 @@ namespace ICSharpCode.UnitTesting @@ -142,6 +142,9 @@ namespace ICSharpCode.UnitTesting
TestClassTreeNode classNode = new TestClassTreeNode(TestProject, c);
classNode.AddTo(this);
}
// Sort the nodes.
SortChildNodes();
}
/// <summary>
@ -265,6 +268,9 @@ namespace ICSharpCode.UnitTesting @@ -265,6 +268,9 @@ namespace ICSharpCode.UnitTesting
// 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);
@ -272,6 +278,9 @@ namespace ICSharpCode.UnitTesting @@ -272,6 +278,9 @@ namespace ICSharpCode.UnitTesting
// Add a new namespace node.
TestNamespaceTreeNode node = new TestNamespaceTreeNode(TestProject, fullNamespace, childNamespace);
node.AddTo(this);
// Sort the nodes.
SortChildNodes();
}
}
}

5
src/AddIns/Misc/UnitTesting/Src/TestProjectTreeNode.cs

@ -53,6 +53,9 @@ namespace ICSharpCode.UnitTesting @@ -53,6 +53,9 @@ namespace ICSharpCode.UnitTesting
foreach (TestClass c in TestProject.GetTestClasses(String.Empty)) {
AddClassNode(c);
}
// Sort the nodes.
SortChildNodes();
}
/// <summary>
@ -72,12 +75,14 @@ namespace ICSharpCode.UnitTesting @@ -72,12 +75,14 @@ namespace ICSharpCode.UnitTesting
{
if (e.TestClass.Namespace == String.Empty) {
AddClassNode(e.TestClass);
SortChildNodes();
} else if (isInitialized) {
// Check that we have a namespace node for this class.
if (!NamespaceNodeExists(e.TestClass.RootNamespace)) {
// Add a new namespace node.
TestNamespaceTreeNode node = new TestNamespaceTreeNode(TestProject, e.TestClass.RootNamespace);
node.AddTo(this);
SortChildNodes();
}
}
}

10
src/AddIns/Misc/UnitTesting/Src/TestTreeNode.cs

@ -92,5 +92,15 @@ namespace ICSharpCode.UnitTesting @@ -92,5 +92,15 @@ namespace ICSharpCode.UnitTesting
}
return false;
}
/// <summary>
/// Sorts the immediate child nodes of this node. The sort
/// is not done recursively.
/// </summary>
protected void SortChildNodes()
{
ExtTreeView treeView = (ExtTreeView)TreeView;
treeView.SortNodes(Nodes, false);
}
}
}

256
src/AddIns/Misc/UnitTesting/Test/Tree/TreeNodeSortingTestFixture.cs

@ -0,0 +1,256 @@ @@ -0,0 +1,256 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Tree
{
/// <summary>
/// Test that when a new class is added to the set of test classes
/// currently being displayed in the tree the nodes are sorted
/// correctly afterwards. We also test that the order of the
/// tree nodes is correct after adding new methods.
/// </summary>
[TestFixture]
public class TreeNodeSortingTestFixture
{
DummyParserServiceTestTreeView treeView;
TestProjectTreeNode projectNode;
TestNamespaceTreeNode myTestsNamespaceNode;
TestClassTreeNode testFixtureNode;
MockProjectContent projectContent;
TestProject testProject;
[SetUp]
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();
}
[TearDown]
public void TearDown()
{
if (treeView != null) {
treeView.Dispose();
}
}
/// <summary>
/// Add a class that exists in a namespace that
/// should be inserted into the tree before the current
/// namespace node.
/// </summary>
[Test]
public void AddClassInNewNamespace()
{
// Create the new test class.
TestClass testClass = CreateTestClass("Apple.MyTestFixture");
// Add the class to the existing classes.
testProject.TestClasses.Add(testClass);
// Check the namespace node is inserted before the
// existing namespace node.
TestNamespaceTreeNode namespaceTreeNode = (TestNamespaceTreeNode)projectNode.FirstNode;
Assert.AreEqual("Apple", namespaceTreeNode.Text);
}
/// <summary>
/// Here we add a class with no root namespace but with a name
/// that alphabetically would occur before the existing
/// namespace tree node. NUnit does not treat namespace
/// nodes any different to test class nodes so have the
/// same behaviour. This means a class node could appear
/// before the namespace node in the tree.
/// </summary>
[Test]
public void AddClassWithNoRootNamespace()
{
TestClass testClass = CreateTestClass("AppleTest");
testProject.TestClasses.Add(testClass);
TestClassTreeNode classNode = projectNode.FirstNode as TestClassTreeNode;
Assert.AreEqual(classNode.Text, "AppleTest");
}
/// <summary>
/// Make sure that if we have a class with no root namespace
/// and it is alphabetically before an existing namespace
/// then it is added in the tree before that namespace.
/// We also test that the same thing occurs with a namespace
/// tree node.
/// </summary>
[Test]
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");
}
/// <summary>
/// Here we add a new class that exists in a namespace that
/// did not previously exist and we make sure the tree node is
/// inserted before any other tree node.
/// </summary>
[Test]
public void NewNamespaceNode()
{
// Add a class in a new namespace.
TestClass testClass = CreateTestClass("MyTests.AppleTests.IsEqual");
testProject.TestClasses.Add(testClass);
TestTreeNode insertedNode = myTestsNamespaceNode.FirstNode as TestTreeNode;
Assert.AreEqual("AppleTests", insertedNode.Text);
}
/// <summary>
/// Here we add a new class that exists in a namespace that
/// already exists and we make sure the new tree node is
/// inserted before any other tree node.
/// </summary>
[Test]
public void AddNewClassToExistingNamespace()
{
// Add a class in the tests namespace.
TestClass testClass = CreateTestClass("MyTests.AppleTestFixture");
testProject.TestClasses.Add(testClass);
TestTreeNode insertedNode = myTestsNamespaceNode.FirstNode as TestTreeNode;
Assert.AreEqual("AppleTestFixture", insertedNode.Text);
}
/// <summary>
/// Tests that new methods are inserted into the tree in the
/// correct alphabetical order.
/// </summary>
[Test]
public void NewClassMethodAdded()
{
MockClass c = (MockClass)testFixtureNode.Class;
MockMethod method = new MockMethod("Apple");
method.Attributes.Add(new MockAttribute("Test"));
method.DeclaringType = c;
c.SetCompoundClass(c);
c.Methods.Add(method);
// Add the test method to the class.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
newUnit.Classes.Add(c);
testProject.UpdateParseInfo(null, newUnit);
// Check that the new tree node is inserted before the
// existing method node.
TestTreeNode insertedNode = testFixtureNode.FirstNode as TestTreeNode;
Assert.AreEqual("Apple", insertedNode.Text);
}
/// <summary>
/// Creates a new class with the fully qualified name.
/// </summary>
TestClass CreateTestClass(string name)
{
MockClass c = new MockClass(name);
c.Attributes.Add(new MockAttribute("TestFixture"));
c.ProjectContent = projectContent;
return new TestClass(c);
}
}
}

1
src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj

@ -57,6 +57,7 @@ @@ -57,6 +57,7 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="NamespaceFilterTests.cs" />
<Compile Include="TestableConditionTests.cs" />
<Compile Include="Tree\TreeNodeSortingTestFixture.cs" />
<Compile Include="Tree\OpenUnitTestsPadWithSolutionOpenTestFixture.cs" />
<Compile Include="Utils\DerivedUnitTestsPad.cs" />
<Compile Include="Utils\MockTestCase.cs" />

Loading…
Cancel
Save