diff --git a/src/AddIns/Misc/UnitTesting/Src/TestClass.cs b/src/AddIns/Misc/UnitTesting/Src/TestClass.cs index 1fdcb502a2..e0a858642b 100644 --- a/src/AddIns/Misc/UnitTesting/Src/TestClass.cs +++ b/src/AddIns/Misc/UnitTesting/Src/TestClass.cs @@ -273,7 +273,9 @@ namespace ICSharpCode.UnitTesting TestMethodCollection existingTestMethods = TestMethods; for (int i = existingTestMethods.Count - 1; i >= 0; --i) { TestMethod method = existingTestMethods[i]; - if (!newTestMethods.Contains(method.Name)) { + if (newTestMethods.Contains(method.Name)) { + method.Update(newTestMethods[method.Name].Method); + } else { existingTestMethods.RemoveAt(i); } } diff --git a/src/AddIns/Misc/UnitTesting/Src/TestMethod.cs b/src/AddIns/Misc/UnitTesting/Src/TestMethod.cs index f051c0cd11..ab41945969 100644 --- a/src/AddIns/Misc/UnitTesting/Src/TestMethod.cs +++ b/src/AddIns/Misc/UnitTesting/Src/TestMethod.cs @@ -61,6 +61,15 @@ namespace ICSharpCode.UnitTesting } } + /// + /// Updates the test method based on new information + /// in the specified IMethod. + /// + public void Update(IMethod method) + { + this.method = method; + } + /// /// Gets the test result for this method. /// diff --git a/src/AddIns/Misc/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs b/src/AddIns/Misc/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs index 0892434b20..1c8d197529 100644 --- a/src/AddIns/Misc/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs +++ b/src/AddIns/Misc/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs @@ -22,6 +22,7 @@ namespace UnitTesting.Tests.Project TestClass testClass; TestMethod testMethod1; TestMethod testMethod2; + MockClass mockClass; [SetUp] public void Init() @@ -35,7 +36,7 @@ namespace UnitTesting.Tests.Project MockProjectContent projectContent = new MockProjectContent(); projectContent.Language = LanguageProperties.None; - MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture"); + mockClass = new MockClass("RootNamespace.Tests.MyTestFixture"); mockClass.Namespace = "RootNamespace.Tests"; mockClass.ProjectContent = projectContent; mockClass.Attributes.Add(new MockAttribute("TestFixture")); @@ -183,5 +184,31 @@ namespace UnitTesting.Tests.Project { Assert.IsNull(testProject.TestClasses.GetTestMethod(String.Empty)); } + + /// + /// SD2-1278. Tests that the method is updated in the TestClass. + /// This ensures that the method's location is up to date. + /// + [Test] + public void TestMethodShouldBeUpdatedInClass() + { + MockMethod mockMethod = new MockMethod("TestMethod1"); + mockMethod.DeclaringType = mockClass; + mockMethod.Attributes.Add(new MockAttribute("Test")); + mockClass.SetCompoundClass(mockClass); + + // Remove the existing TestMethod1 in the class. + mockClass.Methods.RemoveAt(0); + + // Add our newly created test method object. + mockClass.Methods.Insert(0, mockMethod); + + TestClass testClass = testProject.TestClasses["RootNamespace.Tests.MyTestFixture"]; + testClass.UpdateClass(mockClass); + + // Ensure that the TestClass now uses the new method object. + TestMethod method = testClass.GetTestMethod("TestMethod1"); + Assert.AreSame(mockMethod, method.Method); + } } }