Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Supporting Behaviors external to the spec project

  • Loading branch information...
commit be18feff88f44102680d3fad64dfd54f54bbe73c 1 parent 51e8254
@agross agross authored
View
38 Source/Machine.Specifications.ReSharperRunner.6.1/Explorers/ElementHandlers/BehaviorElementHandler.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
+using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.UnitTestFramework;
@@ -61,13 +62,42 @@ public IEnumerable<UnitTestElementDisposition> AcceptElement(ITreeNode element,
var behaviorSpecification = _behaviorSpecifications.CreateBehaviorSpecification(behavior, field);
- yield return new UnitTestElementDisposition(behaviorSpecification,
- field.GetSourceFiles()[0].ToProjectFile(),
- new TextRange(),
- field.GetDeclarations()[0].GetDocumentRange().TextRange);
+ var projectFile = GetProjectFile(field);
+ if (projectFile != null)
+ {
+ yield return new UnitTestElementDisposition(behaviorSpecification,
+ projectFile,
+ new TextRange(),
+ GetTextRange(field));
+ }
+ else
+ {
+ yield return new UnitTestElementDisposition(new UnitTestElementLocation[] {}, behaviorSpecification);
+ }
}
}
+ static IProjectFile GetProjectFile(IDeclaredElement field)
+ {
+ var sourceFile = field.GetSourceFiles();
+ if (sourceFile.Count > 0)
+ {
+ return sourceFile[0].ToProjectFile();
+ }
+ return null;
+ }
+
+ static TextRange GetTextRange(IDeclaredElement field)
+ {
+ var declarations = field.GetDeclarations();
+ if (declarations.Count > 0)
+ {
+ return declarations[0].GetDocumentRange().TextRange;
+ }
+
+ return new TextRange();
+ }
+
public void Cleanup(ITreeNode element)
{
var declaration = (IDeclaration) element;
Please sign in to comment.
Something went wrong with that request. Please try again.