diff --git a/samples/MSTest/MSTest.SharpDevelop.Tests/MSTest.SharpDevelop.Tests.csproj b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTest.SharpDevelop.Tests.csproj
index 933df400f2..1f76e45dc3 100644
--- a/samples/MSTest/MSTest.SharpDevelop.Tests/MSTest.SharpDevelop.Tests.csproj
+++ b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTest.SharpDevelop.Tests.csproj
@@ -37,6 +37,9 @@
..\..\..\bin\ICSharpCode.NRefactory.dll
+
+ ..\..\..\bin\ICSharpCode.NRefactory.CSharp.dll
+
..\..\..\bin\ICSharpCode.SharpDevelop.dll
@@ -56,7 +59,10 @@
+
+
+
diff --git a/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestBaseTests.cs b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestBaseTests.cs
new file mode 100644
index 0000000000..33319f7649
--- /dev/null
+++ b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestBaseTests.cs
@@ -0,0 +1,61 @@
+// 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.NRefactory.CSharp;
+using ICSharpCode.NRefactory.TypeSystem;
+using ICSharpCode.SharpDevelop;
+using ICSharpCode.SharpDevelop.Parser;
+using ICSharpCode.SharpDevelop.Project;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace MSTest.SharpDevelop.Tests
+{
+ public class MSTestBaseTests
+ {
+ protected IProject project;
+ protected IProjectContent projectContent;
+
+ [SetUp]
+ public void SetUp()
+ {
+ SD.InitializeForUnitTests();
+ SD.Services.AddService(typeof(IParserService), MockRepository.GenerateStrictMock());
+ project = MockRepository.GenerateStrictMock();
+ projectContent = new CSharpProjectContent();
+
+ SD.ParserService
+ .Stub(p => p.GetCompilation(project))
+ .WhenCalled(c => c.ReturnValue = projectContent.CreateCompilation());
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ SD.TearDownForUnitTests();
+ }
+
+ public void AddCodeFile(string fileName, string code)
+ {
+ IUnresolvedFile oldFile = projectContent.GetFile(fileName);
+ IUnresolvedFile newFile = Parse(fileName, code);
+ projectContent = projectContent.AddOrUpdateFiles(newFile);
+ }
+
+ IUnresolvedFile Parse(string fileName, string code)
+ {
+ var parser = new CSharpParser();
+ SyntaxTree syntaxTree = parser.Parse(code, fileName);
+ Assert.IsFalse(parser.HasErrors);
+ return syntaxTree.ToTypeSystem();
+ }
+
+ protected ITypeDefinition GetFirstTypeDefinition()
+ {
+ ICompilation compilation = projectContent.CreateCompilation();
+ return compilation.MainAssembly.TopLevelTypeDefinitions.First();
+ }
+ }
+}
diff --git a/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestClassTests.cs b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestClassTests.cs
new file mode 100644
index 0000000000..a791b7e327
--- /dev/null
+++ b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestClassTests.cs
@@ -0,0 +1,77 @@
+// 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.MSTest;
+using NUnit.Framework;
+
+namespace MSTest.SharpDevelop.Tests
+{
+ [TestFixture]
+ public class MSTestClassTests : MSTestBaseTests
+ {
+ bool IsTestClass()
+ {
+ return MSTestClass.IsTestClass(GetFirstTypeDefinition());
+ }
+
+ [Test]
+ public void IsTestClass_ClassHasNoAttributes_ReturnsFalse()
+ {
+ AddCodeFile("myclass.cs", "class MyTest {}");
+
+ bool result = IsTestClass();
+
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void IsTestClass_ClassHasTestFixtureAttributeMissingAttributePart_ReturnsTrue()
+ {
+ AddCodeFile("myclass.cs", "[TestClass]class MyTest {}");
+
+ bool result = IsTestClass();
+
+ Assert.IsTrue(result);
+ }
+
+ [Test]
+ public void IsTestClass_ClassHasTestClassAttributeAndIsAbstract_ReturnsFalse()
+ {
+ AddCodeFile("myclass.cs", "[TestClass] abstract class MyTest {}");
+
+ bool result = IsTestClass();
+
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void IsTestClass_ClassHasTestClassAttributeIncludingAttributePart_ReturnsTrue()
+ {
+ AddCodeFile("myclass.cs", "[TestClassAttribute]class MyTest {}");
+
+ bool result = IsTestClass();
+
+ Assert.IsTrue(result);
+ }
+
+ [Test]
+ public void IsTestClass_ClassHasFullyQualifiedMSTestClassAttribute_ReturnsTrue()
+ {
+ AddCodeFile("myclass.cs", "[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute]class MyTest {}");
+
+ bool result = IsTestClass();
+
+ Assert.IsTrue(result);
+ }
+
+ [Test]
+ public void IsTestClass_ClassIsNull_ReturnsFalse()
+ {
+ bool result = MSTestClass.IsTestClass(null);
+
+ Assert.IsFalse(result);
+ }
+ }
+}
diff --git a/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestFrameworkTests.cs b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestFrameworkTests.cs
index 4922096638..a0f39e2c10 100644
--- a/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestFrameworkTests.cs
+++ b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestFrameworkTests.cs
@@ -189,150 +189,5 @@ namespace MSTest.SharpDevelop.Tests
Assert.IsTrue(result);
}
-//
-// [Test]
-// public void IsTestClass_ClassHasNoAttributes_ReturnsFalse()
-// {
-// IClass fakeClass = CreateClassWithoutAnyAttributes();
-//
-// bool result = testFramework.IsTestClass(fakeClass);
-//
-// Assert.IsFalse(result);
-// }
-//
-// [Test]
-// public void IsTestClass_ClassHasTestFixtureAttributeMissingAttributePart_ReturnsTrue()
-// {
-// IClass fakeClass = CreateClassWithAttributes("TestClass");
-//
-// bool result = testFramework.IsTestClass(fakeClass);
-//
-// Assert.IsTrue(result);
-// }
-//
-// [Test]
-// public void IsTestClass_ClassHasTestClassAttributeAndIsAbstract_ReturnsFalse()
-// {
-// IClass fakeClass = CreateClassWithAttributes("TestClass");
-// MakeClassAbstract(fakeClass);
-//
-// bool result = testFramework.IsTestClass(fakeClass);
-//
-// Assert.IsFalse(result);
-// }
-//
-// [Test]
-// public void IsTestClass_ClassHasTestClassAttributeIncludingAttributePart_ReturnsTrue()
-// {
-// IClass fakeClass = CreateClassWithAttributes("TestClassAttribute");
-//
-// bool result = testFramework.IsTestClass(fakeClass);
-//
-// Assert.IsTrue(result);
-// }
-//
-// [Test]
-// public void IsTestClass_ClassHasFullyQualifiedMSTestClassAttribute_ReturnsTrue()
-// {
-// IClass fakeClass = CreateClassWithAttributes("Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute");
-//
-// bool result = testFramework.IsTestClass(fakeClass);
-//
-// Assert.IsTrue(result);
-// }
-//
-// [Test]
-// public void IsTestClass_ClassIsNull_ReturnsFalse()
-// {
-// bool result = testFramework.IsTestClass(null);
-//
-// Assert.IsFalse(result);
-// }
-//
-// [Test]
-// public void IsTestMember_MethodHasNoAttributes_ReturnsFalse()
-// {
-// IMethod method = CreateMethodWithoutAnyAttributes();
-//
-// bool result = testFramework.IsTestMember(method);
-//
-// Assert.IsFalse(result);
-// }
-//
-// [Test]
-// public void IsTestMember_MethodHasTestMethodAttributeWithoutAttributePart_ReturnsTrue()
-// {
-// IMethod method = CreateMethodWithAttributes("TestMethod");
-//
-// bool result = testFramework.IsTestMember(method);
-//
-// Assert.IsTrue(result);
-// }
-//
-// [Test]
-// public void IsTestMember_MethodHasTestMethodAttributeAttribute_ReturnsTrue()
-// {
-// IMethod method = CreateMethodWithAttributes("TestMethodAttribute");
-//
-// bool result = testFramework.IsTestMember(method);
-//
-// Assert.IsTrue(result);
-// }
-//
-// [Test]
-// public void IsTestMember_MethodHasFullyQualifiedMSTestTestMethodAttribute_ReturnsTrue()
-// {
-// IMethod method = CreateMethodWithAttributes("Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute");
-//
-// bool result = testFramework.IsTestMember(method);
-//
-// Assert.IsTrue(result);
-// }
-//
-// [Test]
-// public void IsTestMember_MethodIsNull_ReturnsFalse()
-// {
-// bool result = testFramework.IsTestMember(null);
-//
-// Assert.IsFalse(result);
-// }
-//
-// [Test]
-// public void IsTestMember_MemberNotMethod_ReturnsFalse()
-// {
-// IMember member = MockRepository.GenerateStub();
-//
-// bool result = testFramework.IsTestMember(member);
-//
-// Assert.IsFalse(result);
-// }
-//
-// [Test]
-// public void GetTestMembersFor_ClassHasNoMethods_ReturnsFalse()
-// {
-// IClass fakeClass = CreateClassWithAttributes("TestClass");
-// AddMethodsToClass(fakeClass, new List());
-//
-// List testMembers = GetTestMembersFor(fakeClass);
-//
-// Assert.AreEqual(0, testMembers.Count);
-// }
-//
-// [Test]
-// public void GetTestMembersFor_ClassHasTwoMethodsAndSecondOneIsTestMethod_ReturnsSecondTestMethodOnly()
-// {
-// IClass fakeClass = CreateClassWithAttributes("TestClass");
-//
-// var methods = new List();
-// methods.Add(CreateMethodWithoutAnyAttributes());
-// IMethod testMethod = CreateMethodWithAttributes("TestMethod");
-// methods.Add(testMethod);
-// AddMethodsToClass(fakeClass, methods);
-//
-// List testMembers = GetTestMembersFor(fakeClass);
-//
-// Assert.AreEqual(1, testMembers.Count);
-// Assert.AreEqual(testMethod, testMembers[0].Member);
-// }
}
}
diff --git a/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestProjectTests.cs b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestProjectTests.cs
new file mode 100644
index 0000000000..6bfd121036
--- /dev/null
+++ b/samples/MSTest/MSTest.SharpDevelop.Tests/MSTestProjectTests.cs
@@ -0,0 +1,141 @@
+// 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.MSTest;
+using NUnit.Framework;
+
+namespace MSTest.SharpDevelop.Tests
+{
+ [TestFixture]
+ public class MSTestProjectTests : MSTestBaseTests
+ {
+ MSTestProject testProject;
+
+ void CreateTestProject()
+ {
+ testProject = new MSTestProject(project);
+ }
+
+ List GetTestMembersFor()
+ {
+ return testProject.GetTestMembersFor(GetFirstTypeDefinition()).ToList();
+ }
+
+ [Test]
+ public void GetTestMembersFor_OneMethodHasNoAttributes_ReturnsOneMember()
+ {
+ string code =
+ "[TestClass]" +
+ "class MyTest {" +
+ " public void MyMethod() {}" +
+ "}";
+ AddCodeFile("myclass.cs", code);
+ CreateTestProject();
+
+ List members = GetTestMembersFor();
+
+ Assert.AreEqual(0, members.Count);
+ }
+
+ [Test]
+ public void GetTestMembersFor_MethodHasTestMethodAttributeWithoutAttributePart_ReturnsOneMember()
+ {
+ string code =
+ "[TestClass]" +
+ "class MyTest {" +
+ " [TestMethod]" +
+ " public void MyMethod() {}" +
+ "}";
+ AddCodeFile("myclass.cs", code);
+ CreateTestProject();
+
+ List members = GetTestMembersFor();
+
+ Assert.AreEqual(1, members.Count);
+ Assert.AreEqual("MyMethod", members[0].DisplayName);
+ }
+
+ [Test]
+ public void GetTestMembersFor_MethodHasTestMethodAttributeAttribute_ReturnsOneMember()
+ {
+ string code =
+ "[TestClass]" +
+ "class MyTest {" +
+ " [TestMethodAttribute]" +
+ " public void MyMethod() {}" +
+ "}";
+ AddCodeFile("myclass.cs", code);
+ CreateTestProject();
+
+ List members = GetTestMembersFor();
+
+ Assert.AreEqual("MyMethod", members[0].DisplayName);
+ }
+
+ [Test]
+ public void GetTestMembersFor_MethodHasFullyQualifiedMSTestTestMethodAttribute_ReturnsOneMember()
+ {
+ string code =
+ "[TestClass]" +
+ "class MyTest {" +
+ " [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute]" +
+ " public void MyMethod() {}" +
+ "}";
+ AddCodeFile("myclass.cs", code);
+ CreateTestProject();
+
+ List members = GetTestMembersFor();
+
+ Assert.AreEqual("MyMethod", members[0].DisplayName);
+ }
+
+ [Test]
+ public void GetTestMembersFor_MemberNotMethod_ReturnsNoItems()
+ {
+ string code =
+ "[TestClass]" +
+ "class MyTest {" +
+ " public int MyProperty { get; set; }" +
+ "}";
+ AddCodeFile("myclass.cs", code);
+ CreateTestProject();
+
+ List members = GetTestMembersFor();
+
+ Assert.AreEqual(0, members.Count);
+ }
+
+ [Test]
+ public void GetTestMembersFor_ClassHasNoMethods_ReturnsNoItems()
+ {
+ AddCodeFile("myclass.cs", "[TestClass]class MyTest {}");
+ CreateTestProject();
+
+ List testMembers = GetTestMembersFor();
+
+ Assert.AreEqual(0, testMembers.Count);
+ }
+
+ [Test]
+ public void GetTestMembersFor_ClassHasTwoMethodsAndSecondOneIsTestMethod_ReturnsSecondTestMethodOnly()
+ {
+ string code =
+ "[TestClass]" +
+ "class MyTest {" +
+ " public void MyFirstMethod() {}" +
+ "" +
+ " [TestMethod]" +
+ " public void MySecondMethod() {}" +
+ "}";
+ AddCodeFile("myclass.cs", code);
+ CreateTestProject();
+
+ List members = GetTestMembersFor();
+
+ Assert.AreEqual("MySecondMethod", members[0].DisplayName);
+ }
+ }
+}
diff --git a/samples/MSTest/MSTest.SharpDevelop/MSTestClass.cs b/samples/MSTest/MSTest.SharpDevelop/MSTestClass.cs
index b745aa6d41..c43e505822 100644
--- a/samples/MSTest/MSTest.SharpDevelop/MSTestClass.cs
+++ b/samples/MSTest/MSTest.SharpDevelop/MSTestClass.cs
@@ -24,6 +24,34 @@ namespace ICSharpCode.MSTest
BindResultToCompositeResultOfNestedTests();
}
+ public static bool IsTestClass(ITypeDefinition typeDefinition)
+ {
+ if ((typeDefinition == null) || (typeDefinition.IsAbstract)) {
+ return false;
+ }
+
+ foreach (IAttribute attribute in typeDefinition.Attributes) {
+ if (IsMSTestClassAttribute(attribute)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ static bool IsMSTestClassAttribute(IAttribute attribute)
+ {
+ return IsMSTestClassAttribute(attribute.AttributeType.FullName);
+ }
+
+ static bool IsMSTestClassAttribute(string name)
+ {
+ return
+ name == "TestClass" ||
+ name == "TestClassAttribute" ||
+ name == "Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute";
+ }
+
public string GetTypeName()
{
return fullTypeName.ReflectionName;
diff --git a/samples/MSTest/MSTest.SharpDevelop/MSTestProject.cs b/samples/MSTest/MSTest.SharpDevelop/MSTestProject.cs
index 3f67847827..2e78446bc4 100644
--- a/samples/MSTest/MSTest.SharpDevelop/MSTestProject.cs
+++ b/samples/MSTest/MSTest.SharpDevelop/MSTestProject.cs
@@ -27,30 +27,7 @@ namespace ICSharpCode.MSTest
protected override bool IsTestClass(ITypeDefinition typeDefinition)
{
- if ((typeDefinition == null) || (typeDefinition.IsAbstract)) {
- return false;
- }
-
- foreach (IAttribute attribute in typeDefinition.Attributes) {
- if (IsMSTestClassAttribute(attribute)) {
- return true;
- }
- }
-
- return false;
- }
-
- bool IsMSTestClassAttribute(IAttribute attribute)
- {
- return IsMSTestClassAttribute(attribute.AttributeType.FullName);
- }
-
- bool IsMSTestClassAttribute(string name)
- {
- return
- name == "TestClass" ||
- name == "TestClassAttribute" ||
- name == "Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute";
+ return MSTestClass.IsTestClass(typeDefinition);
}
protected override ITest CreateTestClass(ITypeDefinition typeDefinition)