From a6df882523825f7599fa50e1ba54661f0310c865 Mon Sep 17 00:00:00 2001 From: Tomasz Tretkowski Date: Tue, 18 Oct 2011 22:32:28 +0200 Subject: [PATCH] Showing multiple times nested test classes in the test pad. --- .../Analysis/UnitTesting/Src/TestClass.cs | 24 +++++++++++------- .../Project/InnerClassInTestFixtureTests.cs | 25 +++++++++++++++---- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs b/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs index 667042fd9e..2e63b14bde 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs @@ -90,11 +90,16 @@ namespace ICSharpCode.UnitTesting /// Gets the name of the class. /// 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 /// Gets the namespace of this class. /// 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; } } diff --git a/src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassInTestFixtureTests.cs b/src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassInTestFixtureTests.cs index 5a3b2e621d..9820664348 100644 --- a/src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassInTestFixtureTests.cs +++ b/src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassInTestFixtureTests.cs @@ -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 /// } /// } /// } - /// - /// In this case the FooBar test is identified via: "A+InnerATest.FooBar". + /// /// [TestFixture] public class InnerClassInTestFixtureTests : InnerClassTestFixtureBase @@ -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); + } } }