Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2321 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
13 changed files with 518 additions and 11 deletions
After Width: | Height: | Size: 759 B |
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
// <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 ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.UnitTesting |
||||
{ |
||||
/// <summary>
|
||||
/// All Tests root tree node that is added to the test tree when the
|
||||
/// solution has multiple test projects.
|
||||
/// </summary>
|
||||
public class AllTestsTreeNode : TestTreeNode |
||||
{ |
||||
public AllTestsTreeNode() |
||||
: base(null, StringParser.Parse("${res:ICSharpCode.UnitTesting.AllTestsTreeNode.Text}")) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Raised when the all tests tree node is disposed.
|
||||
/// </summary>
|
||||
public event EventHandler Disposed; |
||||
|
||||
/// <summary>
|
||||
/// Disposes this tree node.
|
||||
/// </summary>
|
||||
public override void Dispose() |
||||
{ |
||||
base.Dispose(); |
||||
if (Disposed != null) { |
||||
Disposed(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new project node as a child of the All Tests node.
|
||||
/// </summary>
|
||||
public void AddProjectNode(TestProjectTreeNode node) |
||||
{ |
||||
node.AddTo(this); |
||||
node.ImageIndexChanged += TestProjectTreeNodeImageIndexChanged; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Removes the project node.
|
||||
/// </summary>
|
||||
public void RemoveProjectNode(TestProjectTreeNode node) |
||||
{ |
||||
if (Nodes.Contains(node)) { |
||||
node.ImageIndexChanged -= TestProjectTreeNodeImageIndexChanged; |
||||
node.Remove(); |
||||
} |
||||
} |
||||
|
||||
void TestProjectTreeNodeImageIndexChanged(object source, EventArgs e) |
||||
{ |
||||
UpdateImageListIndex(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the All Tests image index based on the current image
|
||||
/// indexes of the child project tree nodes.
|
||||
/// </summary>
|
||||
void UpdateImageListIndex() |
||||
{ |
||||
int ignored = 0; |
||||
int failed = 0; |
||||
int passed = 0; |
||||
int notRun = 0; |
||||
int total = Nodes.Count; |
||||
|
||||
foreach (TestProjectTreeNode projectNode in Nodes) { |
||||
switch (projectNode.ImageIndex) { |
||||
case (int)TestTreeViewImageListIndex.TestFailed: |
||||
failed++; |
||||
break; |
||||
case (int)TestTreeViewImageListIndex.TestPassed: |
||||
passed++; |
||||
break; |
||||
case (int)TestTreeViewImageListIndex.TestIgnored: |
||||
ignored++; |
||||
break; |
||||
default: // Not run.
|
||||
notRun++; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
// Update the image index based on the test project results.
|
||||
if (failed > 0) { |
||||
UpdateImageListIndex(TestResultType.Failure); |
||||
} else if (ignored > 0) { |
||||
UpdateImageListIndex(TestResultType.Ignored); |
||||
} else if (passed > 0 && notRun == 0) { |
||||
UpdateImageListIndex(TestResultType.Success); |
||||
} else { |
||||
UpdateImageListIndex(TestResultType.None); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,210 @@
@@ -0,0 +1,210 @@
|
||||
// <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 ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace UnitTesting.Tests.Tree |
||||
{ |
||||
/// <summary>
|
||||
/// When there are multiple test projects in a solution then the
|
||||
/// test tree should have an All Tests root node.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class MultipleTestProjectsTestFixture |
||||
{ |
||||
DummyParserServiceTestTreeView treeView; |
||||
MockCSharpProject firstProject; |
||||
MockCSharpProject secondProject; |
||||
AllTestsTreeNode allTestsTreeNode; |
||||
TestProject firstTestProject; |
||||
TestProject secondTestProject; |
||||
Solution solution; |
||||
|
||||
[SetUp] |
||||
public void SetUp() |
||||
{ |
||||
treeView = new DummyParserServiceTestTreeView(); |
||||
|
||||
// Create a solution with two test projects.
|
||||
solution = new Solution(); |
||||
|
||||
// Create the first test project.
|
||||
firstProject = new MockCSharpProject(solution); |
||||
firstProject.Name = "FirstTestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(firstProject); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
ProjectService.AddProjectItem(firstProject, nunitFrameworkReferenceItem); |
||||
|
||||
// Create the second test project.
|
||||
secondProject = new MockCSharpProject(solution); |
||||
secondProject.Name = "SecondTestProject"; |
||||
nunitFrameworkReferenceItem = new ReferenceProjectItem(secondProject); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
ProjectService.AddProjectItem(secondProject, nunitFrameworkReferenceItem); |
||||
|
||||
// Add the projects to the solution.
|
||||
solution.Folders.Add(firstProject); |
||||
solution.Folders.Add(secondProject); |
||||
|
||||
// Create a dummy project content so the projects will be added
|
||||
// to the tree.
|
||||
treeView.ProjectContentForProject = new MockProjectContent(); |
||||
|
||||
// Add the solution to the tree.
|
||||
treeView.AddSolution(solution); |
||||
|
||||
allTestsTreeNode = treeView.Nodes[0] as AllTestsTreeNode; |
||||
firstTestProject = treeView.GetTestProject(firstProject); |
||||
secondTestProject = treeView.GetTestProject(secondProject); |
||||
} |
||||
|
||||
[TearDown] |
||||
public void TearDown() |
||||
{ |
||||
treeView.Dispose(); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneAllTestsRootNode() |
||||
{ |
||||
Assert.AreEqual(1, treeView.Nodes.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void RootNodeIsAllTestsNode() |
||||
{ |
||||
Assert.IsNotNull(allTestsTreeNode); |
||||
} |
||||
|
||||
[Test] |
||||
public void AllTestsNodeText() |
||||
{ |
||||
Assert.AreEqual(StringParser.Parse("${res:ICSharpCode.UnitTesting.AllTestsTreeNode.Text}"), treeView.Nodes[0].Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProjectsAfterClear() |
||||
{ |
||||
treeView.Clear(); |
||||
Assert.AreEqual(0, treeView.GetProjects().Length); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the All Tests node is removed when only one
|
||||
/// project remains.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ProjectRemoved() |
||||
{ |
||||
treeView.RemoveProject(firstProject); |
||||
|
||||
Assert.AreEqual(1, treeView.GetProjects().Length); |
||||
Assert.IsInstanceOfType(typeof(TestProjectTreeNode), treeView.Nodes[0]); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that the all test node has the correct image index.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void ProjectIgnoredTestResult() |
||||
{ |
||||
TestClass c = new TestClass(new MockClass("Tests.TestFixture")); |
||||
firstTestProject.TestClasses.Add(c); |
||||
c.Result = TestResultType.Ignored; |
||||
|
||||
Assert.AreEqual((int)TestTreeViewImageListIndex.TestIgnored, allTestsTreeNode.ImageIndex); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests that a removed project does not affect the image index of the
|
||||
/// All Tests root node.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void IgnoredTestResultAfterProjectRemoved() |
||||
{ |
||||
// Add an extra project so when we remove one the All Tests node
|
||||
// is not removed.
|
||||
MockCSharpProject project = new MockCSharpProject(solution); |
||||
project.Name = "ThirdTestProject"; |
||||
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); |
||||
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; |
||||
ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem); |
||||
|
||||
// Add the project into a dummy project node.
|
||||
TestProject testProject = new TestProject(project, new MockProjectContent()); |
||||
DerivedTestProjectTreeNode projectNode = new DerivedTestProjectTreeNode(testProject); |
||||
allTestsTreeNode.AddProjectNode(projectNode); |
||||
|
||||
// Remove an existing project.
|
||||
treeView.RemoveProject(project); |
||||
|
||||
// Modify the image index for the removed tree node.
|
||||
projectNode.CallUpdateImageListIndex(TestResultType.Ignored); |
||||
|
||||
// Image index of the all tests node should be unchanged.
|
||||
Assert.AreEqual((int)TestTreeViewImageListIndex.TestNotRun, allTestsTreeNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectFailedTestResult() |
||||
{ |
||||
TestClass c = new TestClass(new MockClass("Tests.TestFixture")); |
||||
firstTestProject.TestClasses.Add(c); |
||||
c.Result = TestResultType.Failure; |
||||
|
||||
Assert.AreEqual((int)TestTreeViewImageListIndex.TestFailed, allTestsTreeNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProjectPassedTestResult() |
||||
{ |
||||
TestClass c = new TestClass(new MockClass("Tests.TestFixture")); |
||||
firstTestProject.TestClasses.Add(c); |
||||
c.Result = TestResultType.Success; |
||||
|
||||
Assert.AreEqual((int)TestTreeViewImageListIndex.TestNotRun, allTestsTreeNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void AllTestsNodeImageIndexReset() |
||||
{ |
||||
// Make one of the test projects pass so the all tests
|
||||
// node's image index is changed.
|
||||
ProjectPassedTestResult(); |
||||
|
||||
// Set the test class result back to not run.
|
||||
firstTestProject.TestClasses[0].Result = TestResultType.None; |
||||
|
||||
Assert.AreEqual((int)TestTreeViewImageListIndex.TestNotRun, allTestsTreeNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void AllTestProjectsPassed() |
||||
{ |
||||
TestClass c = new TestClass(new MockClass("Tests.TestFixture")); |
||||
firstTestProject.TestClasses.Add(c); |
||||
c.Result = TestResultType.Success; |
||||
|
||||
c = new TestClass(new MockClass("Tests.TestFixture")); |
||||
secondTestProject.TestClasses.Add(c); |
||||
c.Result = TestResultType.Success; |
||||
|
||||
Assert.AreEqual((int)TestTreeViewImageListIndex.TestPassed, allTestsTreeNode.ImageIndex); |
||||
} |
||||
|
||||
[Test] |
||||
public void CanClearSelection() |
||||
{ |
||||
Assert.IsFalse(treeView.CanClearSelection); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// <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 ICSharpCode.UnitTesting; |
||||
|
||||
namespace UnitTesting.Tests.Utils |
||||
{ |
||||
/// <summary>
|
||||
/// Derived version of the TestProjectTreeNode class that
|
||||
/// allows us to call the UpdateImageListIndex method directly.
|
||||
/// </summary>
|
||||
public class DerivedTestProjectTreeNode : TestProjectTreeNode |
||||
{ |
||||
public DerivedTestProjectTreeNode(TestProject testProject) |
||||
: base(testProject) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Calls the base class's UpdateImageListIndex method.
|
||||
/// </summary>
|
||||
public void CallUpdateImageListIndex(TestResultType result) |
||||
{ |
||||
base.UpdateImageListIndex(result); |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Loading…
Reference in new issue