Browse Source

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
shortcuts
Matt Ward 19 years ago
parent
commit
ed2d73dd0d
  1. 4
      src/AddIns/Misc/UnitTesting/Src/TestClass.cs
  2. 9
      src/AddIns/Misc/UnitTesting/Src/TestMethod.cs
  3. 29
      src/AddIns/Misc/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs

4
src/AddIns/Misc/UnitTesting/Src/TestClass.cs

@ -273,7 +273,9 @@ namespace ICSharpCode.UnitTesting
TestMethodCollection existingTestMethods = TestMethods; TestMethodCollection existingTestMethods = TestMethods;
for (int i = existingTestMethods.Count - 1; i >= 0; --i) { for (int i = existingTestMethods.Count - 1; i >= 0; --i) {
TestMethod method = existingTestMethods[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); existingTestMethods.RemoveAt(i);
} }
} }

9
src/AddIns/Misc/UnitTesting/Src/TestMethod.cs

@ -61,6 +61,15 @@ namespace ICSharpCode.UnitTesting
} }
} }
/// <summary>
/// Updates the test method based on new information
/// in the specified IMethod.
/// </summary>
public void Update(IMethod method)
{
this.method = method;
}
/// <summary> /// <summary>
/// Gets the test result for this method. /// Gets the test result for this method.
/// </summary> /// </summary>

29
src/AddIns/Misc/UnitTesting/Test/Project/TestClassWithTwoMethodsTestFixture.cs

@ -22,6 +22,7 @@ namespace UnitTesting.Tests.Project
TestClass testClass; TestClass testClass;
TestMethod testMethod1; TestMethod testMethod1;
TestMethod testMethod2; TestMethod testMethod2;
MockClass mockClass;
[SetUp] [SetUp]
public void Init() public void Init()
@ -35,7 +36,7 @@ namespace UnitTesting.Tests.Project
MockProjectContent projectContent = new MockProjectContent(); MockProjectContent projectContent = new MockProjectContent();
projectContent.Language = LanguageProperties.None; projectContent.Language = LanguageProperties.None;
MockClass mockClass = new MockClass("RootNamespace.Tests.MyTestFixture"); mockClass = new MockClass("RootNamespace.Tests.MyTestFixture");
mockClass.Namespace = "RootNamespace.Tests"; mockClass.Namespace = "RootNamespace.Tests";
mockClass.ProjectContent = projectContent; mockClass.ProjectContent = projectContent;
mockClass.Attributes.Add(new MockAttribute("TestFixture")); mockClass.Attributes.Add(new MockAttribute("TestFixture"));
@ -183,5 +184,31 @@ namespace UnitTesting.Tests.Project
{ {
Assert.IsNull(testProject.TestClasses.GetTestMethod(String.Empty)); Assert.IsNull(testProject.TestClasses.GetTestMethod(String.Empty));
} }
/// <summary>
/// SD2-1278. Tests that the method is updated in the TestClass.
/// This ensures that the method's location is up to date.
/// </summary>
[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);
}
} }
} }

Loading…
Cancel
Save