From ed2d73dd0de755575ae61aef9033781f768bbf91 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 28 Jan 2007 20:26:11 +0000 Subject: [PATCH] SD2-1278. Test method locations are now updated in the test tree as the file is edited. Previously using Goto Definition in the test tree could jump to the wrong line after the file was edited. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2344 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- src/AddIns/Misc/UnitTesting/Src/TestClass.cs | 4 ++- src/AddIns/Misc/UnitTesting/Src/TestMethod.cs | 9 ++++++ .../TestClassWithTwoMethodsTestFixture.cs | 29 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) 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); + } } }