Browse Source

More UnitTesting.Tests.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
740d893085
  1. 2
      SharpDevelop.Tests.sln
  2. 2
      src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestClass.cs
  3. 6
      src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestMethod.cs
  4. 12
      src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestProject.cs
  5. 29
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassInTestFixtureTests.cs
  6. 26
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassMethodRenamedTestFixture.cs
  7. 21
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassNameChangesTestFixture.cs
  8. 27
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassTestFixture.cs
  9. 20
      src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassTestFixtureAttributeRemovedTestFixture.cs
  10. 28
      src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs
  11. 45
      src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithOneMethodTestFixture.cs
  12. 59
      src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs
  13. 188
      src/AddIns/Analysis/UnitTesting/Test/Project/TestCollectionTests.cs
  14. 87
      src/AddIns/Analysis/UnitTesting/Test/Project/TestMethodsInBaseClassTestFixture.cs
  15. 115
      src/AddIns/Analysis/UnitTesting/Test/Project/TestProjectWithOneClassTestFixture.cs
  16. 173
      src/AddIns/Analysis/UnitTesting/Test/Project/ThreeTestClassesTestResultsTestFixture.cs
  17. 156
      src/AddIns/Analysis/UnitTesting/Test/Project/ThreeTestMethodsTestResultsTestFixture.cs
  18. 96
      src/AddIns/Analysis/UnitTesting/Test/Project/TwoBaseClassesWithTestMethodsTestFixture.cs
  19. 117
      src/AddIns/Analysis/UnitTesting/Test/Project/TwoProjectRootNamespacesTestFixture.cs
  20. 11
      src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj
  21. 32
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockStatusBarService.cs
  22. 106
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFramework.cs
  23. 43
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFrameworkFactory.cs
  24. 32
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFrameworksWithNUnitFrameworkSupport.cs
  25. 80
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockUnitTestWorkbench.cs
  26. 74
      src/AddIns/Analysis/UnitTesting/Test/Utils/MockUnitTestsPad.cs
  27. 2
      src/Main/Base/Project/Src/Services/ParserService/IParserService.cs
  28. 2
      src/Main/Base/Project/Src/Services/ParserService/SharpDevelopSolutionSnapshot.cs
  29. 4
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs
  30. 2
      src/Main/SharpDevelop/Parser/ParserService.cs

2
SharpDevelop.Tests.sln

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 # Visual Studio 2010
# SharpDevelop 5.0 # SharpDevelop 4.3
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}"
ProjectSection(SolutionItems) = postProject ProjectSection(SolutionItems) = postProject
EndProjectSection EndProjectSection

2
src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestClass.cs

@ -65,7 +65,7 @@ namespace ICSharpCode.UnitTesting
} }
} }
ITypeDefinition Resolve() public ITypeDefinition Resolve()
{ {
ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project); ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project);
IType type = compilation.MainAssembly.GetTypeDefinition(fullTypeName); IType type = compilation.MainAssembly.GetTypeDefinition(fullTypeName);

6
src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestMethod.cs

@ -53,6 +53,10 @@ namespace ICSharpCode.UnitTesting
public override event EventHandler DisplayNameChanged; public override event EventHandler DisplayNameChanged;
public DomRegion Region {
get { return method.Region; }
}
public bool IsInherited { public bool IsInherited {
get { return derivedFixture.Name != null; } get { return derivedFixture.Name != null; }
} }
@ -74,7 +78,7 @@ namespace ICSharpCode.UnitTesting
this.Result = result.ResultType; this.Result = result.ResultType;
} }
IMethod Resolve() public IMethod Resolve()
{ {
ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project); ICompilation compilation = SD.ParserService.GetCompilation(parentProject.Project);
IMethod resolvedMethod = method.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly)); IMethod resolvedMethod = method.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));

12
src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestProject.cs

@ -61,9 +61,9 @@ namespace ICSharpCode.UnitTesting
if (typeDefinition.IsAbstract) { if (typeDefinition.IsAbstract) {
tests = from c in entity.ParentAssembly.GetAllTypeDefinitions() tests = from c in entity.ParentAssembly.GetAllTypeDefinitions()
where c.IsDerivedFrom(typeDefinition) where c.IsDerivedFrom(typeDefinition)
select GetTestForEntityInClass(FindTestClass(c.FullTypeName), entity); select GetTestForEntityInClass(GetTestClass(c.FullTypeName), entity);
} else { } else {
NUnitTestClass c = FindTestClass(typeDefinition.FullTypeName); NUnitTestClass c = GetTestClass(typeDefinition.FullTypeName);
tests = new [] { GetTestForEntityInClass(c, entity) }; tests = new [] { GetTestForEntityInClass(c, entity) };
} }
// GetTestForEntityInClass might return null, so filter those out: // GetTestForEntityInClass might return null, so filter those out:
@ -89,14 +89,14 @@ namespace ICSharpCode.UnitTesting
return; return;
string fixtureName = result.Name.Substring(0, lastDot); string fixtureName = result.Name.Substring(0, lastDot);
string methodName = result.Name.Substring(lastDot + 1); string methodName = result.Name.Substring(lastDot + 1);
NUnitTestClass testClass = FindTestClass(new FullTypeName(fixtureName)); NUnitTestClass testClass = GetTestClass(new FullTypeName(fixtureName));
if (testClass == null) { if (testClass == null) {
// maybe it's an inherited test // maybe it's an inherited test
int secondToLastDot = result.Name.LastIndexOf('.', lastDot - 1); int secondToLastDot = result.Name.LastIndexOf('.', lastDot - 1);
if (secondToLastDot >= 0) { if (secondToLastDot >= 0) {
string fixtureName2 = result.Name.Substring(0, secondToLastDot); string fixtureName2 = result.Name.Substring(0, secondToLastDot);
methodName = result.Name.Substring(secondToLastDot + 1); methodName = result.Name.Substring(secondToLastDot + 1);
testClass = FindTestClass(new FullTypeName(fixtureName2)); testClass = GetTestClass(new FullTypeName(fixtureName2));
} }
} }
if (testClass != null) { if (testClass != null) {
@ -107,9 +107,9 @@ namespace ICSharpCode.UnitTesting
} }
} }
NUnitTestClass FindTestClass(FullTypeName fullTypeName) public NUnitTestClass GetTestClass(FullTypeName fullTypeName)
{ {
var testClass = (NUnitTestClass)GetTestClass(fullTypeName.TopLevelTypeName); var testClass = (NUnitTestClass)base.GetTestClass(fullTypeName.TopLevelTypeName);
int tpc = fullTypeName.TopLevelTypeName.TypeParameterCount; int tpc = fullTypeName.TopLevelTypeName.TypeParameterCount;
for (int i = 0; i < fullTypeName.NestingLevel; i++) { for (int i = 0; i < fullTypeName.NestingLevel; i++) {
if (testClass == null) if (testClass == null)

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

@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
using UnitTesting.Tests.Utils; using UnitTesting.Tests.Utils;
@ -13,15 +14,12 @@ namespace UnitTesting.Tests.Project
/// Tests that a class nested inside test fixture is recognized /// Tests that a class nested inside test fixture is recognized
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class InnerClassInTestFixtureTests : ProjectTestFixtureBase public class InnerClassInTestFixtureTests : NUnitTestProjectFixtureBase
{ {
TestClass outerTestClass; public override void SetUp()
[SetUp]
public void Init()
{ {
CreateNUnitProject( base.SetUp();
Parse(@"using NUnit.Framework; AddCodeFile("test.cs", @"using NUnit.Framework;
namespace MyTests { namespace MyTests {
[TestFixture] [TestFixture]
public class A public class A
@ -40,38 +38,31 @@ namespace MyTests {
public class InnerBClass {} public class InnerBClass {}
} }
} }");
"));
} }
[Test] [Test]
public void OuterTestClassFound() public void OuterTestClassFound()
{ {
Assert.IsNotNull(testProject.GetTestClass("A")); Assert.IsNotNull(testProject.GetTestClass(new FullTypeName("MyTests.A")));
} }
[Test] [Test]
public void InnerNonTestClassWithoutWasNotMarkedAsTestClass() public void InnerNonTestClassWithoutWasNotMarkedAsTestClass()
{ {
Assert.IsNull(testProject.GetTestClass("A+InnerBClass")); Assert.IsNull(testProject.GetTestClass(new FullTypeName("MyTests.A+InnerBClass")));
} }
[Test] [Test]
public void InnerClassInInnerClassFound() public void InnerClassInInnerClassFound()
{ {
Assert.IsNotNull(testProject.GetTestClass("A+InnerATest+InnerTestLevel2")); Assert.IsNotNull(testProject.GetTestClass(new FullTypeName("MyTests.A+InnerATest+InnerTestLevel2")));
} }
[Test] [Test]
public void TestClassNameShouldBeDotNetNameOfTheDoubleNestedClass() public void TestClassNameShouldBeDotNetNameOfTheDoubleNestedClass()
{ {
Assert.AreEqual("MyTests.A+InnerATest+InnerTestLevel2", testProject.GetTestClass("A+InnerATest+InnerTestLevel2").QualifiedName); Assert.AreEqual("MyTests.A+InnerATest+InnerTestLevel2", testProject.GetTestClass(new FullTypeName("MyTests.A+InnerATest+InnerTestLevel2")).ReflectionName);
}
[Test]
public void TestClassNamespaceShouldBeValid()
{
Assert.AreEqual("MyTests", testProject.GetTestClass("A+InnerATest+InnerTestLevel2").Namespace);
} }
} }
} }

26
src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassMethodRenamedTestFixture.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
using UnitTesting.Tests.Utils; using UnitTesting.Tests.Utils;
@ -13,14 +14,15 @@ namespace UnitTesting.Tests.Project
/// Tests what happens when a test method is renamed inside an inner class. /// Tests what happens when a test method is renamed inside an inner class.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class InnerClassMethodRemovedTestFixture : ProjectTestFixtureBase public class InnerClassMethodRemovedTestFixture : NUnitTestProjectFixtureBase
{ {
TestClass innerTestClass; NUnitTestClass innerTestClass;
[SetUp] public override void SetUp()
public void Init()
{ {
CreateNUnitProject(Parse(@" base.SetUp();
AddCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace MyTests { namespace MyTests {
class A { class A {
@ -30,13 +32,13 @@ namespace MyTests {
} }
} }
} }
")); ");
// The members should be changed on the existing TestClass instance, // The members should be changed on the existing TestClass instance,
// so grab the reference in before updating. // so grab the reference in before updating.
innerTestClass = testProject.GetTestClass("MyTests.A+InnerATest"); innerTestClass = testProject.GetTestClass(new FullTypeName("MyTests.A+InnerATest"));
UpdateCodeFile(@" UpdateCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace MyTests { namespace MyTests {
class A { class A {
@ -55,20 +57,20 @@ namespace MyTests {
[Test] [Test]
public void NewTestMethodExists() public void NewTestMethodExists()
{ {
TestMember method = innerTestClass.Members[0]; Assert.Contains("FooBarRenamed", GetTestMethodNames(innerTestClass));
Assert.AreEqual("FooBarRenamed", method.Name);
} }
[Test] [Test]
public void OldTestMethodRemoved() public void OldTestMethodRemoved()
{ {
Assert.AreEqual(1, innerTestClass.Members.Count); Assert.IsFalse(GetTestMethodNames(innerTestClass).Contains("FooBar"));
} }
[Test] [Test]
public void NewTestClassExists() public void NewTestClassExists()
{ {
CollectionAssert.Contains(innerTestClass.NestedClasses.Select(x => x.QualifiedName).ToList(), "MyTests.A+InnerATest+InnerInnerTest"); CollectionAssert.Contains(innerTestClass.NestedTests.OfType<NUnitTestClass>().Select(x => x.ReflectionName),
"MyTests.A+InnerATest+InnerInnerTest");
} }
} }
} }

21
src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassNameChangesTestFixture.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
@ -14,14 +15,14 @@ namespace UnitTesting.Tests.Project
/// Tests that the TestProject is correctly updated after the inner class name changes. /// Tests that the TestProject is correctly updated after the inner class name changes.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class InnerClassNameChangesTestFixture : ProjectTestFixtureBase public class InnerClassNameChangesTestFixture : NUnitTestProjectFixtureBase
{ {
TestClass originalA; NUnitTestClass originalA;
[SetUp] public override void SetUp()
public void Init()
{ {
CreateNUnitProject(Parse(@" base.SetUp();
AddCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace MyTests { namespace MyTests {
class A { class A {
@ -31,11 +32,11 @@ namespace MyTests {
} }
} }
} }
")); ");
originalA = testProject.GetTestClass("MyTests.A"); originalA = testProject.GetTestClass(new FullTypeName("MyTests.A"));
UpdateCodeFile(@" UpdateCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace MyTests { namespace MyTests {
class A { class A {
@ -52,13 +53,13 @@ namespace MyTests {
public void OuterClassNotChanged() public void OuterClassNotChanged()
{ {
Assert.IsNotNull(originalA); Assert.IsNotNull(originalA);
Assert.AreSame(originalA, testProject.GetTestClass("MyTests.A")); Assert.AreSame(originalA, testProject.GetTestClass(new FullTypeName("MyTests.A")));
} }
[Test] [Test]
public void InnerClassRenamed() public void InnerClassRenamed()
{ {
Assert.AreEqual("InnerTestMod", originalA.NestedClasses.Single().Name); Assert.AreEqual("InnerTestMod", originalA.NestedTests.Single().DisplayName);
} }
} }
} }

27
src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassTestFixture.cs

@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
@ -27,15 +28,15 @@ namespace UnitTesting.Tests.Project
/// In this case the FooBar test is identified via: "A+InnerATest.FooBar". /// In this case the FooBar test is identified via: "A+InnerATest.FooBar".
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class InnerClassTestFixture : ProjectTestFixtureBase public class InnerClassTestFixture : NUnitTestProjectFixtureBase
{ {
TestClass outerClass; NUnitTestClass outerClass;
TestClass innerClass; NUnitTestClass innerClass;
[SetUp] public override void SetUp()
public void Init()
{ {
CreateNUnitProject(Parse(@" base.SetUp();
AddCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace MyTests { namespace MyTests {
public class A public class A
@ -48,33 +49,33 @@ namespace MyTests {
} }
} }
} }
}")); }");
outerClass = testProject.GetTestClass("A"); outerClass = testProject.GetTestClass(new FullTypeName("MyTests.A"));
innerClass = testProject.GetTestClass("A+InnerATest"); innerClass = testProject.GetTestClass(new FullTypeName("MyTests.A+InnerATest"));
} }
[Test] [Test]
public void OneTestClassFound() public void OneTestClassFound()
{ {
Assert.AreEqual(1, testProject.TestClasses.Count); Assert.AreEqual(1, testProject.NestedTests.Count);
} }
[Test] [Test]
public void TestClassQualifiedName() public void TestClassQualifiedName()
{ {
Assert.AreEqual("MyTests.A+InnerATest", innerClass.QualifiedName); Assert.AreEqual("MyTests.A+InnerATest", innerClass.ReflectionName);
} }
[Test] [Test]
public void TestClassName() public void TestClassName()
{ {
Assert.AreEqual("InnerATest", innerClass.Name); Assert.AreEqual("InnerATest", innerClass.ClassName);
} }
[Test] [Test]
public void NamespaceForInnerClassIsDeclaringTypesNamespace() public void NamespaceForInnerClassIsDeclaringTypesNamespace()
{ {
Assert.AreEqual("MyTests", innerClass.Namespace); Assert.AreEqual("MyTests", innerClass.FullTypeName.TopLevelTypeName.Namespace);
} }
} }
} }

20
src/AddIns/Analysis/UnitTesting/Test/Project/InnerClassTestFixtureAttributeRemovedTestFixture.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
using UnitTesting.Tests.Utils; using UnitTesting.Tests.Utils;
@ -13,38 +14,39 @@ namespace UnitTesting.Tests.Project
/// Tests that the inner test class is removed when its TestFixture attribute is removed. /// Tests that the inner test class is removed when its TestFixture attribute is removed.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class InnerClassTestFixtureAttributeRemovedTestFixture : ProjectTestFixtureBase public class InnerClassTestFixtureAttributeRemovedTestFixture : NUnitTestProjectFixtureBase
{ {
[SetUp] public override void SetUp()
public void Init()
{ {
CreateNUnitProject(Parse(@" base.SetUp();
AddCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace MyTests { namespace MyTests {
class A { class A {
[TestFixture] [TestFixture]
class Inner {} class Inner {}
} }
}")); }");
testProject.EnsureNestedTestsInitialized();
} }
[Test] [Test]
public void RemoveAttribute_Leaves_No_TestClasses() public void RemoveAttribute_Leaves_No_TestClasses()
{ {
UpdateCodeFile(@" UpdateCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace MyTests { namespace MyTests {
class A { class A {
class Inner {} class Inner {}
} }
}"); }");
Assert.AreEqual(0, testProject.TestClasses.Count); Assert.AreEqual(0, testProject.NestedTests.Count);
} }
[Test] [Test]
public void MoveAttributeToOuterClass() public void MoveAttributeToOuterClass()
{ {
UpdateCodeFile(@" UpdateCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace MyTests { namespace MyTests {
[TestFixture] [TestFixture]
@ -52,7 +54,7 @@ namespace MyTests {
class Inner {} class Inner {}
} }
}"); }");
Assert.IsEmpty(testProject.TestClasses.Single().NestedClasses); Assert.IsEmpty(testProject.GetTestClass(new FullTypeName("MyTests.A")).NestedTests);
} }
} }
} }

28
src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs

@ -1,28 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Linq;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
[TestFixture]
public class TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests : ProjectTestFixtureBase
{
[Test]
public void TestMembers_ClassHasOneFieldDefinedAsTestMemberByTestFramework_FirstItemHasSameNameAsField()
{
var fakeTestFramework = new MockTestFramework();
fakeTestFramework.AddTestClass("MyClass");
fakeTestFramework.AddTestMember("MyClass.MyField");
CreateProject(fakeTestFramework, Parse("class MyClass { int MyField; }"));
TestMember testField = testProject.TestClasses.Single().Members.Single();
Assert.AreEqual("MyField", testField.Name);
}
}
}

45
src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithOneMethodTestFixture.cs

@ -14,18 +14,17 @@ using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project namespace UnitTesting.Tests.Project
{ {
[TestFixture] [TestFixture]
public class TestClassWithOneMethodTestFixture : ProjectTestFixtureBase public class TestClassWithOneMethodTestFixture : NUnitTestProjectFixtureBase
{ {
TestClass testClass; NUnitTestClass testClass;
TestMember testMethod; NUnitTestMethod testMethod;
bool resultChangedCalled; bool resultChangedCalled;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp] public override void SetUp()
public void Init()
{ {
base.SetUp();
resultChangedCalled = false; resultChangedCalled = false;
CreateNUnitProject(Parse(@" AddCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace RootNamespace.Tests { namespace RootNamespace.Tests {
[TestFixture] [TestFixture]
@ -33,15 +32,15 @@ namespace RootNamespace.Tests {
[Test] [Test]
public void TestMethod() { } public void TestMethod() { }
} }
}")); }");
testClass = testProject.TestClasses.Single(); testClass = (NUnitTestClass)testProject.NestedTests.Single().NestedTests.Single();
testMethod = testClass.Members.Single(); testMethod = (NUnitTestMethod)testClass.NestedTests.Single();
} }
[Test] [Test]
public void TestMethodResult() public void TestMethodResult()
{ {
Assert.AreEqual(TestResultType.None, testMethod.TestResult); Assert.AreEqual(TestResultType.None, testMethod.Result);
} }
[Test] [Test]
@ -52,14 +51,14 @@ namespace RootNamespace.Tests {
testProject.UpdateTestResult(result); testProject.UpdateTestResult(result);
Assert.AreEqual(TestResultType.Failure, testMethod.TestResult); Assert.AreEqual(TestResultType.Failure, testMethod.Result);
} }
[Test] [Test]
public void TestClassFailed() public void TestClassFailed()
{ {
TestFailed(); TestFailed();
Assert.AreEqual(TestResultType.Failure, testClass.TestResult); Assert.AreEqual(TestResultType.Failure, testClass.Result);
} }
[Test] [Test]
@ -70,19 +69,19 @@ namespace RootNamespace.Tests {
testProject.UpdateTestResult(result); testProject.UpdateTestResult(result);
Assert.AreEqual(TestResultType.Ignored, testClass.TestResult); Assert.AreEqual(TestResultType.Ignored, testClass.Result);
} }
[Test] [Test]
public void TestResultChanged() public void TestResultChanged()
{ {
try { try {
testMethod.TestResultChanged += ResultChanged; testMethod.ResultChanged += ResultChanged;
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod"); TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod");
result.ResultType = TestResultType.Failure; result.ResultType = TestResultType.Failure;
testProject.UpdateTestResult(result); testProject.UpdateTestResult(result);
} finally { } finally {
testMethod.TestResultChanged -= ResultChanged; testMethod.ResultChanged -= ResultChanged;
} }
Assert.IsTrue(resultChangedCalled); Assert.IsTrue(resultChangedCalled);
@ -92,12 +91,12 @@ namespace RootNamespace.Tests {
public void TestResultChangedOnClass() public void TestResultChangedOnClass()
{ {
try { try {
testClass.TestResultChanged += ResultChanged; testClass.ResultChanged += ResultChanged;
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod"); TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod");
result.ResultType = TestResultType.Failure; result.ResultType = TestResultType.Failure;
testProject.UpdateTestResult(result); testProject.UpdateTestResult(result);
} finally { } finally {
testClass.TestResultChanged -= ResultChanged; testClass.ResultChanged -= ResultChanged;
} }
Assert.IsTrue(resultChangedCalled); Assert.IsTrue(resultChangedCalled);
@ -133,14 +132,14 @@ namespace RootNamespace.Tests {
[Test] [Test]
public void FindTestMethod() public void FindTestMethod()
{ {
Assert.AreSame(testMethod, testClass.Members.Single(m => m.Name == "TestMethod")); Assert.AreSame(testMethod, testClass.NestedTests.Single(m => m.DisplayName == "TestMethod"));
} }
/* /*
[Test] [Test]
public void AddNewClassNodeWhenTestClassPassed() public void AddNewClassNodeWhenTestClassPassed()
{ {
testClass.TestResult = TestResultType.Success; testClass.Result = TestResultType.Success;
TestClassTreeNode node = new TestClassTreeNode(testProject, testClass); TestClassTreeNode node = new TestClassTreeNode(testProject, testClass);
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex); Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex);
} }
@ -148,7 +147,7 @@ namespace RootNamespace.Tests {
[Test] [Test]
public void AddNewMethodNodeWhenTestPassed() public void AddNewMethodNodeWhenTestPassed()
{ {
testMethod.TestResult = TestResultType.Success; testMethod.Result = TestResultType.Success;
TestMemberTreeNode node = new TestMemberTreeNode(testProject, testMethod); TestMemberTreeNode node = new TestMemberTreeNode(testProject, testMethod);
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex); Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex);
} }
@ -161,7 +160,7 @@ namespace RootNamespace.Tests {
[Test] [Test]
public void MethodRemovedInParserInfo() public void MethodRemovedInParserInfo()
{ {
UpdateCodeFile(@" UpdateCodeFile("test.cs", @"
using NUnit.Framework; using NUnit.Framework;
namespace RootNamespace.Tests { namespace RootNamespace.Tests {
[TestFixture] [TestFixture]
@ -170,7 +169,7 @@ namespace RootNamespace.Tests {
} }
}"); }");
Assert.AreEqual(0, testClass.Members.Count); Assert.AreEqual(0, testClass.NestedTests.Count);
} }
void ResultChanged(object source, EventArgs e) void ResultChanged(object source, EventArgs e)

59
src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
@ -11,32 +12,32 @@ using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project namespace UnitTesting.Tests.Project
{ {
[TestFixture] [TestFixture]
public class TestClassWithTwoMethodsTestFixture : ProjectTestFixtureBase public class TestClassWithTwoMethodsTestFixture : NUnitTestProjectFixtureBase
{ {
TestClass testClass; NUnitTestClass testClass;
TestMember testMethod1; NUnitTestMethod testMethod1;
TestMember testMethod2; NUnitTestMethod testMethod2;
[SetUp] public override void SetUp()
public void Init()
{ {
CreateNUnitProject(Parse(@"using NUnit.Framework; base.SetUp();
AddCodeFile("test.cs", @"using NUnit.Framework;
namespace RootNamespace.Tests { namespace RootNamespace.Tests {
[TestFixture] [TestFixture]
class MyTestFixture { class MyTestFixture {
[Test] public void TestMethod1() {} [Test] public void TestMethod1() {}
[Test] public void TestMethod2() {} [Test] public void TestMethod2() {}
} }
}")); }");
testClass = testProject.TestClasses.Single(); testClass = testProject.GetTestClass(new FullTypeName("RootNamespace.Tests.MyTestFixture"));
testMethod1 = testClass.Members[0]; testMethod1 = testClass.FindTestMethod("TestMethod1");
testMethod2 = testClass.Members[1]; testMethod2 = testClass.FindTestMethod("TestMethod2");
} }
[Test] [Test]
public void TwoMethods() public void TwoMethods()
{ {
Assert.AreEqual(2, testClass.Members.Count); Assert.AreEqual(2, testClass.NestedTests.Count);
} }
[Test] [Test]
@ -47,7 +48,7 @@ namespace RootNamespace.Tests {
testProject.UpdateTestResult(result); testProject.UpdateTestResult(result);
Assert.AreEqual(TestResultType.Failure, testMethod1.TestResult); Assert.AreEqual(TestResultType.Failure, testMethod1.Result);
} }
[Test] [Test]
@ -58,7 +59,7 @@ namespace RootNamespace.Tests {
testProject.UpdateTestResult(result); testProject.UpdateTestResult(result);
Assert.AreEqual(TestResultType.Ignored, testMethod1.TestResult); Assert.AreEqual(TestResultType.Ignored, testMethod1.Result);
} }
[Test] [Test]
@ -66,7 +67,7 @@ namespace RootNamespace.Tests {
{ {
TestMethod1Failed(); TestMethod1Failed();
Assert.AreEqual(TestResultType.Failure, testClass.TestResult); Assert.AreEqual(TestResultType.Failure, testClass.Result);
} }
[Test] [Test]
@ -77,7 +78,7 @@ namespace RootNamespace.Tests {
testProject.UpdateTestResult(result); testProject.UpdateTestResult(result);
Assert.AreEqual(TestResultType.Success, testMethod1.TestResult); Assert.AreEqual(TestResultType.Success, testMethod1.Result);
} }
[Test] [Test]
@ -85,7 +86,7 @@ namespace RootNamespace.Tests {
{ {
TestMethod1Passes(); TestMethod1Passes();
Assert.AreEqual(TestResultType.None, testClass.TestResult); Assert.AreEqual(TestResultType.None, testClass.Result);
} }
[Test] [Test]
@ -96,7 +97,7 @@ namespace RootNamespace.Tests {
testProject.UpdateTestResult(result); testProject.UpdateTestResult(result);
Assert.AreEqual(TestResultType.Success, testMethod2.TestResult); Assert.AreEqual(TestResultType.Success, testMethod2.Result);
} }
[Test] [Test]
@ -104,7 +105,7 @@ namespace RootNamespace.Tests {
{ {
TestMethod2Passes(); TestMethod2Passes();
Assert.AreEqual(TestResultType.None, testClass.TestResult); Assert.AreEqual(TestResultType.None, testClass.Result);
} }
[Test] [Test]
@ -113,7 +114,7 @@ namespace RootNamespace.Tests {
TestMethod1Passes(); TestMethod1Passes();
TestMethod2Passes(); TestMethod2Passes();
Assert.AreEqual(TestResultType.Success, testClass.TestResult); Assert.AreEqual(TestResultType.Success, testClass.Result);
} }
[Test] [Test]
@ -122,7 +123,7 @@ namespace RootNamespace.Tests {
TestMethod1Ignored(); TestMethod1Ignored();
TestMethod2Passes(); TestMethod2Passes();
Assert.AreEqual(TestResultType.Ignored, testClass.TestResult); Assert.AreEqual(TestResultType.Ignored, testClass.Result);
} }
[Test] [Test]
@ -131,10 +132,10 @@ namespace RootNamespace.Tests {
TestMethod1Failed(); TestMethod1Failed();
TestMethod2Passes(); TestMethod2Passes();
Assert.AreEqual(TestResultType.Failure, testClass.TestResult); Assert.AreEqual(TestResultType.Failure, testClass.Result);
} }
[Test] /*[Test]
public void FindTestMethod() public void FindTestMethod()
{ {
TestMember method = testProject.GetTestMember("RootNamespace.Tests.MyTestFixture.TestMethod1"); TestMember method = testProject.GetTestMember("RootNamespace.Tests.MyTestFixture.TestMethod1");
@ -157,7 +158,7 @@ namespace RootNamespace.Tests {
public void FindTestMethodFromInvalidTestMethodName() public void FindTestMethodFromInvalidTestMethodName()
{ {
Assert.IsNull(testProject.GetTestMember(String.Empty)); Assert.IsNull(testProject.GetTestMember(String.Empty));
} }*/
/// <summary> /// <summary>
/// SD2-1278. Tests that the method is updated in the TestClass. /// SD2-1278. Tests that the method is updated in the TestClass.
@ -166,9 +167,9 @@ namespace RootNamespace.Tests {
[Test] [Test]
public void TestMethodShouldBeUpdatedInClass() public void TestMethodShouldBeUpdatedInClass()
{ {
Assert.AreEqual(5, testMethod1.Member.Region.BeginLine); Assert.AreEqual(5, testMethod1.Region.BeginLine);
UpdateCodeFile(@"using NUnit.Framework; UpdateCodeFile("test.cs", @"using NUnit.Framework;
namespace RootNamespace.Tests { namespace RootNamespace.Tests {
[TestFixture] [TestFixture]
class MyTestFixture { class MyTestFixture {
@ -178,9 +179,9 @@ namespace RootNamespace.Tests {
} }
}"); }");
Assert.AreSame(testClass, testProject.TestClasses.Single()); Assert.AreSame(testClass, testProject.GetTestClass(new FullTypeName("RootNamespace.Tests.MyTestFixture")));
Assert.AreSame(testMethod1, testClass.Members[0]); Assert.AreSame(testMethod1, testClass.NestedTests.Single(m => m.DisplayName == "TestMethod1"));
Assert.AreEqual(6, testMethod1.Member.Region.BeginLine); Assert.AreEqual(6, testMethod1.Region.BeginLine);
} }
} }
} }

188
src/AddIns/Analysis/UnitTesting/Test/Project/TestCollectionTests.cs

@ -0,0 +1,188 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.ComponentModel;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// Creates a TestClassCollection with three test classes.
/// </summary>
[TestFixture]
public class TestCollectionTests
{
class FakeTest : TestBase
{
public override ITestProject ParentProject {
get { throw new NotImplementedException(); }
}
public override string DisplayName {
get { throw new NotImplementedException(); }
}
public new TestResultType Result {
get { return base.Result; }
// expose the setter
set { base.Result = value; }
}
}
FakeTest testClass1;
FakeTest testClass2;
FakeTest testClass3;
TestCollection testCollection;
bool testClassesResultChanged;
[SetUp]
public void Init()
{
testClassesResultChanged = false;
testCollection = new TestCollection();
// TestClass1.
testClass1 = new FakeTest();
testCollection.Add(testClass1);
// TestClass2.
testClass2 = new FakeTest();
testCollection.Add(testClass2);
// TestClass3.
testClass3 = new FakeTest();
testCollection.Add(testClass3);
testCollection.PropertyChanged += testCollection_PropertyChanged;
}
[Test]
public void InitialTestResult()
{
Assert.AreEqual(TestResultType.None, testCollection.CompositeResult);
}
[Test]
public void TestClass1Fails()
{
testClass1.Result = TestResultType.Failure;
Assert.AreEqual(TestResultType.Failure, testCollection.CompositeResult);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void ResetAfterTestClass1Failed()
{
TestClass1Fails();
foreach (var test in testCollection)
test.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testClass1.Result);
}
[Test]
public void AllTestClassesPass()
{
testClass1.Result = TestResultType.Success;
testClass2.Result = TestResultType.Success;
testClass3.Result = TestResultType.Success;
Assert.AreEqual(TestResultType.Success, testCollection.CompositeResult);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void ResetAfterAllPassed()
{
AllTestClassesPass();
foreach (var test in testCollection)
test.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testClass1.Result);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void AllTestClassesIgnored()
{
testClass1.Result = TestResultType.Ignored;
testClass2.Result = TestResultType.Ignored;
testClass3.Result = TestResultType.Ignored;
Assert.AreEqual(TestResultType.Ignored, testCollection.CompositeResult);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void ResetAfterAllTestClasssIgnored()
{
AllTestClassesIgnored();
testClassesResultChanged = false;
foreach (var test in testCollection)
test.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testClass1.Result);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void TestClass1Removed()
{
testCollection.Remove(testClass1);
testClass1.Result = TestResultType.Failure;
InitialTestResult();
Assert.IsFalse(testClassesResultChanged);
}
[Test]
public void TestClassesResultSetToNoneAfterAllTestClassesIgnored()
{
AllTestClassesIgnored();
testClassesResultChanged = false;
testClass1.Result = TestResultType.None;
testClass2.Result = TestResultType.None;
testClass3.Result = TestResultType.None;
InitialTestResult();
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void AddTestFailureClassAfterAllTestsPassed()
{
AllTestClassesPass();
FakeTest testClass4 = new FakeTest();
testClass4.Result = TestResultType.Failure;
testCollection.Add(testClass4);
Assert.AreEqual(TestResultType.Failure, testCollection.CompositeResult);
}
[Test]
public void TestClass1RemovedAfterSetToIgnored()
{
testClass1.Result = TestResultType.Ignored;
testCollection.Remove(testClass1);
InitialTestResult();
}
void testCollection_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "CompositeResult") {
testClassesResultChanged = true;
}
}
}
}

87
src/AddIns/Analysis/UnitTesting/Test/Project/TestMethodsInBaseClassTestFixture.cs

@ -1,6 +1,7 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
@ -29,97 +30,65 @@ namespace UnitTesting.Tests.Project
/// ///
/// RootNamespace.DerivedClass.BaseClassMethod /// RootNamespace.DerivedClass.BaseClassMethod
/// </summary> /// </summary>
[TestFixture, Ignore("Inherited tests not implemented")] [TestFixture]
public class TestMethodsInBaseClassTestFixture public class TestMethodsInBaseClassTestFixture : NUnitTestProjectFixtureBase
{ {
/* NUnitTestClass testClass;
TestClass testClass;
MockClass c;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp] public override void SetUp()
public void SetUp()
{ {
MockProjectContent projectContent = new MockProjectContent(); base.SetUp();
// Create the base test class. AddCodeFileInNamespace("base.cs", @"
MockClass baseClass = new MockClass(projectContent, "RootNamespace.TestFixtureBase"); [TestFixture] class TestFixtureBase {
baseClass.Attributes.Add(new MockAttribute("TestFixture")); [Test] public void BaseMethod() {}
MockMethod baseMethod = new MockMethod(baseClass, "BaseMethod"); }");
baseMethod.Attributes.Add(new MockAttribute("Test")); AddCodeFileInNamespace("derived.cs", @"
baseClass.Methods.Add(baseMethod); [TestFixture] class MyTestFixture : TestFixtureBase {
[Test] public void DerivedMethod() {}
// Create the derived test class. }");
c = new MockClass(projectContent, "RootNamespace.MyTestFixture"); testClass = testProject.GetTestClass(new FullTypeName("RootNamespace.MyTestFixture"));
c.Attributes.Add(new MockAttribute("TestFixture")); testClass.EnsureNestedTestsInitialized();
MockMethod method = new MockMethod(c, "DerivedMethod");
method.Attributes.Add(new MockAttribute("Test"));
c.Methods.Add(method);
projectContent.Classes.Add(c);
// Set derived class's base class.
c.AddBaseClass(baseClass);
// Create TestClass.
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testClass = new TestClass(c, testFrameworks);
} }
[Test] [Test]
public void TwoTestMethods() public void TwoTestMethods()
{ {
Assert.AreEqual(2, testClass.Members.Count); Assert.AreEqual(2, testClass.NestedTests.Count);
} }
[Test] [Test]
public void DerivedMethod() public void DerivedMethod()
{ {
Assert.IsTrue(testClass.Members.Contains("DerivedMethod")); Assert.IsNotNull(testClass.FindTestMethod("DerivedMethod"));
} }
[Test] [Test]
public void BaseMethod() public void BaseMethod()
{ {
Assert.IsTrue(testClass.Members.Contains("TestFixtureBase.BaseMethod")); Assert.IsNotNull(testClass.FindTestMethod("TestFixtureBase.BaseMethod"));
} }
/// <summary>
/// The TestMethod.Method property should return an IMethod
/// that returns the derived class from the DeclaringType property
/// and not the base class. This ensures that the correct
/// test is run when selected in the unit test tree.
/// </summary>
[Test] [Test]
public void BaseMethodDeclaringTypeIsDerivedClass() public void FindTestMethodDoesNotReturnBaseMethodIfUsingShortName()
{ {
TestMember method = testClass.Members["TestFixtureBase.BaseMethod"]; Assert.IsNull(testClass.FindTestMethod("BaseMethod"));
Assert.AreEqual(c, method.Member.DeclaringType);
} }
[Test] [Test]
public void UpdateTestResultUsingPrefixBaseClassName() public void FindTestMethodWithShortNameCanFindBaseMethod()
{ {
TestClassCollection testClasses = new TestClassCollection(); Assert.IsNotNull(testClass.FindTestMethodWithShortName("BaseMethod"));
testClasses.Add(testClass);
TestResult testResult = new TestResult("RootNamespace.MyTestFixture.TestFixtureBase.BaseMethod");
testResult.ResultType = TestResultType.Failure;
testClasses.UpdateTestResult(testResult);
Assert.AreEqual(TestResultType.Failure, testClass.Result);
} }
[Test] [Test]
public void UpdateTestResult() public void UpdateTestResultUsingPrefixBaseClassName()
{ {
TestClassCollection testClasses = new TestClassCollection(); TestResult testResult = new TestResult("RootNamespace.MyTestFixture.TestFixtureBase.BaseMethod");
testClasses.Add(testClass);
TestResult testResult = new TestResult("RootNamespace.MyTestFixture.BaseMethod");
testResult.ResultType = TestResultType.Failure; testResult.ResultType = TestResultType.Failure;
testClasses.UpdateTestResult(testResult); testProject.UpdateTestResult(testResult);
Assert.AreEqual(TestResultType.Failure, testClass.Result); Assert.AreEqual(TestResultType.Failure, testClass.Result);
}*/ }
} }
} }

115
src/AddIns/Analysis/UnitTesting/Test/Project/TestProjectWithOneClassTestFixture.cs

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.CSharp.TypeSystem; using ICSharpCode.NRefactory.CSharp.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
@ -18,51 +19,51 @@ namespace UnitTesting.Tests.Project
/// Creates a TestProject that has one test class. /// Creates a TestProject that has one test class.
/// </summary> /// </summary>
[TestFixture] [TestFixture]
public class TestProjectWithOneClassTestFixture : ProjectTestFixtureBase public class TestProjectWithOneClassTestFixture : NUnitTestProjectFixtureBase
{ {
TestClass testClass; NUnitTestClass testClass;
bool resultChangedCalled; List<NUnitTestClass> classesAdded;
List<TestClass> classesAdded; List<NUnitTestClass> classesRemoved;
List<TestClass> classesRemoved;
const string mainFileName = "file1.cs"; const string mainFileName = "file1.cs";
[SetUp] public override void SetUp()
public void Init()
{ {
resultChangedCalled = false; base.SetUp();
classesAdded = new List<TestClass>(); classesAdded = new List<NUnitTestClass>();
classesRemoved = new List<TestClass>(); classesRemoved = new List<NUnitTestClass>();
// Create a project. // Create a project.
CreateNUnitProject(Parse(@"using NUnit.Framework; AddCodeFile(mainFileName, @"using NUnit.Framework;
namespace RootNamespace { namespace RootNamespace {
[TestFixture] [TestFixture]
class MyTestFixture { class MyTestFixture {
} }
class NonTestClass { } class NonNUnitTestClass { }
}", mainFileName)); }");
testClass = testProject.TestClasses[0]; testClass = testProject.GetTestClass(new FullTypeName("RootNamespace.MyTestFixture"));
testProject.NestedTests.CollectionChanged += testProject_TestClasses_CollectionChanged;
} }
[Test] [Test]
public void OneTestClass() public void OneNUnitTestClass()
{ {
Assert.AreEqual(1, testProject.TestClasses.Count); Assert.AreEqual(1, testProject.NestedTests.Count);
Assert.AreSame(testClass, testProject.NestedTests.Single());
} }
[Test] [Test]
public void TestClassName() public void NUnitTestClassName()
{ {
Assert.AreEqual("MyTestFixture", testClass.Name); Assert.AreEqual("MyTestFixture", testClass.ClassName);
} }
[Test] [Test]
public void TestClassQualifiedName() public void NUnitTestClassQualifiedName()
{ {
Assert.AreEqual("RootNamespace.MyTestFixture", testClass.QualifiedName); Assert.AreEqual("RootNamespace.MyTestFixture", testClass.ReflectionName);
} }
[Test] [Test]
@ -72,28 +73,15 @@ namespace RootNamespace {
} }
[Test] [Test]
public void FindTestClass() public void TestClassIsInProjectNestedTestsCollection()
{ {
Assert.AreSame(testClass, testProject.GetTestClass("RootNamespace.MyTestFixture")); Assert.AreSame(testClass, testProject.NestedTests.Single());
} }
[Test] [Test]
public void NoMatchingTestClass() public void NoMatchingNUnitTestClass()
{ {
Assert.IsNull(testProject.GetTestClass("NoSuchClass.MyTestFixture")); Assert.IsNull(testProject.GetTestClass(new FullTypeName("NoSuchClass.MyTestFixture")));
}
[Test]
public void TestClassResultChanged()
{
try {
testClass.TestResultChanged += ResultChanged;
testClass.TestResult = TestResultType.Success;
} finally {
testClass.TestResultChanged -= ResultChanged;
}
Assert.IsTrue(resultChangedCalled);
} }
/// <summary> /// <summary>
@ -103,17 +91,17 @@ namespace RootNamespace {
[Test] [Test]
public void NewClassInParserInfo() public void NewClassInParserInfo()
{ {
UpdateCodeFile(@"using NUnit.Framework; UpdateCodeFile(mainFileName, @"using NUnit.Framework;
namespace RootNamespace { namespace RootNamespace {
[TestFixture] [TestFixture]
class MyTestFixture { } class MyTestFixture { }
[TestFixture] [TestFixture]
class MyNewTestFixture { } class MyNewTestFixture { }
}", mainFileName); }");
Assert.IsNotNull(testProject.GetTestClass("RootNamespace.MyNewTestFixture")); Assert.IsNotNull(testProject.GetTestClass(new TopLevelTypeName("RootNamespace.MyNewTestFixture")));
Assert.AreEqual(1, classesAdded.Count); Assert.AreEqual(1, classesAdded.Count);
Assert.AreEqual("RootNamespace.MyNewTestFixture", classesAdded[0].QualifiedName); Assert.AreEqual("RootNamespace.MyNewTestFixture", classesAdded[0].ReflectionName);
} }
/// <summary> /// <summary>
@ -124,15 +112,15 @@ namespace RootNamespace {
/// added to our TestProject. /// added to our TestProject.
/// </summary> /// </summary>
[Test] [Test]
public void TestClassInNewCompilationUnitOnly() public void NUnitTestClassInNewCompilationUnitOnly()
{ {
UpdateCodeFile(@"using NUnit.Framework; AddCodeFile("file2.cs", @"using NUnit.Framework;
namespace RootNamespace { namespace RootNamespace {
[TestFixture] [TestFixture]
class MyTestFixture { } class MyTestFixture { }
}", "file2.cs"); }");
Assert.IsNotNull(testProject.GetTestClass("RootNamespace.MyTestFixture")); Assert.IsNotNull(testProject.GetTestClass(new TopLevelTypeName("RootNamespace.MyTestFixture")));
Assert.AreEqual(0, classesAdded.Count); Assert.AreEqual(0, classesAdded.Count);
} }
@ -143,26 +131,26 @@ namespace RootNamespace {
[Test] [Test]
public void NewClassInParserInfoWithoutTestFixtureAttribute() public void NewClassInParserInfoWithoutTestFixtureAttribute()
{ {
UpdateCodeFile(@"using NUnit.Framework; UpdateCodeFile(mainFileName, @"using NUnit.Framework;
namespace RootNamespace { namespace RootNamespace {
[TestFixture] [TestFixture]
class MyTestFixture { } class MyTestFixture { }
class SecondNonTestClass { } class SecondNonNUnitTestClass { }
}", mainFileName); }");
Assert.IsNull(testProject.GetTestClass("RootNamespace.MyNewTestFixture")); Assert.IsNull(testProject.GetTestClass(new TopLevelTypeName("RootNamespace.MyNewTestFixture")));
} }
[Test] [Test]
public void TestClassRemovedInParserInfo() public void NUnitTestClassRemovedInParserInfo()
{ {
UpdateCodeFile(@"using NUnit.Framework; UpdateCodeFile(mainFileName, @"using NUnit.Framework;
namespace RootNamespace { namespace RootNamespace {
class NonTestClass { } class NonNUnitTestClass { }
}", mainFileName); }");
Assert.AreEqual(0, testProject.TestClasses.Count); Assert.AreEqual(0, testProject.NestedTests.Count);
Assert.AreEqual(1, classesRemoved.Count); Assert.AreEqual(1, classesRemoved.Count);
Assert.AreSame(testClass, classesRemoved[0]); Assert.AreSame(testClass, classesRemoved[0]);
} }
@ -172,13 +160,13 @@ namespace RootNamespace {
{ {
RemoveCodeFile(mainFileName); RemoveCodeFile(mainFileName);
Assert.AreEqual(0, testProject.TestClasses.Count); Assert.AreEqual(0, testProject.NestedTests.Count);
Assert.AreEqual(1, classesRemoved.Count); Assert.AreEqual(1, classesRemoved.Count);
Assert.AreSame(testClass, classesRemoved[0]); Assert.AreSame(testClass, classesRemoved[0]);
} }
/// <summary> /// <summary>
/// Tests that a new method is added to the TestClass /// Tests that a new method is added to the NUnitTestClass
/// from the parse info. Also checks that the test method is /// from the parse info. Also checks that the test method is
/// taken from the CompoundClass via IClass.GetCompoundClass. /// taken from the CompoundClass via IClass.GetCompoundClass.
/// A CompoundClass combines partial classes into one class so /// A CompoundClass combines partial classes into one class so
@ -187,27 +175,22 @@ namespace RootNamespace {
[Test] [Test]
public void NewMethodInParserInfo() public void NewMethodInParserInfo()
{ {
UpdateCodeFile(@"using NUnit.Framework; UpdateCodeFile(mainFileName, @"using NUnit.Framework;
namespace RootNamespace { namespace RootNamespace {
[TestFixture] [TestFixture]
class MyTestFixture { class MyTestFixture {
[Test] public void NewMethod() {} [Test] public void NewMethod() {}
}", mainFileName); }}");
Assert.AreEqual("NewMethod", testClass.Members.Single().Name); Assert.AreEqual("NewMethod", testClass.NestedTests.Single().DisplayName);
}
void ResultChanged(object source, EventArgs e)
{
resultChangedCalled = true;
} }
void testProject_TestClasses_CollectionChanged(object source, NotifyCollectionChangedEventArgs e) void testProject_TestClasses_CollectionChanged(object source, NotifyCollectionChangedEventArgs e)
{ {
if (e.Action == NotifyCollectionChangedAction.Add) if (e.Action == NotifyCollectionChangedAction.Add)
classesAdded.AddRange(e.NewItems.Cast<TestClass>()); classesAdded.AddRange(e.NewItems.Cast<NUnitTestClass>());
else if (e.Action == NotifyCollectionChangedAction.Remove) else if (e.Action == NotifyCollectionChangedAction.Remove)
classesRemoved.AddRange(e.OldItems.Cast<TestClass>()); classesRemoved.AddRange(e.OldItems.Cast<NUnitTestClass>());
} }
} }
} }

173
src/AddIns/Analysis/UnitTesting/Test/Project/ThreeTestClassesTestResultsTestFixture.cs

@ -1,173 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/*
/// <summary>
/// Creates a TestClassCollection with three test classes.
/// </summary>
[TestFixture]
public class ThreeTestClassesTestResultsTestFixture
{
TestClass testClass1;
TestClass testClass2;
TestClass testClass3;
bool testClassesResultChanged;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
{
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testClassesResultChanged = false;
testClasses = new TestClassCollection();
// TestClass1.
MockClass mockClass = new MockClass("TestClass1");
testClass1 = new TestClass(mockClass, testFrameworks);
testClasses.Add(testClass1);
// TestClass2.
mockClass = new MockClass("TestClass2");
testClass2 = new TestClass(mockClass, testFrameworks);
testClasses.Add(testClass2);
// TestClass3.
mockClass = new MockClass("TestClass3");
testClass3 = new TestClass(mockClass, testFrameworks);
testClasses.Add(testClass3);
testClasses.ResultChanged += TestClassesResultChanged;
}
[Test]
public void InitialTestResult()
{
Assert.AreEqual(TestResultType.None, testClasses.Result);
}
[Test]
public void TestClass1Fails()
{
testClass1.TestResult = TestResultType.Failure;
Assert.AreEqual(TestResultType.Failure, testClasses.Result);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void ResetAfterTestClass1Failed()
{
TestClass1Fails();
testClasses.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testClass1.TestResult);
}
[Test]
public void AllTestClassesPass()
{
testClass1.TestResult = TestResultType.Success;
testClass2.TestResult = TestResultType.Success;
testClass3.TestResult = TestResultType.Success;
Assert.AreEqual(TestResultType.Success, testClasses.Result);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void ResetAfterAllPassed()
{
AllTestClassesPass();
testClasses.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testClass1.TestResult);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void AllTestClassesIgnored()
{
testClass1.TestResult = TestResultType.Ignored;
testClass2.TestResult = TestResultType.Ignored;
testClass3.TestResult = TestResultType.Ignored;
Assert.AreEqual(TestResultType.Ignored, testClasses.Result);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void ResetAfterAllTestClasssIgnored()
{
AllTestClassesIgnored();
testClassesResultChanged = false;
testClasses.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testClass1.TestResult);
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void TestClass1Removed()
{
testClasses.Remove(testClass1);
testClass1.TestResult = TestResultType.Failure;
InitialTestResult();
Assert.IsFalse(testClassesResultChanged);
}
[Test]
public void TestClassesResultSetToNoneAfterAllTestClassesIgnored()
{
AllTestClassesIgnored();
testClassesResultChanged = false;
testClass1.TestResult = TestResultType.None;
testClass2.TestResult = TestResultType.None;
testClass3.TestResult = TestResultType.None;
InitialTestResult();
Assert.IsTrue(testClassesResultChanged);
}
[Test]
public void AddTestFailureClassAfterAllTestsPassed()
{
AllTestClassesPass();
MockClass mockClass = new MockClass("TestClass4");
TestClass testClass4 = new TestClass(mockClass, testFrameworks);
testClass4.TestResult = TestResultType.Failure;
testClasses.Add(testClass4);
Assert.AreEqual(TestResultType.Failure, testClasses.Result);
}
[Test]
public void TestClass1RemovedAfterSetToIgnored()
{
testClass1.TestResult = TestResultType.Ignored;
testClasses.Remove(testClass1);
InitialTestResult();
}
void TestClassesResultChanged(object source, EventArgs e)
{
testClassesResultChanged = true;
}
}
*/
}

156
src/AddIns/Analysis/UnitTesting/Test/Project/ThreeTestMethodsTestResultsTestFixture.cs

@ -1,156 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Linq;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// Creates a TestMethodCollection with three TestMethods.
/// </summary>
[TestFixture]
public class ThreeTestMethodsTestResultsTestFixture : ProjectTestFixtureBase
{
TestClass testClass;
TestMember testMethod1;
TestMember testMethod2;
TestMember testMethod3;
bool testMethodsResultChanged;
[SetUp]
public void Init()
{
testMethodsResultChanged = false;
testClass = new TestClass(MockClass.CreateMockClassWithoutAnyAttributes(), new NUnitTestFramework());
testClass.Members.Add(new TestMember(MockMethod.CreateUnresolvedMethod("TestMethod1")));
testClass.Members.Add(new TestMember(MockMethod.CreateUnresolvedMethod("TestMethod2")));
testClass.Members.Add(new TestMember(MockMethod.CreateUnresolvedMethod("TestMethod3")));
testClass.TestResultChanged += TestMethodsResultChanged;
}
[Test]
public void InitialTestResult()
{
Assert.AreEqual(TestResultType.None, testClass.TestResult);
}
[Test]
public void TestMethod1Fails()
{
testMethod1.TestResult = TestResultType.Failure;
Assert.AreEqual(TestResultType.Failure, testClass.TestResult);
Assert.IsTrue(testMethodsResultChanged);
}
[Test]
public void ResetAfterTestMethod1Failed()
{
TestMethod1Fails();
testClass.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testMethod1.TestResult);
}
[Test]
public void AllTestMethodsPass()
{
testMethod1.TestResult = TestResultType.Success;
testMethod2.TestResult = TestResultType.Success;
testMethod3.TestResult = TestResultType.Success;
Assert.AreEqual(TestResultType.Success, testClass.TestResult);
Assert.IsTrue(testMethodsResultChanged);
}
[Test]
public void ResetAfterAllPassed()
{
AllTestMethodsPass();
testClass.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testMethod1.TestResult);
Assert.IsTrue(testMethodsResultChanged);
}
[Test]
public void AllTestMethodsIgnored()
{
testMethod1.TestResult = TestResultType.Ignored;
testMethod2.TestResult = TestResultType.Ignored;
testMethod3.TestResult = TestResultType.Ignored;
Assert.AreEqual(TestResultType.Ignored, testClass.TestResult);
Assert.IsTrue(testMethodsResultChanged);
}
[Test]
public void ResetAfterAllTestMethodsIgnored()
{
AllTestMethodsIgnored();
testMethodsResultChanged = false;
testClass.ResetTestResults();
InitialTestResult();
Assert.AreEqual(TestResultType.None, testMethod1.TestResult);
Assert.IsTrue(testMethodsResultChanged);
}
[Test]
public void TestMethod1Removed()
{
testClass.Members.Remove(testMethod1);
testMethod1.TestResult = TestResultType.Failure;
InitialTestResult();
Assert.IsFalse(testMethodsResultChanged);
}
[Test]
public void TestMethodsResultSetToNoneAfterAllTestClasssIgnored()
{
AllTestMethodsIgnored();
testMethodsResultChanged = false;
testMethod1.TestResult = TestResultType.None;
testMethod2.TestResult = TestResultType.None;
testMethod3.TestResult = TestResultType.None;
InitialTestResult();
Assert.IsTrue(testMethodsResultChanged);
}
[Test]
public void TestMethod1RemovedAfterSetToIgnored()
{
testMethod1.TestResult = TestResultType.Ignored;
testClass.Members.Remove(testMethod1);
InitialTestResult();
}
[Test]
public void AddTestFailureAfterAllTestsPassed()
{
AllTestMethodsPass();
testClass.Members.Add(new TestMember(MockMethod.CreateUnresolvedMethod("TestMethod4")));
Assert.AreEqual(TestResultType.Failure, testClass.TestResult);
}
void TestMethodsResultChanged(object source, EventArgs e)
{
testMethodsResultChanged = true;
}
}
}

96
src/AddIns/Analysis/UnitTesting/Test/Project/TwoBaseClassesWithTestMethodsTestFixture.cs

@ -1,96 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using System;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
/// <summary>
/// Tests that the test methods of a second parent base class are detected:
///
/// class BaseBaseTestFixture { [Test] public void BaseBaseTest() ... }
/// class BaseTestFixture : BaseBaseTestFixture ...
/// class TestFixture : BaseTestFixture
/// </summary>
[TestFixture, Ignore("Test inheritance not implemented")]
public class TwoBaseClassesWithTestMethodsTestFixture
{
/*
TestClass testClass;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void SetUp()
{
MockProjectContent projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
// Create the top base test class.
MockClass baseBaseClass = new MockClass(projectContent, "ICSharpCode.SharpDevelop.Tests.BaseBaseTestFixture");
MockMethod baseMethod = new MockMethod(baseBaseClass, "BaseBaseTest");
baseMethod.Attributes.Add(new MockAttribute("Test"));
baseBaseClass.Methods.Add(baseMethod);
// Create the next level test class.
MockClass baseClass = new MockClass(projectContent, "ICSharpCode.SharpDevelop.Tests.BaseTestFixture");
baseMethod = new MockMethod(baseClass, "BaseTest");
baseMethod.Attributes.Add(new MockAttribute("Test"));
baseClass.Methods.Add(baseMethod);
// Create the derived test class.
c = new MockClass(projectContent, "ICSharpCode.SharpDevelop.Tests.MainTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
projectContent.Classes.Add(c);
// Set the base class for each class in the hierarchy.
c.AddBaseClass(baseClass);
baseClass.AddBaseClass(baseBaseClass);
// Create TestClass.
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testClass = new TestClass(c, testFrameworks);
}
[Test]
public void BaseBaseTestMethodExists()
{
Assert.IsTrue(testClass.Members.Contains("BaseBaseTestFixture.BaseBaseTest"));
}
[Test]
public void BaseMethodExists()
{
Assert.IsTrue(testClass.Members.Contains("BaseTestFixture.BaseTest"));
}
/// <summary>
/// The TestMethod.Method property should return an IMethod
/// that returns the derived class from the DeclaringType property
/// and not the base class. This ensures that the correct
/// test is run when selected in the unit test tree.
/// </summary>
[Test]
public void BaseBaseMethodDeclaringTypeIsDerivedClass()
{
TestMember method = testClass.Members["BaseBaseTestFixture.BaseBaseTest"];
Assert.AreEqual(c, method.Member.DeclaringType);
}
[Test]
public void UpdateTestResult()
{
TestClassCollection testClasses = new TestClassCollection();
testClasses.Add(testClass);
TestResult testResult = new TestResult("ICSharpCode.SharpDevelop.Tests.MainTestFixture.BaseBaseTest");
testResult.ResultType = TestResultType.Failure;
testClasses.UpdateTestResult(testResult);
Assert.AreEqual(TestResultType.Failure, testClass.TestResult);
}*/
}
}

117
src/AddIns/Analysis/UnitTesting/Test/Project/TwoProjectRootNamespacesTestFixture.cs

@ -1,6 +1,7 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System.Linq;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting; using ICSharpCode.UnitTesting;
using NUnit.Framework; using NUnit.Framework;
@ -10,125 +11,57 @@ using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project namespace UnitTesting.Tests.Project
{ {
[TestFixture] [TestFixture]
public class TwoRootNamespacesTestFixture public class TwoRootNamespacesTestFixture : NUnitTestProjectFixtureBase
{ {
/* public override void SetUp()
TestProject testProject;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
{ {
// Create a project to display in the test tree view. base.SetUp();
IProject project = new MockCSharpProject();
project.Name = "TestProject"; AddCodeFile("ns1.cs", @"using NUnit.Framework;
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project); namespace RootNamespace {
nunitFrameworkReferenceItem.Include = "NUnit.Framework"; [TestFixture] class MyTestFixture1 {}
ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem); }");
AddCodeFile("ns2.cs", @"using NUnit.Framework;
// Add a test class with a TestFixture attributes. namespace RootNamespace2 {
projectContent = new MockProjectContent(); [TestFixture] class MyTestFixture2 {}
projectContent.Language = LanguageProperties.None; }");
MockClass c = new MockClass(projectContent, "RootNamespace1.MyTestFixture1"); testProject.EnsureNestedTestsInitialized();
c.Attributes.Add(new MockAttribute("TestFixture"));
projectContent.Classes.Add(c);
// Add a second class with a different root namespace.
c = new MockClass(projectContent, "RootNamespace2.MyTestFixture2");
c.Attributes.Add(new MockAttribute("TestFixture"));
projectContent.Classes.Add(c);
testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
testProject = new TestProject(project, projectContent, testFrameworks);
} }
[Test] [Test]
public void TwoRootNamespaces() public void TwoRootNamespaces()
{ {
Assert.AreEqual(2, testProject.RootNamespaces.Count); Assert.AreEqual(2, testProject.NestedTests.Count);
} }
[Test] [Test]
public void RootNamespace1() public void RootNamespace1()
{ {
Assert.AreEqual("RootNamespace1", testProject.RootNamespaces[0]); // first root namespace is the project root namespace, so the
// class is added directly
var c = (NUnitTestClass)testProject.NestedTests.First();
Assert.AreEqual("MyTestFixture1", c.ClassName);
} }
[Test] [Test]
public void RootNamespace2() public void RootNamespace2()
{ {
Assert.AreEqual("RootNamespace2", testProject.RootNamespaces[1]); var ns = (TestNamespace)testProject.NestedTests.ElementAt(1);
} Assert.AreEqual("RootNamespace2", ns.NamespaceName);
[Test]
public void OneClassInNamespace1()
{
Assert.AreEqual(1, testProject.GetTestClasses("RootNamespace1").Length);
}
[Test]
public void ClassNameInNamespace1()
{
TestClass[] classes = testProject.GetTestClasses("RootNamespace1");
Assert.AreEqual("MyTestFixture1", classes[0].Name);
} }
[Test] [Test]
public void OneClassInNamespace2() public void OneClassInNamespace2()
{ {
Assert.AreEqual(1, testProject.GetTestClasses("RootNamespace2").Length); var ns = (TestNamespace)testProject.NestedTests.ElementAt(1);
Assert.AreEqual(1, ns.NestedTests.Count);
} }
[Test] [Test]
public void ClassNameInNamespace2() public void ClassNameInNamespace2()
{ {
TestClass[] classes = testProject.GetTestClasses("RootNamespace2"); var ns = (TestNamespace)testProject.NestedTests.ElementAt(1);
Assert.AreEqual("MyTestFixture2", classes[0].Name); Assert.AreEqual("MyTestFixture2", ns.NestedTests.Single().DisplayName);
}
[Test]
public void TwoClassesStartWithRootNamespace()
{
TestClass[] classes = testProject.GetAllTestClasses("RootNamespace");
Assert.AreEqual(2, classes.Length);
Assert.AreEqual("MyTestFixture1", classes[0].Name);
Assert.AreEqual("MyTestFixture2", classes[1].Name);
}
[Test]
public void NoChildNamespaces()
{
Assert.AreEqual(0, testProject.GetChildNamespaces("RootNamespace").Length);
} }
[Test]
public void TwoChildNamespacesForEmptyNamespace()
{
string[] namespaces = testProject.GetChildNamespaces(String.Empty);
Assert.AreEqual(2, namespaces.Length);
Assert.AreEqual("RootNamespace1", namespaces[0]);
Assert.AreEqual("RootNamespace2", namespaces[1]);
}
/// <summary>
/// Makes sure that the fully qualified class name is used
/// when working out the overall test result in the
/// TestClassCollection.
/// </summary>
[Test]
public void DuplicateClassName()
{
MockClass c = new MockClass(projectContent, "RootNamespace1.MyTestFixture2");
c.Attributes.Add(new MockAttribute("TestFixture"));
TestClass testClass = new TestClass(c, testFrameworks);
testProject.TestClasses.Add(testClass);
testClass.TestResult = TestResultType.Failure;
TestClass testClass2 = testProject.TestClasses["RootNamespace2.MyTestFixture2"];
testClass2.TestResult = TestResultType.Failure;
Assert.AreEqual(TestResultType.Failure, testProject.TestClasses.Result);
}*/
} }
} }

11
src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj

@ -83,8 +83,19 @@
<Compile Include="Project\DuplicateMethodNameTestFixture.cs" /> <Compile Include="Project\DuplicateMethodNameTestFixture.cs" />
<Compile Include="Project\EmptyProjectTestFixture.cs" /> <Compile Include="Project\EmptyProjectTestFixture.cs" />
<Compile Include="Project\InheritanceHierarchyTestFixture.cs" /> <Compile Include="Project\InheritanceHierarchyTestFixture.cs" />
<Compile Include="Project\InnerClassInTestFixtureTests.cs" />
<Compile Include="Project\InnerClassMethodRenamedTestFixture.cs" />
<Compile Include="Project\InnerClassNameChangesTestFixture.cs" />
<Compile Include="Project\InnerClassTestFixture.cs" />
<Compile Include="Project\InnerClassTestFixtureAttributeRemovedTestFixture.cs" />
<Compile Include="Project\NUnitTestProjectFixtureBase.cs" /> <Compile Include="Project\NUnitTestProjectFixtureBase.cs" />
<Compile Include="Project\OverriddenBaseTestMethodTestFixture.cs" /> <Compile Include="Project\OverriddenBaseTestMethodTestFixture.cs" />
<Compile Include="Project\TestClassWithOneMethodTestFixture.cs" />
<Compile Include="Project\TestClassWithTwoMethodsTestFixture.cs" />
<Compile Include="Project\TestMethodsInBaseClassTestFixture.cs" />
<Compile Include="Project\TestProjectWithOneClassTestFixture.cs" />
<Compile Include="Project\TestCollectionTests.cs" />
<Compile Include="Project\TwoProjectRootNamespacesTestFixture.cs" />
<Compile Include="Service\TestFrameworkDescriptorTests.cs" /> <Compile Include="Service\TestFrameworkDescriptorTests.cs" />
<Compile Include="TestRunner\TestResultsReaderTests.cs" /> <Compile Include="TestRunner\TestResultsReaderTests.cs" />
<Compile Include="UnitTestingOptionsTestFixture.cs" /> <Compile Include="UnitTestingOptionsTestFixture.cs" />

32
src/AddIns/Analysis/UnitTesting/Test/Utils/MockStatusBarService.cs

@ -1,32 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
namespace UnitTesting.Tests.Utils
{
public class MockStatusBarService : IStatusBarService
{
public void SetCaretPosition(int x, int y, int charOffset)
{
throw new NotImplementedException();
}
public void SetMessage(string message, bool highlighted, IImage icon)
{
throw new NotImplementedException();
}
public IProgressMonitor CreateProgressMonitor(System.Threading.CancellationToken cancellationToken)
{
return new DummyProgressMonitor();
}
public void AddProgress(ProgressCollector progress)
{
throw new NotImplementedException();
}
}
}

106
src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFramework.cs

@ -1,106 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
namespace UnitTesting.Tests.Utils
{
public class MockTestFramework : ITestFramework
{
IMember isTestMemberParameterUsed;
List<string> testMembers = new List<string>();
ITypeDefinition isTestClassParameterUsed;
List<string> testClasses = new List<string>();
IProject isTestProjectParameterUsed;
List<IProject> testProjects = new List<IProject>();
List<MockTestRunner> testRunnersCreated = new List<MockTestRunner>();
List<MockTestRunner> testDebuggersCreated = new List<MockTestRunner>();
bool buildNeededBeforeTestRun = true;
public MockTestFramework()
{
}
public bool IsTestMember(IMember member)
{
isTestMemberParameterUsed = member;
return testMembers.Contains(member.ReflectionName);
}
public IEnumerable<TestMember> GetTestMembersFor(ITypeDefinition @class) {
throw new NotImplementedException();
}
public IMember IsTestMemberParameterUsed {
get { return isTestMemberParameterUsed; }
}
public void AddTestMember(string reflectionName)
{
testMembers.Add(reflectionName);
}
public bool IsTestClass(ITypeDefinition c)
{
isTestClassParameterUsed = c;
return testClasses.Contains(c.ReflectionName);
}
public ITypeDefinition IsTestClassParameterUsed {
get { return isTestClassParameterUsed; }
}
public void AddTestClass(string reflectionName)
{
testClasses.Add(reflectionName);
}
public bool IsTestProject(IProject project)
{
isTestProjectParameterUsed = project;
return testProjects.Contains(project);
}
public IProject IsTestProjectParameterUsed {
get { return isTestProjectParameterUsed; }
}
public void AddTestProject(IProject project)
{
testProjects.Add(project);
}
public ITestRunner CreateTestRunner()
{
MockTestRunner testRunner = new MockTestRunner();
testRunnersCreated.Add(testRunner);
return testRunner;
}
public List<MockTestRunner> TestRunnersCreated {
get { return testRunnersCreated; }
}
public ITestRunner CreateTestDebugger()
{
MockTestRunner testRunner = new MockTestRunner();
testDebuggersCreated.Add(testRunner);
return testRunner;
}
public List<MockTestRunner> TestDebuggersCreated {
get { return testDebuggersCreated; }
}
public bool IsBuildNeededBeforeTestRun {
get { return buildNeededBeforeTestRun; }
set { buildNeededBeforeTestRun = value; }
}
}
}

43
src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFrameworkFactory.cs

@ -1,43 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.UnitTesting;
namespace UnitTesting.Tests.Utils
{
public class MockTestFrameworkFactory : ITestFrameworkFactory
{
Dictionary<string, ITestFramework> frameworks = new Dictionary<string, ITestFramework>();
List<string> classNames = new List<string>();
public void Add(string className, ITestFramework framework)
{
frameworks.Add(className, framework);
}
public ITestFramework Create(string className)
{
classNames.Add(className);
ITestFramework framework;
if (frameworks.TryGetValue(className, out framework)) {
return framework;
}
return null;
}
public List<string> ClassNamesPassedToCreateMethod {
get { return classNames; }
}
public MockTestFramework AddFakeTestFramework(string className)
{
var testFramework = new MockTestFramework();
Add(className, testFramework);
return testFramework;
}
}
}

32
src/AddIns/Analysis/UnitTesting/Test/Utils/MockTestFrameworksWithNUnitFrameworkSupport.cs

@ -1,32 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
namespace UnitTesting.Tests.Utils
{
public class MockTestFrameworksWithNUnitFrameworkSupport : NUnitTestFramework, IRegisteredTestFrameworks
{
public ITestFramework GetTestFrameworkForProject(IProject project)
{
throw new NotImplementedException();
}
public ITestRunner CreateTestRunner(IProject project)
{
throw new NotImplementedException();
}
public ITestRunner CreateTestDebugger(IProject project)
{
throw new NotImplementedException();
}
public bool IsBuildNeededBeforeTestRunForProject(IProject project)
{
throw new NotImplementedException();
}
}
}

80
src/AddIns/Analysis/UnitTesting/Test/Utils/MockUnitTestWorkbench.cs

@ -1,80 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.UnitTesting;
using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Utils
{
public struct ActionArguments<T> {
public Action<T> Action;
public T Arg;
}
public class MockUnitTestWorkbench : IUnitTestWorkbench
{
public List<Action> SafeThreadAsyncMethodCalls = new List<Action>();
public List<object> SafeThreadAsyncMethodCallsWithArguments =
new List<object>();
public bool MakeSafeThreadAsyncMethodCallsWithArguments;
public bool MakeNonGenericSafeThreadAsyncMethodCalls;
public List<Type> TypesPassedToGetPadMethod = new List<Type>();
public PadDescriptor CompilerMessageViewPadDescriptor;
public PadDescriptor ErrorListPadDescriptor;
List<PadDescriptor> padDescriptors = new List<PadDescriptor>();
public MockUnitTestWorkbench()
{
CompilerMessageViewPadDescriptor = new PadDescriptor(typeof(CompilerMessageView), "Output", String.Empty);
AddPadDescriptor(CompilerMessageViewPadDescriptor);
ErrorListPadDescriptor = new PadDescriptor(typeof(ErrorListPad), "Errors", String.Empty);
AddPadDescriptor(ErrorListPadDescriptor);
}
public void AddPadDescriptor(PadDescriptor padDescriptor)
{
padDescriptors.Add(padDescriptor);
}
public PadDescriptor GetPad(Type type)
{
TypesPassedToGetPadMethod.Add(type);
foreach (PadDescriptor padDescriptor in padDescriptors) {
if (padDescriptor.Class == type.FullName) {
return padDescriptor;
}
}
return null;
}
public void SafeThreadAsyncCall(Action method)
{
SafeThreadAsyncMethodCalls.Add(method);
if (MakeNonGenericSafeThreadAsyncMethodCalls) {
method();
}
}
public void SafeThreadAsyncCall<T>(Action<T> method, T arg)
{
ActionArguments<T> actionArgs = new ActionArguments<T>();
actionArgs.Action = method;
actionArgs.Arg = arg;
SafeThreadAsyncMethodCallsWithArguments.Add(actionArgs);
if (MakeSafeThreadAsyncMethodCallsWithArguments) {
method(arg);
}
}
}
}

74
src/AddIns/Analysis/UnitTesting/Test/Utils/MockUnitTestsPad.cs

@ -1,74 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
namespace UnitTesting.Tests.Utils
{
public class MockUnitTestsPad : IUnitTestsPad
{
bool updateToolbarMethodCalled;
bool bringToFrontMethodCalled;
bool resetTestResultsMethodCalled;
List<IProject> projects = new List<IProject>();
List<TestProject> testProjects = new List<TestProject>();
public bool IsUpdateToolbarMethodCalled {
get { return updateToolbarMethodCalled; }
set { updateToolbarMethodCalled = value; }
}
public void UpdateToolbar()
{
updateToolbarMethodCalled = true;
}
public bool IsBringToFrontMethodCalled {
get { return bringToFrontMethodCalled; }
}
public void BringToFront()
{
bringToFrontMethodCalled = true;
}
public bool IsResetTestResultsMethodCalled {
get { return resetTestResultsMethodCalled; }
}
public void ResetTestResults()
{
resetTestResultsMethodCalled = true;
}
public void AddProject(IProject project)
{
projects.Add(project);
}
public IProject[] GetProjects()
{
return projects.ToArray();
}
public TestProject GetTestProject(IProject project)
{
foreach (TestProject testProject in testProjects) {
if (testProject.Project == project) {
return testProject;
}
}
return null;
}
public void AddTestProject(TestProject testProject)
{
testProjects.Add(testProject);
}
public void CollapseAll() { }
}
}

2
src/Main/Base/Project/Src/Services/ParserService/IParserService.cs

@ -59,7 +59,7 @@ namespace ICSharpCode.SharpDevelop.Parser
/// <remarks> /// <remarks>
/// This method is thread-safe. /// This method is thread-safe.
/// </remarks> /// </remarks>
SharpDevelopSolutionSnapshot GetCurrentSolutionSnapshot(); ISolutionSnapshotWithProjectMapping GetCurrentSolutionSnapshot();
/// <summary> /// <summary>
/// Invalidates the current solution snapshot, causing /// Invalidates the current solution snapshot, causing

2
src/Main/Base/Project/Src/Services/ParserService/SharpDevelopSolutionSnapshot.cs

@ -16,6 +16,8 @@ namespace ICSharpCode.SharpDevelop.Parser
public interface ISolutionSnapshotWithProjectMapping : ISolutionSnapshot public interface ISolutionSnapshotWithProjectMapping : ISolutionSnapshot
{ {
IProject GetProject(IAssembly assembly); IProject GetProject(IAssembly assembly);
ICompilation GetCompilation(IProject project);
} }
public class SharpDevelopSolutionSnapshot : DefaultSolutionSnapshot, ISolutionSnapshotWithProjectMapping public class SharpDevelopSolutionSnapshot : DefaultSolutionSnapshot, ISolutionSnapshotWithProjectMapping

4
src/Main/Base/Project/Src/Services/RefactoringService/FindReferenceService.cs

@ -154,9 +154,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
return results; return results;
} }
static SharpDevelopSolutionSnapshot GetSolutionSnapshot(ICompilation compilation) static ISolutionSnapshotWithProjectMapping GetSolutionSnapshot(ICompilation compilation)
{ {
var snapshot = compilation.SolutionSnapshot as SharpDevelopSolutionSnapshot; var snapshot = compilation.SolutionSnapshot as ISolutionSnapshotWithProjectMapping;
return snapshot ?? SD.ParserService.GetCurrentSolutionSnapshot(); return snapshot ?? SD.ParserService.GetCurrentSolutionSnapshot();
} }

2
src/Main/SharpDevelop/Parser/ParserService.cs

@ -111,7 +111,7 @@ namespace ICSharpCode.SharpDevelop.Parser
// is only browsing code. // is only browsing code.
volatile WeakReference<SharpDevelopSolutionSnapshot> currentSolutionSnapshot; volatile WeakReference<SharpDevelopSolutionSnapshot> currentSolutionSnapshot;
public SharpDevelopSolutionSnapshot GetCurrentSolutionSnapshot() public ISolutionSnapshotWithProjectMapping GetCurrentSolutionSnapshot()
{ {
var weakRef = currentSolutionSnapshot; var weakRef = currentSolutionSnapshot;
SharpDevelopSolutionSnapshot result; SharpDevelopSolutionSnapshot result;

Loading…
Cancel
Save