Browse Source

Showing multiple times nested test classes in the test pad.

pull/23/head
Tomasz Tretkowski 15 years ago
parent
commit
a6df882523
  1. 24
      src/AddIns/Analysis/UnitTesting/Src/TestClass.cs
  2. 25
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassInTestFixtureTests.cs

24
src/AddIns/Analysis/UnitTesting/Src/TestClass.cs

@ -90,11 +90,16 @@ namespace ICSharpCode.UnitTesting @@ -90,11 +90,16 @@ namespace ICSharpCode.UnitTesting
/// Gets the name of the class.
/// </summary>
public string Name {
get {
if (c.DeclaringType != null) {
return String.Concat(c.DeclaringType.Name, "+", c.Name);
get
{
var currentClass = c;
var name = c.Name;
while(currentClass.DeclaringType != null)
{
name = String.Concat(currentClass.DeclaringType.Name, "+", name);
currentClass = currentClass.DeclaringType;
}
return c.Name;
return name;
}
}
@ -109,11 +114,12 @@ namespace ICSharpCode.UnitTesting @@ -109,11 +114,12 @@ namespace ICSharpCode.UnitTesting
/// Gets the namespace of this class.
/// </summary>
public string Namespace {
get {
if (c.DeclaringType != null) {
return c.DeclaringType.Namespace;
}
return c.Namespace;
get
{
var currentClass = c;
while (currentClass.DeclaringType != null)
currentClass = currentClass.DeclaringType;
return currentClass.Namespace;
}
}

25
src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassInTestFixtureTests.cs

@ -3,7 +3,6 @@ @@ -3,7 +3,6 @@
using System;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
@ -25,8 +24,7 @@ namespace UnitTesting.Tests.Project @@ -25,8 +24,7 @@ namespace UnitTesting.Tests.Project
/// }
/// }
/// }
///
/// In this case the FooBar test is identified via: "A+InnerATest.FooBar".
///
/// </summary>
[TestFixture]
public class InnerClassInTestFixtureTests : InnerClassTestFixtureBase
@ -71,11 +69,28 @@ namespace UnitTesting.Tests.Project @@ -71,11 +69,28 @@ namespace UnitTesting.Tests.Project
AssertTestResultContainsClass(classNestedInInnerClass);
}
[Test]
public void TestClassNameShouldBeDotNetNameOfTheDoubleNestedClass()
{
Assert.AreEqual("A+InnerATest+InnerTestLevel2", TestClassRelatedTo(classNestedInInnerClass).Name);
}
[Test]
public void TestClassNamespaceShouldBeValid()
{
Assert.AreEqual("MyTests", TestClassRelatedTo(classNestedInInnerClass).Namespace);
}
void AssertTestResultContainsClass(IClass clazz)
{
var count = testProject.TestClasses.Count(c => c.Class == clazz);
if (count != 1)
var testClazz = TestClassRelatedTo(clazz);
if (testClazz == null)
throw new AssertionException(string.Format("Test result should contain class {0}.", clazz.FullyQualifiedName));
}
TestClass TestClassRelatedTo(IClass clazz)
{
return testProject.TestClasses.SingleOrDefault(c => c.Class == clazz);
}
}
}

Loading…
Cancel
Save