Permalink
Browse files

Context & Field elements updated

  • Loading branch information...
kropp committed May 24, 2011
1 parent 1e3f30f commit 00063b6d4e2a9f53565580badcc4ce8e4faf0683
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+
+using JetBrains.Application;
+using JetBrains.ProjectModel;
+using JetBrains.ReSharper.Psi;
+using JetBrains.ReSharper.Psi.Caches;
+using JetBrains.ReSharper.UnitTestFramework;
+using JetBrains.Text;
+
+using Machine.Specifications.Utility;
+using Machine.Specifications.Utility.Internal;
+
+namespace Machine.Specifications.ReSharperRunner.Presentation
+{
+ internal class ContextElement : Element
+ {
+ readonly string _assemblyLocation;
+ readonly string _subject;
+ IEnumerable<UnitTestElementCategory> _categories;
+
+ public ContextElement(MSpecUnitTestProvider provider,
+ ProjectModelElementEnvoy projectEnvoy,
+ string typeName,
+ string assemblyLocation,
+ string subject,
+ ICollection<string> tags,
+ bool isIgnored)
+ : base(provider, null, projectEnvoy, typeName, isIgnored)
+ {
+ _assemblyLocation = assemblyLocation;
+ _subject = subject;
+
+ if (tags != null)
+ {
+ _categories = UnitTestElementCategory.Create(tags);
+ }
+ }
+
+ public override string ShortName
+ {
+ get { return Kind; }
+ }
+
+ public override string AssemblyLocation
+ {
+ get { return _assemblyLocation; }
+ }
+
+ public override string GetPresentation()
+ {
+ return GetSubject() + new ClrTypeName(GetTypeClrName()).ShortName.ToFormat();
+ }
+
+ string GetSubject()
+ {
+ if (String.IsNullOrEmpty(_subject))
+ {
+ return null;
+ }
+
+ return _subject + ", ";
+ }
+
+ public override IDeclaredElement GetDeclaredElement()
+ {
+ return GetDeclaredType();
+ }
+
+ public override string Kind
+ {
+ get { return "Context"; }
+ }
+
+ public override IEnumerable<UnitTestElementCategory> Categories
+ {
+ get { return _categories; }
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (base.Equals(obj))
+ {
+ ContextElement other = (ContextElement)obj;
+ return Equals(AssemblyLocation, other.AssemblyLocation);
+ }
+
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ int result = base.GetHashCode();
+ result = 29 * result + AssemblyLocation.GetHashCode();
+ return result;
+ }
+ }
+}
@@ -18,11 +18,11 @@ internal abstract class Element : IUnitTestElement
protected Element(MSpecUnitTestProvider provider,
Element parent,
- IProjectModelElement project,
+ ProjectModelElementEnvoy projectEnvoy,
string declaringTypeName,
bool isIgnored)
{
- if (project == null && !Shell.Instance.IsTestShell)
+ if (projectEnvoy == null && !Shell.Instance.IsTestShell)
{
throw new ArgumentNullException("project");
}
@@ -32,9 +32,9 @@ internal abstract class Element : IUnitTestElement
throw new ArgumentNullException("declaringTypeName");
}
- if (project != null)
+ if (projectEnvoy != null)
{
- _projectEnvoy = new ProjectModelElementEnvoy(project);
+ _projectEnvoy = projectEnvoy;
}
_provider = provider;
@@ -46,16 +46,14 @@ internal abstract class Element : IUnitTestElement
}
TypeName = declaringTypeName;
- ShortName = shortName;
- AssemblyLocation = assemblyLocation;
Parent = parent;
Children = new List<IUnitTestElement>();
State = UnitTestElementState.Valid;
}
public string TypeName { get; protected set; }
- public string AssemblyLocation { get; private set; }
+ public abstract string AssemblyLocation { get; }
public abstract string Kind { get; }
public abstract IEnumerable<UnitTestElementCategory> Categories { get; }
public string ExplicitReason { get; private set; }
@@ -68,7 +66,7 @@ public string Id
public IUnitTestProvider Provider { get { return _provider; } }
public IUnitTestElement Parent { get; set; }
public ICollection<IUnitTestElement> Children { get; private set; }
- public string ShortName { get; private set; }
+ public abstract string ShortName { get; }
public bool Explicit
{
@@ -14,13 +14,13 @@ internal abstract class FieldElement : Element
{
readonly string _fieldName;
- protected FieldElement(IUnitTestProvider provider,
- UnitTestElement parent,
+ protected FieldElement(MSpecUnitTestProvider provider,
+ Element parent,
ProjectModelElementEnvoy projectEnvoy,
string declaringTypeName,
string fieldName,
bool isIgnored)
- : base(provider, parent, projectEnvoy, declaringTypeName, isIgnored || parent.IsExplicit)
+ : base(provider, parent, projectEnvoy, declaringTypeName, isIgnored || parent.Explicit)
{
_fieldName = fieldName;
}
@@ -35,23 +35,14 @@ public string FieldName
get { return _fieldName; }
}
- public override string GetTitle()
+ public override string GetPresentation()
{
return String.Format("{0}{1}{2}",
GetTitlePrefix(),
String.IsNullOrEmpty(GetTitlePrefix()) ? String.Empty : " ",
FieldName.ToFormat());
}
- public override bool Matches(string filter, IdentifierMatcher matcher)
- {
- if (Parent.Matches(filter, matcher))
- {
- return true;
- }
- return matcher.Matches(FieldName);
- }
-
public override IDeclaredElement GetDeclaredElement()
{
ITypeElement declaredType = GetDeclaredType();

0 comments on commit 00063b6

Please sign in to comment.