diff --git a/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs b/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs index 48a8437fd0..23f604e283 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/TestClass.cs @@ -274,10 +274,10 @@ namespace ICSharpCode.UnitTesting TestMethodCollection GetTestMethods(IClass c) { TestMethodCollection testMethods = new TestMethodCollection(); - foreach (IMethod method in c.Methods) { - if (IsTestMethod(method)) { - if (!testMethods.Contains(method.Name)) { - testMethods.Add(new TestMethod(method)); + foreach (IMember member in c.AllMembers) { + if (IsTestMethod(member)) { + if (!testMethods.Contains(member.Name)) { + testMethods.Add(new TestMethod(member)); } } } diff --git a/src/AddIns/Analysis/UnitTesting/Src/TestMethod.cs b/src/AddIns/Analysis/UnitTesting/Src/TestMethod.cs index b39deabc49..7b71b4fe42 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/TestMethod.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/TestMethod.cs @@ -12,7 +12,7 @@ namespace ICSharpCode.UnitTesting public class TestMethod { string prefix = String.Empty; - IMethod method; + IMember method; TestResultType testResultType = TestResultType.None; /// @@ -20,7 +20,7 @@ namespace ICSharpCode.UnitTesting /// public event EventHandler ResultChanged; - public TestMethod(IMethod method) + public TestMethod(IMember method) { this.method = method; } @@ -41,16 +41,16 @@ namespace ICSharpCode.UnitTesting /// /// RootNamespace.DerivedClass.BaseClass.BaseClassMethod /// - public TestMethod(string prefix, IMethod method) + public TestMethod(string prefix, IMember method) { this.method = method; this.prefix = prefix; } /// - /// Gets the underlying IMethod for this TestMethod. + /// Gets the underlying IMember for this TestMethod. /// - public IMethod Method { + public IMember Method { get { return method; } } @@ -58,7 +58,7 @@ namespace ICSharpCode.UnitTesting /// Updates the test method based on new information /// in the specified IMethod. /// - public void Update(IMethod method) + public void Update(IMember method) { this.method = method; } diff --git a/src/AddIns/Analysis/UnitTesting/Src/TestMethodTreeNode.cs b/src/AddIns/Analysis/UnitTesting/Src/TestMethodTreeNode.cs index 1038e83981..c023697141 100644 --- a/src/AddIns/Analysis/UnitTesting/Src/TestMethodTreeNode.cs +++ b/src/AddIns/Analysis/UnitTesting/Src/TestMethodTreeNode.cs @@ -24,9 +24,9 @@ namespace ICSharpCode.UnitTesting } /// - /// Gets the underlying IMethod for this test method. + /// Gets the underlying IMember for this test method. /// - public IMethod Method { + public IMember Method { get { return testMethod.Method; } diff --git a/src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs b/src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs new file mode 100644 index 0000000000..95ba34e3cf --- /dev/null +++ b/src/AddIns/Analysis/UnitTesting/Test/Project/TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests.cs @@ -0,0 +1,51 @@ +// 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.Dom; +using ICSharpCode.UnitTesting; +using NUnit.Framework; +using UnitTesting.Tests.Utils; + +namespace UnitTesting.Tests.Project +{ + [TestFixture] + public class TestClassWithFieldsDefinedAsTestMembersByTestFrameworkTests + { + TestClass testClass; + MockClass fakeClass; + MockTestFramework fakeTestFramework; + MockRegisteredTestFrameworks fakeRegisteredTestFrameworks; + + void CreateTestClass() + { + fakeClass = MockClass.CreateMockClassWithoutAnyAttributes(); + fakeTestFramework = new MockTestFramework(); + fakeRegisteredTestFrameworks = new MockRegisteredTestFrameworks(); + fakeRegisteredTestFrameworks.AddTestFrameworkForProject(fakeClass.Project, fakeTestFramework); + + testClass = new TestClass(fakeClass, fakeRegisteredTestFrameworks); + } + + DefaultField AddTestFieldDefinedAsTestMemberToClass(string name) + { + var field = new DefaultField(fakeClass, name); + fakeClass.Fields.Add(field); + fakeRegisteredTestFrameworks.AddTestMethod(field); + + return field; + } + + [Test] + public void TestMethods_ClassHasOneFieldDefinedAsTestMemberByTestFramework_FirstItemHasSameNameAsField() + { + CreateTestClass(); + AddTestFieldDefinedAsTestMemberToClass("MyField"); + + TestMethod testField = testClass.TestMethods[0]; + string testFieldName = testField.Name; + + Assert.AreEqual("MyField", testFieldName); + } + } +} diff --git a/src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj b/src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj index c79b3bc4cb..edcba55ea2 100644 --- a/src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj +++ b/src/AddIns/Analysis/UnitTesting/Test/UnitTesting.Tests.csproj @@ -90,6 +90,7 @@ +