Browse Source

Inner classes with a TestFixture attribute are now shown in the Unit Tests and can be tested individually.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3608 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 18 years ago
parent
commit
a7e361e83b
  1. 56
      src/AddIns/Misc/UnitTesting/Src/RemovedClasses.cs
  2. 26
      src/AddIns/Misc/UnitTesting/Src/TestClass.cs
  3. 2
      src/AddIns/Misc/UnitTesting/Src/TestClassCollection.cs
  4. 49
      src/AddIns/Misc/UnitTesting/Src/TestProject.cs
  5. 2
      src/AddIns/Misc/UnitTesting/Src/UnitTestApplicationStartHelper.cs
  6. 73
      src/AddIns/Misc/UnitTesting/Test/Project/InnerClassMethodRenamedTestFixture.cs
  7. 69
      src/AddIns/Misc/UnitTesting/Test/Project/InnerClassNameChangesTestFixture.cs
  8. 79
      src/AddIns/Misc/UnitTesting/Test/Project/InnerClassTestFixture.cs
  9. 61
      src/AddIns/Misc/UnitTesting/Test/Project/InnerClassTestFixtureAttributeRemovedTestFixture.cs
  10. 70
      src/AddIns/Misc/UnitTesting/Test/Project/InnerClassTestFixtureBase.cs
  11. 111
      src/AddIns/Misc/UnitTesting/Test/Project/RemovedClassesTestFixture.cs
  12. 12
      src/AddIns/Misc/UnitTesting/Test/UnitTestCommandLineTests.cs
  13. 6
      src/AddIns/Misc/UnitTesting/Test/UnitTesting.Tests.csproj
  14. 91
      src/AddIns/Misc/UnitTesting/Test/Utils/MockClass.cs
  15. 1
      src/AddIns/Misc/UnitTesting/UnitTesting.csproj

56
src/AddIns/Misc/UnitTesting/Src/RemovedClasses.cs

@ -0,0 +1,56 @@
// <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 ICSharpCode.SharpDevelop.Dom;
namespace ICSharpCode.UnitTesting
{
/// <summary>
/// Used to determine which classes have been removed by the user in the project.
/// </summary>
public class RemovedClasses
{
Dictionary<string, IClass> classDictionary = new Dictionary<string, IClass>();
public RemovedClasses()
{
}
public void Add(IList<IClass> classes)
{
foreach (IClass c in classes) {
classDictionary[c.DotNetName] = c;
foreach (IClass innerClass in c.InnerClasses) {
classDictionary[innerClass.DotNetName] = innerClass;
}
}
}
/// <summary>
///
/// </summary>
/// <param name="c"></param>
public void Remove(IClass c)
{
classDictionary.Remove(c.DotNetName);
foreach (IClass innerClass in c.InnerClasses) {
classDictionary.Remove(innerClass.DotNetName);
}
}
public IList<IClass> GetMissingClasses()
{
List<IClass> missingClasses = new List<IClass>();
foreach (IClass c in classDictionary.Values) {
missingClasses.Add(c);
}
return missingClasses;
}
}
}

26
src/AddIns/Misc/UnitTesting/Src/TestClass.cs

@ -37,9 +37,7 @@ namespace ICSharpCode.UnitTesting
/// Gets the underlying IClass for this test class. /// Gets the underlying IClass for this test class.
/// </summary> /// </summary>
public IClass Class { public IClass Class {
get { get { return c; }
return c;
}
} }
/// <summary> /// <summary>
@ -132,7 +130,10 @@ 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);
}
return c.Name; return c.Name;
} }
} }
@ -141,16 +142,17 @@ namespace ICSharpCode.UnitTesting
/// Gets the fully qualified name of the class. /// Gets the fully qualified name of the class.
/// </summary> /// </summary>
public string QualifiedName { public string QualifiedName {
get { get { return c.DotNetName; }
return c.FullyQualifiedName;
}
} }
/// <summary> /// <summary>
/// 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;
}
return c.Namespace; return c.Namespace;
} }
} }
@ -159,18 +161,14 @@ namespace ICSharpCode.UnitTesting
/// Gets the root namespace for this class. /// Gets the root namespace for this class.
/// </summary> /// </summary>
public string RootNamespace { public string RootNamespace {
get { get { return GetRootNamespace(c.Namespace); }
return GetRootNamespace(c.Namespace);
}
} }
/// <summary> /// <summary>
/// Gets the test result for this class. /// Gets the test result for this class.
/// </summary> /// </summary>
public TestResultType Result { public TestResultType Result {
get { get { return testResultType; }
return testResultType;
}
set { set {
TestResultType previousTestResultType = testResultType; TestResultType previousTestResultType = testResultType;
testResultType = value; testResultType = value;

2
src/AddIns/Misc/UnitTesting/Src/TestClassCollection.cs

@ -100,7 +100,7 @@ namespace ICSharpCode.UnitTesting
protected override string GetKeyForItem(TestClass item) protected override string GetKeyForItem(TestClass item)
{ {
return item.Class.FullyQualifiedName; return item.QualifiedName;
} }
protected override void InsertItem(int index, TestClass item) protected override void InsertItem(int index, TestClass item)

49
src/AddIns/Misc/UnitTesting/Src/TestProject.cs

@ -34,9 +34,7 @@ namespace ICSharpCode.UnitTesting
/// Returns the underlying project. /// Returns the underlying project.
/// </summary> /// </summary>
public IProject Project { public IProject Project {
get { get { return project; }
return project;
}
} }
/// <summary> /// <summary>
@ -114,9 +112,7 @@ namespace ICSharpCode.UnitTesting
/// Gets the project's name. /// Gets the project's name.
/// </summary> /// </summary>
public string Name { public string Name {
get { get { return project.Name; }
return project.Name;
}
} }
/// <summary> /// <summary>
@ -152,8 +148,7 @@ namespace ICSharpCode.UnitTesting
} }
/// <summary> /// <summary>
/// Updates the classes and methods based on the new parse /// Updates the classes and methods based on the new parse information.
/// information.
/// </summary> /// </summary>
/// <param name="oldUnit">The old compiliation unit /// <param name="oldUnit">The old compiliation unit
/// (ParseInformationEventArgs.ParseInformation.BestCompilationUnit as ICompilationUnit)</param> /// (ParseInformationEventArgs.ParseInformation.BestCompilationUnit as ICompilationUnit)</param>
@ -165,28 +160,25 @@ namespace ICSharpCode.UnitTesting
return; return;
} }
Dictionary<string, IClass> classDictionary = new Dictionary<string, IClass>(); RemovedClasses removedClasses = new RemovedClasses();
Dictionary<string, bool> wasUpdatedDictionary = new Dictionary<string, bool>();
if (oldUnit != null) { if (oldUnit != null) {
foreach (IClass c in oldUnit.Classes) { removedClasses.Add(oldUnit.Classes);
classDictionary[c.FullyQualifiedName] = c;
wasUpdatedDictionary[c.FullyQualifiedName] = false;
}
} }
if (newUnit != null) { if (newUnit != null) {
foreach (IClass c in newUnit.Classes) { foreach (IClass c in newUnit.Classes) {
UpdateTestClass(c); UpdateTestClass(c);
wasUpdatedDictionary[c.FullyQualifiedName] = true; foreach (IClass innerClass in c.InnerClasses) {
UpdateTestClass(innerClass);
removedClasses.Remove(innerClass);
}
removedClasses.Remove(c);
} }
} }
// Remove missing classes. // Remove missing classes.
foreach (KeyValuePair<string, bool> entry in wasUpdatedDictionary) { foreach (IClass c in removedClasses.GetMissingClasses()) {
if (!entry.Value) { TestClasses.Remove(c.DotNetName);
IClass c = classDictionary[entry.Key];
TestClasses.Remove(c.FullyQualifiedName);
}
} }
} }
@ -224,14 +216,14 @@ namespace ICSharpCode.UnitTesting
/// </summary> /// </summary>
void UpdateTestClass(IClass c) void UpdateTestClass(IClass c)
{ {
if (TestClasses.Contains(c.FullyQualifiedName)) { if (TestClasses.Contains(c.DotNetName)) {
if (TestClass.IsTestClass(c)) { if (TestClass.IsTestClass(c)) {
TestClass testClass = TestClasses[c.FullyQualifiedName]; TestClass testClass = TestClasses[c.DotNetName];
testClass.UpdateClass(c); testClass.UpdateClass(c);
} else { } else {
// TestFixture attribute has been removed so // TestFixture attribute has been removed so
// remove the class from the set of TestClasses. // remove the class from the set of TestClasses.
TestClasses.Remove(c.FullyQualifiedName); TestClasses.Remove(c.DotNetName);
} }
} else { } else {
// TestFixture attribute may have been recently added to // TestFixture attribute may have been recently added to
@ -239,7 +231,7 @@ namespace ICSharpCode.UnitTesting
// check if the class is actually a test class since // check if the class is actually a test class since
// AddNewTestClass does this anyway. // AddNewTestClass does this anyway.
AddNewTestClass(c); AddNewTestClass(c);
} }
} }
void GetTestClasses() void GetTestClasses()
@ -251,6 +243,13 @@ namespace ICSharpCode.UnitTesting
testClasses.Add(new TestClass(c)); testClasses.Add(new TestClass(c));
} }
} }
foreach (IClass innerClass in c.InnerClasses) {
if (TestClass.IsTestClass(innerClass)) {
if (!testClasses.Contains(innerClass.DotNetName)) {
testClasses.Add(new TestClass(innerClass));
}
}
}
} }
} }
@ -263,6 +262,6 @@ namespace ICSharpCode.UnitTesting
rootNamespaces.Add(rootNamespace); rootNamespaces.Add(rootNamespace);
} }
} }
} }
} }
} }

2
src/AddIns/Misc/UnitTesting/Src/UnitTestApplicationStartHelper.cs

@ -119,7 +119,7 @@ namespace ICSharpCode.UnitTesting
NamespaceFilter = namespaceFilter; NamespaceFilter = namespaceFilter;
} }
if (fixture != null) { if (fixture != null) {
Fixture = fixture.FullyQualifiedName; Fixture = fixture.DotNetName;
if (test != null) { if (test != null) {
Test = test.Name; Test = test.Name;
} }

73
src/AddIns/Misc/UnitTesting/Test/Project/InnerClassMethodRenamedTestFixture.cs

@ -0,0 +1,73 @@
// <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.SharpDevelop.Dom;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// Tests what happens when a test method is renamed inside an inner class.
/// </summary>
[TestFixture]
public class InnerClassMethodRemovedTestFixture : InnerClassTestFixtureBase
{
TestClass innerTestClass;
[SetUp]
public void Init()
{
base.InitBase();
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
oldUnit.Classes.Add(outerClass);
// Create new compilation unit with inner class that has its method renamed.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newOuterClass = new MockClass("MyTests.A");
newOuterClass.ProjectContent = projectContent;
projectContent.Classes.Add(newOuterClass);
newOuterClass.SetCompoundClass(newOuterClass);
newUnit.Classes.Add(newOuterClass);
// Create the inner test class.
MockClass newInnerClass = new MockClass("MyTests.A.InnerATest", "MyTests.A+InnerATest");
newInnerClass.Attributes.Add(new MockAttribute("TestFixture"));
newInnerClass.ProjectContent = projectContent;
newInnerClass.DeclaringType = outerClass; // Declaring type is outer class.
newInnerClass.SetCompoundClass(newInnerClass);
newOuterClass.InnerClasses.Add(newInnerClass);
MockMethod method = new MockMethod("FooBarRenamed");
method.Attributes.Add(new MockAttribute("Test"));
method.DeclaringType = newInnerClass;
newInnerClass.Methods.Add(method);
outerClass.InnerClasses.Add(newInnerClass);
// Update TestProject's parse info.
testProject.UpdateParseInfo(oldUnit, newUnit);
innerTestClass = testProject.TestClasses["MyTests.A+InnerATest"];
}
[Test]
public void NewTestMethodExists()
{
TestMethod method = innerTestClass.TestMethods[0];
Assert.AreEqual("FooBarRenamed", method.Name);
}
[Test]
public void OldTestMethodRemoved()
{
Assert.AreEqual(1, innerTestClass.TestMethods.Count);
}
}
}

69
src/AddIns/Misc/UnitTesting/Test/Project/InnerClassNameChangesTestFixture.cs

@ -0,0 +1,69 @@
// <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.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// Tests that the TestProject is correctly updated after the inner class name changes.
/// </summary>
[TestFixture]
public class InnerClassNameChangesTestFixture : InnerClassTestFixtureBase
{
[SetUp]
public void Init()
{
base.InitBase();
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
oldUnit.Classes.Add(outerClass);
// Create new compilation unit with extra class.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newOuterClass = new MockClass("MyTests.A");
newOuterClass.ProjectContent = projectContent;
projectContent.Classes.Add(newOuterClass);
newOuterClass.SetCompoundClass(newOuterClass);
newUnit.Classes.Add(newOuterClass);
// Create the inner test class.
// Note the use of the DotNetName "MyTests.A+InnerTest".
MockClass newInnerClass = new MockClass("MyTests.A.InnerATestMod", "MyTests.A+InnerATestMod");
newInnerClass.Attributes.Add(new MockAttribute("TestFixture"));
newInnerClass.ProjectContent = projectContent;
newInnerClass.DeclaringType = outerClass; // Declaring type is outer class.
newOuterClass.InnerClasses.Add(newInnerClass);
// Update TestProject's parse info.
testProject.UpdateParseInfo(oldUnit, newUnit);
}
[Test]
public void NewInnerClassAdded()
{
Assert.IsTrue(testProject.TestClasses.Contains("MyTests.A+InnerATestMod"));
}
[Test]
public void OldInnerClassRemoved()
{
Assert.IsFalse(testProject.TestClasses.Contains("MyTests.A+InnerATest"));
}
[Test]
public void OneTestClassRemain()
{
Assert.AreEqual(1, testProject.TestClasses.Count);
}
}
}

79
src/AddIns/Misc/UnitTesting/Test/Project/InnerClassTestFixture.cs

@ -0,0 +1,79 @@
// <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.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// Tests that a class with an inner test fixture is recognised, for example:
///
/// public class A
/// {
/// [TestFixture]
/// public class InnerATest
/// {
/// [Test]
/// public void FooBar()
/// {
/// }
/// }
/// }
///
/// In this case the FooBar test is identified via: "A+InnerATest.FooBar".
/// </summary>
[TestFixture]
public class InnerClassTestFixture : InnerClassTestFixtureBase
{
[SetUp]
public void Init()
{
base.InitBase();
}
[Test]
public void OneTestClassFound()
{
Assert.AreEqual(1, testProject.TestClasses.Count);
}
[Test]
public void TestClassQualifiedName()
{
Assert.AreEqual("MyTests.A+InnerATest", testClass.QualifiedName);
}
[Test]
public void TestClassName()
{
Assert.AreEqual("A+InnerATest", testClass.Name);
}
[Test]
public void NoTestClassesForNamespaceMyTestsA()
{
Assert.AreEqual(0, testProject.GetTestClasses("MyTests.A").Length);
}
[Test]
public void OneTestClassForNamespaceMyTests()
{
Assert.AreEqual(1, testProject.GetTestClasses("MyTests").Length);
}
[Test]
public void NamespaceForInnerClassIsDeclaringTypesNamespace()
{
Assert.AreEqual("MyTests", testClass.Namespace);
}
}
}

61
src/AddIns/Misc/UnitTesting/Test/Project/InnerClassTestFixtureAttributeRemovedTestFixture.cs

@ -0,0 +1,61 @@
// <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.SharpDevelop.Dom;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// Tests that the inner test class is removed when its TestFixture attribute is removed.
/// </summary>
[TestFixture]
public class InnerClassTestFixtureAttributeRemovedTestFixture : InnerClassTestFixtureBase
{
[SetUp]
public void Init()
{
base.InitBase();
DefaultCompilationUnit oldUnit = new DefaultCompilationUnit(projectContent);
oldUnit.Classes.Add(outerClass);
// Create new compilation unit with inner class that no longer has the TestFixture attribute.
DefaultCompilationUnit newUnit = new DefaultCompilationUnit(projectContent);
MockClass newOuterClass = new MockClass("MyTests.A");
newOuterClass.ProjectContent = projectContent;
projectContent.Classes.Add(newOuterClass);
newOuterClass.SetCompoundClass(newOuterClass);
newUnit.Classes.Add(newOuterClass);
// Create the inner test class.
MockClass newInnerClass = new MockClass("MyTests.A.InnerATest", "MyTests.A+InnerATest");
newInnerClass.ProjectContent = projectContent;
newInnerClass.DeclaringType = outerClass; // Declaring type is outer class.
newInnerClass.SetCompoundClass(newInnerClass);
newOuterClass.InnerClasses.Add(newInnerClass);
// Update TestProject's parse info.
testProject.UpdateParseInfo(oldUnit, newUnit);
}
[Test]
public void NoTestClasses()
{
Assert.AreEqual(0, testProject.TestClasses.Count);
}
[Test]
public void InnerTestClassRemoved()
{
Assert.IsFalse(testProject.TestClasses.Contains("MyTests.A+InnerATest"));
}
}
}

70
src/AddIns/Misc/UnitTesting/Test/Project/InnerClassTestFixtureBase.cs

@ -0,0 +1,70 @@
// <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.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// Base class for testing inner classes with TestFixture information.
/// </summary>
public class InnerClassTestFixtureBase
{
protected TestClass testClass;
protected MockClass innerClass;
protected TestProject testProject;
protected MockProjectContent projectContent;
protected MockClass outerClass;
protected void InitBase()
{
projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
// Create the base test class.
outerClass = new MockClass("MyTests.A");
outerClass.ProjectContent = projectContent;
projectContent.Classes.Add(outerClass);
// Create the inner test class.
// Note the use of the DotNetName "MyTests.A+InnerTest".
innerClass = new MockClass("MyTests.A.InnerATest", "MyTests.A+InnerATest");
innerClass.Attributes.Add(new MockAttribute("TestFixture"));
innerClass.ProjectContent = projectContent;
innerClass.DeclaringType = outerClass; // Declaring type is outer class.
MockMethod method = new MockMethod("FooBar");
method.Attributes.Add(new MockAttribute("Test"));
method.DeclaringType = innerClass;
innerClass.Methods.Add(method);
outerClass.InnerClasses.Add(innerClass);
// Add another inner class that is not a test class.
MockClass nonTestInnerClass = new MockClass("MyTests.A.InnerBClass");
nonTestInnerClass.ProjectContent = projectContent;
nonTestInnerClass.DeclaringType = outerClass; // Declaring type is outer class.
outerClass.InnerClasses.Add(nonTestInnerClass);
// Add another inner class with the same name as the InnerATest.
// This makes sure duplicate classes are not added.
MockClass duplicateInnerClass = new MockClass("MyTests.A.InnerATest", "MyTests.A+InnerATest");
duplicateInnerClass.Attributes.Add(new MockAttribute("TestFixture"));
duplicateInnerClass.ProjectContent = projectContent;
duplicateInnerClass.DeclaringType = outerClass; // Declaring type is outer class.
outerClass.InnerClasses.Add(duplicateInnerClass);
testProject = new TestProject(null, projectContent);
if (testProject.TestClasses.Count > 0) {
testClass = testProject.TestClasses[0];
}
}
}
}

111
src/AddIns/Misc/UnitTesting/Test/Project/RemovedClassesTestFixture.cs

@ -0,0 +1,111 @@
// <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.Text;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
[TestFixture]
public class RemovedClassesTestFixture
{
RemovedClasses removedClasses;
MockClass myClass;
MockClass anotherClass;
MockClass innerClass;
[SetUp]
public void Init()
{
myClass = new MockClass("MyTests.MyClass");
innerClass = new MockClass("MyTests.MyClass.InnerClass", "MyTests.MyClass+InnerClass");
myClass.InnerClasses.Add(innerClass);
anotherClass = new MockClass("MyTests.AnotherClass");
List<IClass> classes = new List<IClass>();
classes.Add(myClass);
classes.Add(anotherClass);
removedClasses = new RemovedClasses();
removedClasses.Add(classes);
}
[Test]
public void InnerClassesIncludedInMissingClasses()
{
List<IClass> expectedClasses = new List<IClass>();
expectedClasses.Add(myClass);
expectedClasses.Add(innerClass);
expectedClasses.Add(anotherClass);
AssertContains(expectedClasses, removedClasses.GetMissingClasses());
}
/// <summary>
/// Should remove inner class too.
/// </summary>
[Test]
public void RemoveMyClass()
{
removedClasses.Remove(myClass);
List<IClass> expectedClasses = new List<IClass>();
expectedClasses.Add(anotherClass);
AssertContains(expectedClasses, removedClasses.GetMissingClasses());
}
[Test]
public void RemoveInnerClass()
{
removedClasses.Remove(innerClass);
List<IClass> expectedClasses = new List<IClass>();
expectedClasses.Add(myClass);
expectedClasses.Add(anotherClass);
AssertContains(expectedClasses, removedClasses.GetMissingClasses());
}
[Test]
public void DotNetNameUsedWhenAddingClasses()
{
MockClass c = new MockClass("MyTests.MyClass.InnerClass", "MyTests.MyClass+InnerClass");
List<IClass> classes = new List<IClass>();
classes.Add(c);
RemovedClasses removedClasses = new RemovedClasses();
removedClasses.Add(classes);
removedClasses.Remove(c);
Assert.AreEqual(0, removedClasses.GetMissingClasses().Count);
}
void AssertContains(IList<IClass> expectedClasses, IList<IClass> actualClasses)
{
foreach (IClass c in expectedClasses) {
Assert.IsTrue(actualClasses.Contains(c), "Class missing: " + c.FullyQualifiedName + " Actual:\r\n" + GetClassNames(actualClasses));
}
Assert.AreEqual(expectedClasses.Count, actualClasses.Count, "Actual:\r\n" + GetClassNames(actualClasses));
}
string GetClassNames(IList<IClass> classes)
{
StringBuilder names = new StringBuilder();
foreach (IClass c in classes) {
names.AppendLine(c.FullyQualifiedName);
}
return names.ToString();
}
}
}

12
src/AddIns/Misc/UnitTesting/Test/UnitTestCommandLineTests.cs

@ -209,6 +209,18 @@ namespace UnitTesting.Tests
{ {
helper.Initialize(project, null, null); helper.Initialize(project, null, null);
Assert.AreSame(project, helper.Project); Assert.AreSame(project, helper.Project);
}
[Test]
public void TestInnerClassSpecifiedInInitialize()
{
MockClass testFixture = new MockClass("MyTests.TestFixture.InnerTest", "MyTests.TestFixture+InnerTest");
helper.Initialize(project, testFixture, null);
helper.NoLogo = false;
helper.ShadowCopy = true;
string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"MyTests.TestFixture+InnerTest\"";
Assert.AreEqual(expectedCommandLine, helper.GetArguments());
} }
} }
} }

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

@ -62,6 +62,12 @@
<Compile Include="NUnitConsoleExeSelectedTestFixture.cs" /> <Compile Include="NUnitConsoleExeSelectedTestFixture.cs" />
<Compile Include="Project\AbstractBaseClassWithTestMethodsTestFixture.cs" /> <Compile Include="Project\AbstractBaseClassWithTestMethodsTestFixture.cs" />
<Compile Include="Project\BaseTestMethodTestFixture.cs" /> <Compile Include="Project\BaseTestMethodTestFixture.cs" />
<Compile Include="Project\InnerClassMethodRenamedTestFixture.cs" />
<Compile Include="Project\InnerClassNameChangesTestFixture.cs" />
<Compile Include="Project\InnerClassTestFixture.cs" />
<Compile Include="Project\InnerClassTestFixtureAttributeRemovedTestFixture.cs" />
<Compile Include="Project\InnerClassTestFixtureBase.cs" />
<Compile Include="Project\RemovedClassesTestFixture.cs" />
<Compile Include="TestableConditionTests.cs" /> <Compile Include="TestableConditionTests.cs" />
<Compile Include="Tree\MultipleTestProjectsTestFixture.cs" /> <Compile Include="Tree\MultipleTestProjectsTestFixture.cs" />
<Compile Include="Tree\TreeNodeContextMenuTestFixture.cs" /> <Compile Include="Tree\TreeNodeContextMenuTestFixture.cs" />

91
src/AddIns/Misc/UnitTesting/Test/Utils/MockClass.cs

@ -17,25 +17,36 @@ namespace UnitTesting.Tests.Utils
DomRegion region = DomRegion.Empty; DomRegion region = DomRegion.Empty;
IList<IAttribute> attributes = new List<IAttribute>(); IList<IAttribute> attributes = new List<IAttribute>();
IList<IMethod> methods = new List<IMethod>(); IList<IMethod> methods = new List<IMethod>();
IList<IClass> innerClasses = new List<IClass>();
string fullyQualifiedName = String.Empty; string fullyQualifiedName = String.Empty;
string name = String.Empty; string name = String.Empty;
string ns = String.Empty; string ns = String.Empty;
IClass compoundClass; IClass compoundClass;
IClass baseClass; IClass baseClass;
string dotNetName = String.Empty;
IClass declaringType;
public MockClass() public MockClass()
{ {
} }
public MockClass(string fullyQualifiedName) public MockClass(string fullyQualifiedName) : this(fullyQualifiedName, fullyQualifiedName)
{
}
public MockClass(string fullyQualifiedName, string dotNetName)
{ {
FullyQualifiedName = fullyQualifiedName; FullyQualifiedName = fullyQualifiedName;
this.dotNetName = dotNetName;
}
public override string ToString()
{
return dotNetName;
} }
public string FullyQualifiedName { public string FullyQualifiedName {
get { get { return fullyQualifiedName; }
return fullyQualifiedName;
}
set { set {
fullyQualifiedName = value; fullyQualifiedName = value;
int index = fullyQualifiedName.LastIndexOf('.'); int index = fullyQualifiedName.LastIndexOf('.');
@ -49,74 +60,45 @@ namespace UnitTesting.Tests.Utils
} }
public string Name { public string Name {
get { get { return name; }
return name; set { name = value; }
}
set {
name = value;
}
} }
public string Namespace { public string Namespace {
get { get { return ns; }
return ns; set { ns = value; }
}
set {
ns = value;
}
} }
public ClassType ClassType { public ClassType ClassType {
get { get { return ClassType.Class; }
return ClassType.Class;
}
} }
public IProjectContent ProjectContent { public IProjectContent ProjectContent {
get { get { return projectContent; }
return projectContent; set { projectContent = value; }
}
set {
projectContent = value;
}
} }
public DomRegion Region { public DomRegion Region {
get { get { return region; }
return region; set { region = value; }
}
set {
region = value;
}
} }
public IList<IMethod> Methods { public IList<IMethod> Methods {
get { get { return methods; }
return methods;
}
} }
public IClass BaseClass { public IClass BaseClass {
get { get { return baseClass; }
return baseClass; set { baseClass = value; }
}
set {
baseClass = value;
}
} }
public ModifierEnum Modifiers { public ModifierEnum Modifiers {
get { get { return ModifierEnum.None; }
return ModifierEnum.None; set { }
}
set {
}
} }
public IList<IAttribute> Attributes { public IList<IAttribute> Attributes {
get { get { return attributes; }
return attributes;
}
} }
public IClass GetCompoundClass() public IClass GetCompoundClass()
@ -136,9 +118,7 @@ namespace UnitTesting.Tests.Utils
} }
public string DotNetName { public string DotNetName {
get { get { return dotNetName; }
throw new NotImplementedException();
}
} }
public ICompilationUnit CompilationUnit { public ICompilationUnit CompilationUnit {
@ -160,9 +140,7 @@ namespace UnitTesting.Tests.Utils
} }
public IList<IClass> InnerClasses { public IList<IClass> InnerClasses {
get { get { return innerClasses; }
throw new NotImplementedException();
}
} }
public IList<IField> Fields { public IList<IField> Fields {
@ -223,9 +201,8 @@ namespace UnitTesting.Tests.Utils
} }
public IClass DeclaringType { public IClass DeclaringType {
get { get { return declaringType; }
throw new NotImplementedException(); set { declaringType = value; }
}
} }
public string Documentation { public string Documentation {

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

@ -62,6 +62,7 @@
</None> </None>
<Compile Include="Src\AllTestsTreeNode.cs" /> <Compile Include="Src\AllTestsTreeNode.cs" />
<Compile Include="Src\BaseTestMethod.cs" /> <Compile Include="Src\BaseTestMethod.cs" />
<Compile Include="Src\RemovedClasses.cs" />
<Compile Include="Src\UnitTestCommands.cs" /> <Compile Include="Src\UnitTestCommands.cs" />
<Compile Include="Src\TestableCondition.cs" /> <Compile Include="Src\TestableCondition.cs" />
<Compile Include="Src\RunningTestsCondition.cs" /> <Compile Include="Src\RunningTestsCondition.cs" />

Loading…
Cancel
Save