From 9ab4031e9f03a42b55b45cbd6263cc919d51285b Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 27 Jul 2012 21:02:48 +0200 Subject: [PATCH] Fix some issues in the unit testing AddIn. --- .../UnitTesting/Commands/RunTestCommands.cs | 2 +- .../UnitTesting/Commands/UnitTestCommands.cs | 23 +++++++------------ .../UnitTesting/Interfaces/ITestTreeView.cs | 2 +- .../UnitTesting/NUnit/NUnitTestFramework.cs | 2 ++ .../UnitTesting/Service/TestService.cs | 3 +++ .../UnitTesting/Service/TestableCondition.cs | 4 ++-- .../Analysis/UnitTesting/TestTreeView.cs | 4 ++-- .../Src/Completion/CSharpMethodInsight.cs | 13 +++++++++++ 8 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/AddIns/Analysis/UnitTesting/Commands/RunTestCommands.cs b/src/AddIns/Analysis/UnitTesting/Commands/RunTestCommands.cs index 47c108fae2..bf0a3d7687 100644 --- a/src/AddIns/Analysis/UnitTesting/Commands/RunTestCommands.cs +++ b/src/AddIns/Analysis/UnitTesting/Commands/RunTestCommands.cs @@ -531,7 +531,7 @@ namespace ICSharpCode.UnitTesting get { return null; } } - public ITypeDefinition SelectedClass { + public TestClass SelectedClass { get { return null; } } diff --git a/src/AddIns/Analysis/UnitTesting/Commands/UnitTestCommands.cs b/src/AddIns/Analysis/UnitTesting/Commands/UnitTestCommands.cs index 4b1dd040c6..f33bd82220 100644 --- a/src/AddIns/Analysis/UnitTesting/Commands/UnitTestCommands.cs +++ b/src/AddIns/Analysis/UnitTesting/Commands/UnitTestCommands.cs @@ -57,33 +57,26 @@ namespace ICSharpCode.UnitTesting { ITestTreeView treeView = Owner as ITestTreeView; if (treeView != null) { - IMethod method = treeView.SelectedMethod.Resolve(); - ITypeDefinition c = treeView.SelectedClass; + var method = treeView.SelectedMethod; + var c = treeView.SelectedClass; if (method != null) { - GotoMember(method); + GotoMember(method.Resolve()); } else if (c != null) { - GotoClass(c); + GotoClass(c.Resolve()); } } } void GotoMember(IMember member) { - GotoFilePosition(member.Region); + if (member != null) + NavigationService.NavigateTo(member); } void GotoClass(ITypeDefinition c) { - GotoFilePosition(c.Region); - } - - void GotoFilePosition(DomRegion filePosition) - { - if (filePosition.IsEmpty) { - fileService.OpenFile(new FileName(filePosition.FileName)); - } else { - fileService.JumpToFilePosition(new FileName(filePosition.FileName), filePosition.BeginLine, filePosition.BeginColumn); - } + if (c != null) + NavigationService.NavigateTo(c); } } diff --git a/src/AddIns/Analysis/UnitTesting/Interfaces/ITestTreeView.cs b/src/AddIns/Analysis/UnitTesting/Interfaces/ITestTreeView.cs index 635c17b82a..10ec9e9df2 100644 --- a/src/AddIns/Analysis/UnitTesting/Interfaces/ITestTreeView.cs +++ b/src/AddIns/Analysis/UnitTesting/Interfaces/ITestTreeView.cs @@ -18,7 +18,7 @@ namespace ICSharpCode.UnitTesting /// /// Gets the selected class in the test tree view. /// - ITypeDefinition SelectedClass {get;} + TestClass SelectedClass {get;} /// /// Gets the selected project for the selected node diff --git a/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestFramework.cs b/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestFramework.cs index 73e368207b..a6eb41fa91 100644 --- a/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestFramework.cs +++ b/src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestFramework.cs @@ -65,6 +65,8 @@ namespace ICSharpCode.UnitTesting { if (type == null) throw new ArgumentNullException("type"); + if (type.IsAbstract) + return false; var testAttribute = NUnitTestFramework.testAttribute.Resolve(compilation.TypeResolveContext); var testCaseAttribute = NUnitTestFramework.testCaseAttribute.Resolve(compilation.TypeResolveContext); return type.Methods.Any(m => m.Attributes.Any(a => a.AttributeType.Equals(testAttribute) || a.AttributeType.Equals(testCaseAttribute))); diff --git a/src/AddIns/Analysis/UnitTesting/Service/TestService.cs b/src/AddIns/Analysis/UnitTesting/Service/TestService.cs index 236684e0ec..463027346a 100644 --- a/src/AddIns/Analysis/UnitTesting/Service/TestService.cs +++ b/src/AddIns/Analysis/UnitTesting/Service/TestService.cs @@ -64,6 +64,9 @@ namespace ICSharpCode.UnitTesting ProjectService.ProjectAdded += ProjectService_ProjectAdded; ProjectService.ProjectRemoved += ProjectService_ProjectRemoved; SD.ParserService.LoadSolutionProjectsThread.Finished += SD_ParserService_LoadSolutionProjectsThread_Finished; + // TODO: get rid of static service. + // We don't even know for sure that we're on the main thread when the cctor runs + SD_ParserService_LoadSolutionProjectsThread_Finished(null, null); } static void SD_ParserService_LoadSolutionProjectsThread_Finished(object sender, EventArgs e) diff --git a/src/AddIns/Analysis/UnitTesting/Service/TestableCondition.cs b/src/AddIns/Analysis/UnitTesting/Service/TestableCondition.cs index aacb2dd77d..497b328854 100644 --- a/src/AddIns/Analysis/UnitTesting/Service/TestableCondition.cs +++ b/src/AddIns/Analysis/UnitTesting/Service/TestableCondition.cs @@ -46,8 +46,8 @@ namespace ICSharpCode.UnitTesting public static ITypeDefinition GetClass(object caller) { ITestTreeView testTreeView = caller as ITestTreeView; - if (testTreeView != null) { - return testTreeView.SelectedClass; + if (testTreeView != null && testTreeView.SelectedClass != null) { + return testTreeView.SelectedClass.Resolve(); } // ClassNode classNode = caller as ClassNode; // if (classNode != null) diff --git a/src/AddIns/Analysis/UnitTesting/TestTreeView.cs b/src/AddIns/Analysis/UnitTesting/TestTreeView.cs index 8d072a8897..921c833a16 100644 --- a/src/AddIns/Analysis/UnitTesting/TestTreeView.cs +++ b/src/AddIns/Analysis/UnitTesting/TestTreeView.cs @@ -71,7 +71,7 @@ namespace ICSharpCode.UnitTesting /// /// Gets the class of the currently selected tree node. /// - public ITypeDefinition SelectedClass { + public TestClass SelectedClass { get { ClassUnitTestNode classNode = SelectedItem as ClassUnitTestNode; if (classNode == null) { @@ -79,7 +79,7 @@ namespace ICSharpCode.UnitTesting } if (classNode != null) { - return classNode.TestClass.Resolve(); + return classNode.TestClass; } return null; } diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpMethodInsight.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpMethodInsight.cs index 613e5b5a5a..a881b638af 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpMethodInsight.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpMethodInsight.cs @@ -8,6 +8,7 @@ using System.Linq; using ICSharpCode.NRefactory.Completion; using ICSharpCode.NRefactory.CSharp.Completion; +using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor.CodeCompletion; @@ -20,6 +21,7 @@ namespace CSharpBinding.Completion readonly CSharpCompletionBinding binding; readonly ITextEditor editor; IInsightWindow window; + CSharpInsightItem initiallySelectedItem; public CSharpMethodInsight(CSharpCompletionBinding binding, ITextEditor editor, int startOffset, IEnumerable items) { @@ -38,6 +40,8 @@ namespace CSharpBinding.Completion window.StartOffset = startOffset; // closing the window at the end of the parameter list is handled by the CaretPositionChanged event window.EndOffset = editor.Document.TextLength; + if (initiallySelectedItem != null) + window.SelectedItem = initiallySelectedItem; window.CaretPositionChanged += window_CaretPositionChanged; } @@ -65,6 +69,15 @@ namespace CSharpBinding.Completion if (parameterIndex < 0 && window != null) { window.Close(); } else { + if (window == null || parameterIndex > ((CSharpInsightItem)window.SelectedItem).Method.Parameters.Count) { + var newItem = items.FirstOrDefault(i => parameterIndex <= i.Method.Parameters.Count); + if (newItem != null) { + if (window != null) + window.SelectedItem = newItem; + else + initiallySelectedItem = newItem; + } + } if (parameterIndex > 0) parameterIndex--; // NR returns 1-based parameter index foreach (var item in items)