Browse Source

Fix some issues in the unit testing AddIn.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
9ab4031e9f
  1. 2
      src/AddIns/Analysis/UnitTesting/Commands/RunTestCommands.cs
  2. 23
      src/AddIns/Analysis/UnitTesting/Commands/UnitTestCommands.cs
  3. 2
      src/AddIns/Analysis/UnitTesting/Interfaces/ITestTreeView.cs
  4. 2
      src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestFramework.cs
  5. 3
      src/AddIns/Analysis/UnitTesting/Service/TestService.cs
  6. 4
      src/AddIns/Analysis/UnitTesting/Service/TestableCondition.cs
  7. 4
      src/AddIns/Analysis/UnitTesting/TestTreeView.cs
  8. 13
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpMethodInsight.cs

2
src/AddIns/Analysis/UnitTesting/Commands/RunTestCommands.cs

@ -531,7 +531,7 @@ namespace ICSharpCode.UnitTesting
get { return null; } get { return null; }
} }
public ITypeDefinition SelectedClass { public TestClass SelectedClass {
get { return null; } get { return null; }
} }

23
src/AddIns/Analysis/UnitTesting/Commands/UnitTestCommands.cs

@ -57,33 +57,26 @@ namespace ICSharpCode.UnitTesting
{ {
ITestTreeView treeView = Owner as ITestTreeView; ITestTreeView treeView = Owner as ITestTreeView;
if (treeView != null) { if (treeView != null) {
IMethod method = treeView.SelectedMethod.Resolve(); var method = treeView.SelectedMethod;
ITypeDefinition c = treeView.SelectedClass; var c = treeView.SelectedClass;
if (method != null) { if (method != null) {
GotoMember(method); GotoMember(method.Resolve());
} else if (c != null) { } else if (c != null) {
GotoClass(c); GotoClass(c.Resolve());
} }
} }
} }
void GotoMember(IMember member) void GotoMember(IMember member)
{ {
GotoFilePosition(member.Region); if (member != null)
NavigationService.NavigateTo(member);
} }
void GotoClass(ITypeDefinition c) void GotoClass(ITypeDefinition c)
{ {
GotoFilePosition(c.Region); if (c != null)
} NavigationService.NavigateTo(c);
void GotoFilePosition(DomRegion filePosition)
{
if (filePosition.IsEmpty) {
fileService.OpenFile(new FileName(filePosition.FileName));
} else {
fileService.JumpToFilePosition(new FileName(filePosition.FileName), filePosition.BeginLine, filePosition.BeginColumn);
}
} }
} }

2
src/AddIns/Analysis/UnitTesting/Interfaces/ITestTreeView.cs

@ -18,7 +18,7 @@ namespace ICSharpCode.UnitTesting
/// <summary> /// <summary>
/// Gets the selected class in the test tree view. /// Gets the selected class in the test tree view.
/// </summary> /// </summary>
ITypeDefinition SelectedClass {get;} TestClass SelectedClass {get;}
/// <summary> /// <summary>
/// Gets the selected project for the selected node /// Gets the selected project for the selected node

2
src/AddIns/Analysis/UnitTesting/NUnit/NUnitTestFramework.cs

@ -65,6 +65,8 @@ namespace ICSharpCode.UnitTesting
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException("type");
if (type.IsAbstract)
return false;
var testAttribute = NUnitTestFramework.testAttribute.Resolve(compilation.TypeResolveContext); var testAttribute = NUnitTestFramework.testAttribute.Resolve(compilation.TypeResolveContext);
var testCaseAttribute = NUnitTestFramework.testCaseAttribute.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))); return type.Methods.Any(m => m.Attributes.Any(a => a.AttributeType.Equals(testAttribute) || a.AttributeType.Equals(testCaseAttribute)));

3
src/AddIns/Analysis/UnitTesting/Service/TestService.cs

@ -64,6 +64,9 @@ namespace ICSharpCode.UnitTesting
ProjectService.ProjectAdded += ProjectService_ProjectAdded; ProjectService.ProjectAdded += ProjectService_ProjectAdded;
ProjectService.ProjectRemoved += ProjectService_ProjectRemoved; ProjectService.ProjectRemoved += ProjectService_ProjectRemoved;
SD.ParserService.LoadSolutionProjectsThread.Finished += SD_ParserService_LoadSolutionProjectsThread_Finished; 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) static void SD_ParserService_LoadSolutionProjectsThread_Finished(object sender, EventArgs e)

4
src/AddIns/Analysis/UnitTesting/Service/TestableCondition.cs

@ -46,8 +46,8 @@ namespace ICSharpCode.UnitTesting
public static ITypeDefinition GetClass(object caller) public static ITypeDefinition GetClass(object caller)
{ {
ITestTreeView testTreeView = caller as ITestTreeView; ITestTreeView testTreeView = caller as ITestTreeView;
if (testTreeView != null) { if (testTreeView != null && testTreeView.SelectedClass != null) {
return testTreeView.SelectedClass; return testTreeView.SelectedClass.Resolve();
} }
// ClassNode classNode = caller as ClassNode; // ClassNode classNode = caller as ClassNode;
// if (classNode != null) // if (classNode != null)

4
src/AddIns/Analysis/UnitTesting/TestTreeView.cs

@ -71,7 +71,7 @@ namespace ICSharpCode.UnitTesting
/// <summary> /// <summary>
/// Gets the class of the currently selected tree node. /// Gets the class of the currently selected tree node.
/// </summary> /// </summary>
public ITypeDefinition SelectedClass { public TestClass SelectedClass {
get { get {
ClassUnitTestNode classNode = SelectedItem as ClassUnitTestNode; ClassUnitTestNode classNode = SelectedItem as ClassUnitTestNode;
if (classNode == null) { if (classNode == null) {
@ -79,7 +79,7 @@ namespace ICSharpCode.UnitTesting
} }
if (classNode != null) { if (classNode != null) {
return classNode.TestClass.Resolve(); return classNode.TestClass;
} }
return null; return null;
} }

13
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpMethodInsight.cs

@ -8,6 +8,7 @@ using System.Linq;
using ICSharpCode.NRefactory.Completion; using ICSharpCode.NRefactory.Completion;
using ICSharpCode.NRefactory.CSharp.Completion; using ICSharpCode.NRefactory.CSharp.Completion;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Editor.CodeCompletion; using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
@ -20,6 +21,7 @@ namespace CSharpBinding.Completion
readonly CSharpCompletionBinding binding; readonly CSharpCompletionBinding binding;
readonly ITextEditor editor; readonly ITextEditor editor;
IInsightWindow window; IInsightWindow window;
CSharpInsightItem initiallySelectedItem;
public CSharpMethodInsight(CSharpCompletionBinding binding, ITextEditor editor, int startOffset, IEnumerable<CSharpInsightItem> items) public CSharpMethodInsight(CSharpCompletionBinding binding, ITextEditor editor, int startOffset, IEnumerable<CSharpInsightItem> items)
{ {
@ -38,6 +40,8 @@ namespace CSharpBinding.Completion
window.StartOffset = startOffset; window.StartOffset = startOffset;
// closing the window at the end of the parameter list is handled by the CaretPositionChanged event // closing the window at the end of the parameter list is handled by the CaretPositionChanged event
window.EndOffset = editor.Document.TextLength; window.EndOffset = editor.Document.TextLength;
if (initiallySelectedItem != null)
window.SelectedItem = initiallySelectedItem;
window.CaretPositionChanged += window_CaretPositionChanged; window.CaretPositionChanged += window_CaretPositionChanged;
} }
@ -65,6 +69,15 @@ namespace CSharpBinding.Completion
if (parameterIndex < 0 && window != null) { if (parameterIndex < 0 && window != null) {
window.Close(); window.Close();
} else { } 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) if (parameterIndex > 0)
parameterIndex--; // NR returns 1-based parameter index parameterIndex--; // NR returns 1-based parameter index
foreach (var item in items) foreach (var item in items)

Loading…
Cancel
Save