Browse Source

More UnitTesting.Tests.

newNRvisualizers
Daniel Grunwald 13 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. 28
      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. 115
      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 @@ @@ -1,7 +1,7 @@

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

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

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

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

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

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

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

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

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

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

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
@ -13,14 +14,15 @@ namespace UnitTesting.Tests.Project @@ -13,14 +14,15 @@ namespace UnitTesting.Tests.Project
/// Tests what happens when a test method is renamed inside an inner class.
/// </summary>
[TestFixture]
public class InnerClassMethodRemovedTestFixture : ProjectTestFixtureBase
public class InnerClassMethodRemovedTestFixture : NUnitTestProjectFixtureBase
{
TestClass innerTestClass;
NUnitTestClass innerTestClass;
[SetUp]
public void Init()
public override void SetUp()
{
CreateNUnitProject(Parse(@"
base.SetUp();
AddCodeFile("test.cs", @"
using NUnit.Framework;
namespace MyTests {
class A {
@ -30,13 +32,13 @@ namespace MyTests { @@ -30,13 +32,13 @@ namespace MyTests {
}
}
}
"));
");
// The members should be changed on the existing TestClass instance,
// 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;
namespace MyTests {
class A {
@ -55,20 +57,20 @@ namespace MyTests { @@ -55,20 +57,20 @@ namespace MyTests {
[Test]
public void NewTestMethodExists()
{
TestMember method = innerTestClass.Members[0];
Assert.AreEqual("FooBarRenamed", method.Name);
Assert.Contains("FooBarRenamed", GetTestMethodNames(innerTestClass));
}
[Test]
public void OldTestMethodRemoved()
{
Assert.AreEqual(1, innerTestClass.Members.Count);
Assert.IsFalse(GetTestMethodNames(innerTestClass).Contains("FooBar"));
}
[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 @@ @@ -3,6 +3,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
@ -14,14 +15,14 @@ namespace UnitTesting.Tests.Project @@ -14,14 +15,14 @@ namespace UnitTesting.Tests.Project
/// Tests that the TestProject is correctly updated after the inner class name changes.
/// </summary>
[TestFixture]
public class InnerClassNameChangesTestFixture : ProjectTestFixtureBase
public class InnerClassNameChangesTestFixture : NUnitTestProjectFixtureBase
{
TestClass originalA;
NUnitTestClass originalA;
[SetUp]
public void Init()
public override void SetUp()
{
CreateNUnitProject(Parse(@"
base.SetUp();
AddCodeFile("test.cs", @"
using NUnit.Framework;
namespace MyTests {
class A {
@ -31,11 +32,11 @@ namespace MyTests { @@ -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;
namespace MyTests {
class A {
@ -52,13 +53,13 @@ namespace MyTests { @@ -52,13 +53,13 @@ namespace MyTests {
public void OuterClassNotChanged()
{
Assert.IsNotNull(originalA);
Assert.AreSame(originalA, testProject.GetTestClass("MyTests.A"));
Assert.AreSame(originalA, testProject.GetTestClass(new FullTypeName("MyTests.A")));
}
[Test]
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 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
@ -27,15 +28,15 @@ namespace UnitTesting.Tests.Project @@ -27,15 +28,15 @@ namespace UnitTesting.Tests.Project
/// In this case the FooBar test is identified via: "A+InnerATest.FooBar".
/// </summary>
[TestFixture]
public class InnerClassTestFixture : ProjectTestFixtureBase
public class InnerClassTestFixture : NUnitTestProjectFixtureBase
{
TestClass outerClass;
TestClass innerClass;
NUnitTestClass outerClass;
NUnitTestClass innerClass;
[SetUp]
public void Init()
public override void SetUp()
{
CreateNUnitProject(Parse(@"
base.SetUp();
AddCodeFile("test.cs", @"
using NUnit.Framework;
namespace MyTests {
public class A
@ -48,33 +49,33 @@ namespace MyTests { @@ -48,33 +49,33 @@ namespace MyTests {
}
}
}
}"));
outerClass = testProject.GetTestClass("A");
innerClass = testProject.GetTestClass("A+InnerATest");
}");
outerClass = testProject.GetTestClass(new FullTypeName("MyTests.A"));
innerClass = testProject.GetTestClass(new FullTypeName("MyTests.A+InnerATest"));
}
[Test]
public void OneTestClassFound()
{
Assert.AreEqual(1, testProject.TestClasses.Count);
Assert.AreEqual(1, testProject.NestedTests.Count);
}
[Test]
public void TestClassQualifiedName()
{
Assert.AreEqual("MyTests.A+InnerATest", innerClass.QualifiedName);
Assert.AreEqual("MyTests.A+InnerATest", innerClass.ReflectionName);
}
[Test]
public void TestClassName()
{
Assert.AreEqual("InnerATest", innerClass.Name);
Assert.AreEqual("InnerATest", innerClass.ClassName);
}
[Test]
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 @@ @@ -3,6 +3,7 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
using UnitTesting.Tests.Utils;
@ -13,38 +14,39 @@ namespace UnitTesting.Tests.Project @@ -13,38 +14,39 @@ namespace UnitTesting.Tests.Project
/// Tests that the inner test class is removed when its TestFixture attribute is removed.
/// </summary>
[TestFixture]
public class InnerClassTestFixtureAttributeRemovedTestFixture : ProjectTestFixtureBase
public class InnerClassTestFixtureAttributeRemovedTestFixture : NUnitTestProjectFixtureBase
{
[SetUp]
public void Init()
public override void SetUp()
{
CreateNUnitProject(Parse(@"
base.SetUp();
AddCodeFile("test.cs", @"
using NUnit.Framework;
namespace MyTests {
class A {
[TestFixture]
class Inner {}
}
}"));
}");
testProject.EnsureNestedTestsInitialized();
}
[Test]
public void RemoveAttribute_Leaves_No_TestClasses()
{
UpdateCodeFile(@"
UpdateCodeFile("test.cs", @"
using NUnit.Framework;
namespace MyTests {
class A {
class Inner {}
}
}");
Assert.AreEqual(0, testProject.TestClasses.Count);
Assert.AreEqual(0, testProject.NestedTests.Count);
}
[Test]
public void MoveAttributeToOuterClass()
{
UpdateCodeFile(@"
UpdateCodeFile("test.cs", @"
using NUnit.Framework;
namespace MyTests {
[TestFixture]
@ -52,7 +54,7 @@ namespace MyTests { @@ -52,7 +54,7 @@ namespace MyTests {
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 @@ @@ -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; @@ -14,18 +14,17 @@ using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
[TestFixture]
public class TestClassWithOneMethodTestFixture : ProjectTestFixtureBase
public class TestClassWithOneMethodTestFixture : NUnitTestProjectFixtureBase
{
TestClass testClass;
TestMember testMethod;
NUnitTestClass testClass;
NUnitTestMethod testMethod;
bool resultChangedCalled;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
public override void SetUp()
{
base.SetUp();
resultChangedCalled = false;
CreateNUnitProject(Parse(@"
AddCodeFile("test.cs", @"
using NUnit.Framework;
namespace RootNamespace.Tests {
[TestFixture]
@ -33,15 +32,15 @@ namespace RootNamespace.Tests { @@ -33,15 +32,15 @@ namespace RootNamespace.Tests {
[Test]
public void TestMethod() { }
}
}"));
testClass = testProject.TestClasses.Single();
testMethod = testClass.Members.Single();
}");
testClass = (NUnitTestClass)testProject.NestedTests.Single().NestedTests.Single();
testMethod = (NUnitTestMethod)testClass.NestedTests.Single();
}
[Test]
public void TestMethodResult()
{
Assert.AreEqual(TestResultType.None, testMethod.TestResult);
Assert.AreEqual(TestResultType.None, testMethod.Result);
}
[Test]
@ -52,14 +51,14 @@ namespace RootNamespace.Tests { @@ -52,14 +51,14 @@ namespace RootNamespace.Tests {
testProject.UpdateTestResult(result);
Assert.AreEqual(TestResultType.Failure, testMethod.TestResult);
Assert.AreEqual(TestResultType.Failure, testMethod.Result);
}
[Test]
public void TestClassFailed()
{
TestFailed();
Assert.AreEqual(TestResultType.Failure, testClass.TestResult);
Assert.AreEqual(TestResultType.Failure, testClass.Result);
}
[Test]
@ -70,19 +69,19 @@ namespace RootNamespace.Tests { @@ -70,19 +69,19 @@ namespace RootNamespace.Tests {
testProject.UpdateTestResult(result);
Assert.AreEqual(TestResultType.Ignored, testClass.TestResult);
Assert.AreEqual(TestResultType.Ignored, testClass.Result);
}
[Test]
public void TestResultChanged()
{
try {
testMethod.TestResultChanged += ResultChanged;
testMethod.ResultChanged += ResultChanged;
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod");
result.ResultType = TestResultType.Failure;
testProject.UpdateTestResult(result);
} finally {
testMethod.TestResultChanged -= ResultChanged;
testMethod.ResultChanged -= ResultChanged;
}
Assert.IsTrue(resultChangedCalled);
@ -92,12 +91,12 @@ namespace RootNamespace.Tests { @@ -92,12 +91,12 @@ namespace RootNamespace.Tests {
public void TestResultChangedOnClass()
{
try {
testClass.TestResultChanged += ResultChanged;
testClass.ResultChanged += ResultChanged;
TestResult result = new TestResult("RootNamespace.Tests.MyTestFixture.TestMethod");
result.ResultType = TestResultType.Failure;
testProject.UpdateTestResult(result);
} finally {
testClass.TestResultChanged -= ResultChanged;
testClass.ResultChanged -= ResultChanged;
}
Assert.IsTrue(resultChangedCalled);
@ -133,14 +132,14 @@ namespace RootNamespace.Tests { @@ -133,14 +132,14 @@ namespace RootNamespace.Tests {
[Test]
public void FindTestMethod()
{
Assert.AreSame(testMethod, testClass.Members.Single(m => m.Name == "TestMethod"));
Assert.AreSame(testMethod, testClass.NestedTests.Single(m => m.DisplayName == "TestMethod"));
}
/*
[Test]
public void AddNewClassNodeWhenTestClassPassed()
{
testClass.TestResult = TestResultType.Success;
testClass.Result = TestResultType.Success;
TestClassTreeNode node = new TestClassTreeNode(testProject, testClass);
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex);
}
@ -148,7 +147,7 @@ namespace RootNamespace.Tests { @@ -148,7 +147,7 @@ namespace RootNamespace.Tests {
[Test]
public void AddNewMethodNodeWhenTestPassed()
{
testMethod.TestResult = TestResultType.Success;
testMethod.Result = TestResultType.Success;
TestMemberTreeNode node = new TestMemberTreeNode(testProject, testMethod);
Assert.AreEqual(TestTreeViewImageListIndex.TestPassed, (TestTreeViewImageListIndex)node.ImageIndex);
}
@ -161,7 +160,7 @@ namespace RootNamespace.Tests { @@ -161,7 +160,7 @@ namespace RootNamespace.Tests {
[Test]
public void MethodRemovedInParserInfo()
{
UpdateCodeFile(@"
UpdateCodeFile("test.cs", @"
using NUnit.Framework;
namespace RootNamespace.Tests {
[TestFixture]
@ -170,7 +169,7 @@ namespace RootNamespace.Tests { @@ -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)

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

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

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

@ -0,0 +1,188 @@ @@ -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 @@ @@ -1,6 +1,7 @@
// 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.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
@ -13,7 +14,7 @@ namespace UnitTesting.Tests.Project @@ -13,7 +14,7 @@ namespace UnitTesting.Tests.Project
/// If a test fixture's base class has test attributes then
/// NUnit includes the base class test methods by prefixing
/// the base class name to them. In NUnit 2.2 this was true for
/// both the GUI and the test result information. In
/// both the GUI and the test result information. In
/// NUnit 2.4 the GUI prefixes the base class to the method
/// name but the test result does not prefix the base class
/// to the name of the method.
@ -29,97 +30,65 @@ namespace UnitTesting.Tests.Project @@ -29,97 +30,65 @@ namespace UnitTesting.Tests.Project
///
/// RootNamespace.DerivedClass.BaseClassMethod
/// </summary>
[TestFixture, Ignore("Inherited tests not implemented")]
public class TestMethodsInBaseClassTestFixture
[TestFixture]
public class TestMethodsInBaseClassTestFixture : NUnitTestProjectFixtureBase
{
/*
TestClass testClass;
MockClass c;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
NUnitTestClass testClass;
[SetUp]
public void SetUp()
public override void SetUp()
{
MockProjectContent projectContent = new MockProjectContent();
base.SetUp();
// Create the base test class.
MockClass baseClass = new MockClass(projectContent, "RootNamespace.TestFixtureBase");
baseClass.Attributes.Add(new MockAttribute("TestFixture"));
MockMethod baseMethod = new MockMethod(baseClass, "BaseMethod");
baseMethod.Attributes.Add(new MockAttribute("Test"));
baseClass.Methods.Add(baseMethod);
// Create the derived test class.
c = new MockClass(projectContent, "RootNamespace.MyTestFixture");
c.Attributes.Add(new MockAttribute("TestFixture"));
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);
AddCodeFileInNamespace("base.cs", @"
[TestFixture] class TestFixtureBase {
[Test] public void BaseMethod() {}
}");
AddCodeFileInNamespace("derived.cs", @"
[TestFixture] class MyTestFixture : TestFixtureBase {
[Test] public void DerivedMethod() {}
}");
testClass = testProject.GetTestClass(new FullTypeName("RootNamespace.MyTestFixture"));
testClass.EnsureNestedTestsInitialized();
}
[Test]
public void TwoTestMethods()
{
Assert.AreEqual(2, testClass.Members.Count);
Assert.AreEqual(2, testClass.NestedTests.Count);
}
[Test]
public void DerivedMethod()
{
Assert.IsTrue(testClass.Members.Contains("DerivedMethod"));
Assert.IsNotNull(testClass.FindTestMethod("DerivedMethod"));
}
[Test]
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]
public void BaseMethodDeclaringTypeIsDerivedClass()
public void FindTestMethodDoesNotReturnBaseMethodIfUsingShortName()
{
TestMember method = testClass.Members["TestFixtureBase.BaseMethod"];
Assert.AreEqual(c, method.Member.DeclaringType);
Assert.IsNull(testClass.FindTestMethod("BaseMethod"));
}
[Test]
public void UpdateTestResultUsingPrefixBaseClassName()
public void FindTestMethodWithShortNameCanFindBaseMethod()
{
TestClassCollection testClasses = new TestClassCollection();
testClasses.Add(testClass);
TestResult testResult = new TestResult("RootNamespace.MyTestFixture.TestFixtureBase.BaseMethod");
testResult.ResultType = TestResultType.Failure;
testClasses.UpdateTestResult(testResult);
Assert.AreEqual(TestResultType.Failure, testClass.Result);
Assert.IsNotNull(testClass.FindTestMethodWithShortName("BaseMethod"));
}
[Test]
public void UpdateTestResult()
public void UpdateTestResultUsingPrefixBaseClassName()
{
TestClassCollection testClasses = new TestClassCollection();
testClasses.Add(testClass);
TestResult testResult = new TestResult("RootNamespace.MyTestFixture.BaseMethod");
TestResult testResult = new TestResult("RootNamespace.MyTestFixture.TestFixtureBase.BaseMethod");
testResult.ResultType = TestResultType.Failure;
testClasses.UpdateTestResult(testResult);
testProject.UpdateTestResult(testResult);
Assert.AreEqual(TestResultType.Failure, testClass.Result);
}*/
}
}
}

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

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

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
// 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.Linq;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.UnitTesting;
using NUnit.Framework;
@ -10,125 +11,57 @@ using UnitTesting.Tests.Utils; @@ -10,125 +11,57 @@ using UnitTesting.Tests.Utils;
namespace UnitTesting.Tests.Project
{
[TestFixture]
public class TwoRootNamespacesTestFixture
public class TwoRootNamespacesTestFixture : NUnitTestProjectFixtureBase
{
/*
TestProject testProject;
MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
[SetUp]
public void Init()
public override void SetUp()
{
// Create a project to display in the test tree view.
IProject project = new MockCSharpProject();
project.Name = "TestProject";
ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project);
nunitFrameworkReferenceItem.Include = "NUnit.Framework";
ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem);
// Add a test class with a TestFixture attributes.
projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None;
MockClass c = new MockClass(projectContent, "RootNamespace1.MyTestFixture1");
c.Attributes.Add(new MockAttribute("TestFixture"));
projectContent.Classes.Add(c);
base.SetUp();
// 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);
AddCodeFile("ns1.cs", @"using NUnit.Framework;
namespace RootNamespace {
[TestFixture] class MyTestFixture1 {}
}");
AddCodeFile("ns2.cs", @"using NUnit.Framework;
namespace RootNamespace2 {
[TestFixture] class MyTestFixture2 {}
}");
testProject.EnsureNestedTestsInitialized();
}
[Test]
public void TwoRootNamespaces()
{
Assert.AreEqual(2, testProject.RootNamespaces.Count);
Assert.AreEqual(2, testProject.NestedTests.Count);
}
[Test]
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]
public void RootNamespace2()
{
Assert.AreEqual("RootNamespace2", testProject.RootNamespaces[1]);
}
[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);
var ns = (TestNamespace)testProject.NestedTests.ElementAt(1);
Assert.AreEqual("RootNamespace2", ns.NamespaceName);
}
[Test]
public void OneClassInNamespace2()
{
Assert.AreEqual(1, testProject.GetTestClasses("RootNamespace2").Length);
var ns = (TestNamespace)testProject.NestedTests.ElementAt(1);
Assert.AreEqual(1, ns.NestedTests.Count);
}
[Test]
public void ClassNameInNamespace2()
{
TestClass[] classes = testProject.GetTestClasses("RootNamespace2");
Assert.AreEqual("MyTestFixture2", classes[0].Name);
}
[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);
var ns = (TestNamespace)testProject.NestedTests.ElementAt(1);
Assert.AreEqual("MyTestFixture2", ns.NestedTests.Single().DisplayName);
}
[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 @@ @@ -83,8 +83,19 @@
<Compile Include="Project\DuplicateMethodNameTestFixture.cs" />
<Compile Include="Project\EmptyProjectTestFixture.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\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="TestRunner\TestResultsReaderTests.cs" />
<Compile Include="UnitTestingOptionsTestFixture.cs" />

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

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

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

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

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

@ -154,9 +154,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -154,9 +154,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring
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();
}

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

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

Loading…
Cancel
Save