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
/// Gets the name of the class. /// Gets the name of the class.
/// </summary> /// </summary>
public string Name { public string Name {
get { get
if (c.DeclaringType != null) { {
return String.Concat(c.DeclaringType.Name, "+", c.Name); 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
/// Gets the namespace of this class. /// Gets the namespace of this class.
/// </summary> /// </summary>
public string Namespace { public string Namespace {
get { get
if (c.DeclaringType != null) { {
return c.DeclaringType.Namespace; var currentClass = c;
} while (currentClass.DeclaringType != null)
return c.Namespace; currentClass = currentClass.DeclaringType;
return currentClass.Namespace;
} }
} }

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

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