Permalink
Browse files

Fixing Unit Test Session restore for ReSharper 6.1 and above

  • Loading branch information...
1 parent aa2d271 commit dca91114d62ccc8119e860511ff53aadb6bfddc9 @agross agross committed Jan 17, 2012
Showing with 122 additions and 93 deletions.
  1. +50 −0 Source/Machine.Specifications.ReSharperRunner.4.1/MSpecUnitTestElementComparer.cs
  2. +1 −1 Source/Machine.Specifications.ReSharperRunner.4.1/MSpecUnitTestProvider.cs
  3. +1 −1 Source/Machine.Specifications.ReSharperRunner.4.1/Machine.Specifications.ReSharperRunner.4.1.csproj
  4. +0 −58 Source/Machine.Specifications.ReSharperRunner.4.1/UnitTestElementComparer.cs
  5. +2 −2 Source/Machine.Specifications.ReSharperRunner.4.5/Machine.Specifications.ReSharperRunner.4.5.csproj
  6. +1 −1 Source/Machine.Specifications.ReSharperRunner.5.0/Factories/BehaviorFactory.cs
  7. +1 −1 Source/Machine.Specifications.ReSharperRunner.5.0/Factories/BehaviorSpecificationFactory.cs
  8. +1 −1 Source/Machine.Specifications.ReSharperRunner.5.0/Factories/ContextSpecificationFactory.cs
  9. +2 −2 Source/Machine.Specifications.ReSharperRunner.5.0/Machine.Specifications.ReSharperRunner.5.0.csproj
  10. +2 −2 Source/Machine.Specifications.ReSharperRunner.5.1/Machine.Specifications.ReSharperRunner.5.1.csproj
  11. +2 −2 Source/Machine.Specifications.ReSharperRunner.6.0/Machine.Specifications.ReSharperRunner.6.0.csproj
  12. +3 −3 Source/Machine.Specifications.ReSharperRunner.6.0/Presentation/BehaviorElement.cs
  13. +3 −3 Source/Machine.Specifications.ReSharperRunner.6.0/Presentation/BehaviorSpecificationElement.cs
  14. +3 −2 Source/Machine.Specifications.ReSharperRunner.6.0/Presentation/ContextElement.cs
  15. +3 −3 Source/Machine.Specifications.ReSharperRunner.6.0/Presentation/ContextSpecificationElement.cs
  16. +45 −9 Source/Machine.Specifications.ReSharperRunner.6.1/MSpecUnitTestElementSerializer.cs
  17. +2 −2 Source/Machine.Specifications.ReSharperRunner.6.1/Machine.Specifications.ReSharperRunner.6.1.csproj
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+
+using Machine.Specifications.ReSharperRunner.Presentation;
+#if RESHARPER_5 || RESHARPER_6
+using JetBrains.ReSharper.UnitTestFramework;
+#else
+using JetBrains.ReSharper.UnitTestExplorer;
+#endif
+
+namespace Machine.Specifications.ReSharperRunner
+{
+#if RESHARPER_6
+ class MSpecUnitTestElementComparer : Comparer<IUnitTestElement>
+#else
+ class MSpecUnitTestElementComparer : Comparer<UnitTestElement>
+#endif
+ {
+ readonly Type[] _typeOrder;
+
+ public MSpecUnitTestElementComparer()
+ {
+ _typeOrder = new[]
+ {
+ typeof(ContextElement),
+ typeof(BehaviorElement),
+ typeof(BehaviorSpecificationElement),
+ typeof(ContextSpecificationElement)
+ };
+ }
+
+#if RESHARPER_6
+ public override int Compare(IUnitTestElement x, IUnitTestElement y)
+#else
+ public override int Compare(UnitTestElement x, UnitTestElement y)
+#endif
+ {
+ var different = Array.IndexOf(_typeOrder, x.GetType()) - Array.IndexOf(_typeOrder, y.GetType());
+ if (different != 0)
+ {
+ return different;
+ }
+#if RESHARPER_6
+ return x.ShortName.CompareTo(y.ShortName);
+#else
+ return x.GetTitle().CompareTo(y.GetTitle());
+#endif
+ }
+ }
+}
@@ -27,7 +27,7 @@ internal class MSpecUnitTestProvider : IUnitTestProvider
const string ProviderId = "Machine.Specifications";
static readonly Presenter Presenter = new Presenter();
readonly UnitTestTaskFactory _taskFactory = new UnitTestTaskFactory(ProviderId);
- readonly UnitTestElementComparer _unitTestElementComparer = new UnitTestElementComparer();
+ readonly MSpecUnitTestElementComparer _unitTestElementComparer = new MSpecUnitTestElementComparer();
public MSpecUnitTestProvider()
{
@@ -150,7 +150,7 @@
<Compile Include="Presentation\FieldElement.cs" />
<Compile Include="Tasks\Task.4.1.cs" />
<Compile Include="Tasks\Task.cs" />
- <Compile Include="UnitTestElementComparer.cs" />
+ <Compile Include="MSpecUnitTestElementComparer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Machine.Specifications\Machine.Specifications.csproj">
@@ -1,58 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-#if RESHARPER_5 || RESHARPER_6
-using JetBrains.ReSharper.UnitTestFramework;
-#else
-using JetBrains.ReSharper.UnitTestExplorer;
-#endif
-using Machine.Specifications.ReSharperRunner.Presentation;
-
-namespace Machine.Specifications.ReSharperRunner
-{
-#if RESHARPER_6
- internal class UnitTestElementComparer : Comparer<IUnitTestElement>
- {
-
- public override int Compare(IUnitTestElement x, IUnitTestElement y)
- {
-#else
- internal class UnitTestElementComparer : Comparer<UnitTestElement>
- {
-
- public override int Compare(UnitTestElement x, UnitTestElement y)
- {
-#endif
- if (Equals(x, y))
- {
- return 0;
- }
-
- if ((x is ContextSpecificationElement || x is BehaviorElement) && y is ContextElement)
- {
- return -1;
- }
-
- if (x is ContextElement && (y is ContextSpecificationElement || y is BehaviorElement))
- {
- return 1;
- }
-
- if (x is ContextSpecificationElement && y is BehaviorElement)
- {
- return 1;
- }
-
- if (x is BehaviorElement && y is ContextSpecificationElement)
- {
- return -1;
- }
-#if RESHARPER_6
- return StringComparer.CurrentCultureIgnoreCase.Compare(x.ShortName, y.ShortName);
-#else
- return StringComparer.CurrentCultureIgnoreCase.Compare(x.GetTitle(), y.GetTitle());
-#endif
- }
-
- }
-}
@@ -199,8 +199,8 @@
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\Tasks\Task.cs">
<Link>Tasks\Task.cs</Link>
</Compile>
- <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\UnitTestElementComparer.cs">
- <Link>UnitTestElementComparer.cs</Link>
+ <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\MSpecUnitTestElementComparer.cs">
+ <Link>MSpecUnitTestElementComparer.cs</Link>
</Compile>
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
@@ -101,7 +101,7 @@ public BehaviorElement CreateBehavior(IDeclaredElement field)
string fullyQualifiedTypeName)
{
#if RESHARPER_6
- var id = BehaviorElement.CreateId(context.TypeName, fieldName);
+ var id = BehaviorElement.CreateId(context.Id, fieldName);
#if RESHARPER_61
var behavior = manager.GetElementById(project, id) as BehaviorElement;
#else
@@ -110,7 +110,7 @@ public BehaviorSpecificationFactory(MSpecUnitTestProvider provider, IProject pro
bool isIgnored)
{
#if RESHARPER_6
- var id = BehaviorSpecificationElement.CreateId(behavior.TypeName, fieldName);
+ var id = BehaviorSpecificationElement.CreateId(behavior.Id, fieldName);
#if RESHARPER_61
var behaviorSpecification = manager.GetElementById(project, id) as BehaviorSpecificationElement;
#else
@@ -107,7 +107,7 @@ public ContextSpecificationElement CreateContextSpecification(ContextElement con
bool isIgnored)
{
#if RESHARPER_6
- var id = ContextSpecificationElement.CreateId(context.TypeName, fieldName);
+ var id = ContextSpecificationElement.CreateId(context.Id, fieldName);
#if RESHARPER_61
var contextSpecification = manager.GetElementById(project, id) as ContextSpecificationElement;
#else
@@ -174,8 +174,8 @@
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\Tasks\Task.cs">
<Link>Tasks\Task.cs</Link>
</Compile>
- <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\UnitTestElementComparer.cs">
- <Link>UnitTestElementComparer.cs</Link>
+ <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\MSpecUnitTestElementComparer.cs">
+ <Link>MSpecUnitTestElementComparer.cs</Link>
</Compile>
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.5\MSpecElementNaming.cs">
<Link>MSpecElementNaming.cs</Link>
@@ -174,8 +174,8 @@
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\Tasks\Task.cs">
<Link>Tasks\Task.cs</Link>
</Compile>
- <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\UnitTestElementComparer.cs">
- <Link>UnitTestElementComparer.cs</Link>
+ <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\MSpecUnitTestElementComparer.cs">
+ <Link>MSpecUnitTestElementComparer.cs</Link>
</Compile>
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.5\MSpecElementNaming.cs">
<Link>MSpecElementNaming.cs</Link>
@@ -171,8 +171,8 @@
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\Tasks\Task.cs">
<Link>Tasks\Task.cs</Link>
</Compile>
- <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\UnitTestElementComparer.cs">
- <Link>UnitTestElementComparer.cs</Link>
+ <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\MSpecUnitTestElementComparer.cs">
+ <Link>MSpecUnitTestElementComparer.cs</Link>
</Compile>
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.5\MSpecElementNaming.cs">
<Link>MSpecElementNaming.cs</Link>
@@ -99,12 +99,12 @@ public override void WriteToXml(XmlElement parent)
public override string Id
{
- get { return CreateId(TypeName, FieldName); }
+ get { return CreateId(Context.Id, FieldName); }
}
- public static string CreateId(string contextElementTypeName, string fieldName)
+ public static string CreateId(string contextElementId, string fieldName)
{
- var id = String.Format("{0}.{1}", contextElementTypeName, fieldName);
+ var id = String.Format("{0}.{1}", contextElementId, fieldName);
System.Diagnostics.Debug.WriteLine("BE " + id);
return id;
}
@@ -77,12 +77,12 @@ public override IEnumerable<UnitTestElementCategory> Categories
public override string Id
{
- get { return CreateId(Behavior.TypeName, FieldName); }
+ get { return CreateId(Behavior.Id, FieldName); }
}
- public static string CreateId(string behaviorElementTypeName, string fieldName)
+ public static string CreateId(string behaviorElementId, string fieldName)
{
- var id = String.Format("{0}.{1}", behaviorElementTypeName, fieldName);
+ var id = String.Format("{0}.{1}", behaviorElementId, fieldName);
System.Diagnostics.Debug.WriteLine("BSE " + id);
return id;
}
@@ -92,10 +92,11 @@ public override string Id
public void WriteToXml(XmlElement parent)
{
+ parent.SetAttribute("projectId", GetProject().GetPersistentID());
parent.SetAttribute("typeName", TypeName);
- parent.GetAttribute("assemblyLocation", AssemblyLocation);
+ parent.SetAttribute("assemblyLocation", AssemblyLocation);
parent.SetAttribute("isIgnored", Explicit.ToString());
- parent.GetAttribute("subject", GetSubject());
+ parent.SetAttribute("subject", _subject);
}
public static IUnitTestElement ReadFromXml(XmlElement parent, IUnitTestElement parentElement, MSpecUnitTestProvider provider, ISolution solution
@@ -88,13 +88,13 @@ public override string Id
{
get
{
- return CreateId(TypeName, FieldName);
+ return CreateId(Context.Id, FieldName);
}
}
- public static string CreateId(string contextElementTypeName, string fieldName)
+ public static string CreateId(string contextElementId, string fieldName)
{
- var id = String.Format("{0}.{1}", contextElementTypeName, fieldName);
+ var id = String.Format("{0}.{1}", contextElementId, fieldName);
System.Diagnostics.Debug.WriteLine("CSE " + id);
return id;
}
@@ -13,13 +13,17 @@ namespace Machine.Specifications.ReSharperRunner
[SolutionComponent]
public class MSpecUnitTestElementSerializer : IUnitTestElementSerializer
{
- readonly ISolution _solution;
- readonly MSpecUnitTestProvider _provider;
+ readonly CacheManager _cacheManager;
readonly IUnitTestElementManager _manager;
+ readonly MSpecUnitTestProvider _provider;
readonly PsiModuleManager _psiModuleManager;
- readonly CacheManager _cacheManager;
+ readonly ISolution _solution;
- public MSpecUnitTestElementSerializer(ISolution solution, MSpecUnitTestProvider provider, IUnitTestElementManager manager, PsiModuleManager psiModuleManager, CacheManager cacheManager)
+ public MSpecUnitTestElementSerializer(ISolution solution,
+ MSpecUnitTestProvider provider,
+ IUnitTestElementManager manager,
+ PsiModuleManager psiModuleManager,
+ CacheManager cacheManager)
{
_solution = solution;
_provider = provider;
@@ -40,16 +44,48 @@ public void SerializeElement(XmlElement parent, IUnitTestElement element)
public IUnitTestElement DeserializeElement(XmlElement parent, IUnitTestElement parentElement)
{
- var typeName = parent.GetAttribute("elemenType");
+ var typeName = parent.GetAttribute("elementType");
if (Equals(typeName, "ContextElement"))
- return ContextElement.ReadFromXml(parent, parentElement, _provider, _solution, _manager, _psiModuleManager, _cacheManager);
+ {
+ return ContextElement.ReadFromXml(parent,
+ parentElement,
+ _provider,
+ _solution,
+ _manager,
+ _psiModuleManager,
+ _cacheManager);
+ }
if (Equals(typeName, "BehaviorElement"))
- return BehaviorElement.ReadFromXml(parent, parentElement, _provider, _solution, _manager, _psiModuleManager, _cacheManager);
+ {
+ return BehaviorElement.ReadFromXml(parent,
+ parentElement,
+ _provider,
+ _solution,
+ _manager,
+ _psiModuleManager,
+ _cacheManager);
+ }
if (Equals(typeName, "BehaviorSpecificationElement"))
- return BehaviorSpecificationElement.ReadFromXml(parent, parentElement, _provider, _solution, _manager, _psiModuleManager, _cacheManager);
+ {
+ return BehaviorSpecificationElement.ReadFromXml(parent,
+ parentElement,
+ _provider,
+ _solution,
+ _manager,
+ _psiModuleManager,
+ _cacheManager);
+ }
if (Equals(typeName, "ContextSpecificationElement"))
- return ContextSpecificationElement.ReadFromXml(parent, parentElement, _provider, _solution, _manager, _psiModuleManager, _cacheManager);
+ {
+ return ContextSpecificationElement.ReadFromXml(parent,
+ parentElement,
+ _provider,
+ _solution,
+ _manager,
+ _psiModuleManager,
+ _cacheManager);
+ }
return null;
}
@@ -168,8 +168,8 @@
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\Tasks\Task.cs">
<Link>Tasks\Task.cs</Link>
</Compile>
- <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\UnitTestElementComparer.cs">
- <Link>UnitTestElementComparer.cs</Link>
+ <Compile Include="..\Machine.Specifications.ReSharperRunner.4.1\MSpecUnitTestElementComparer.cs">
+ <Link>MSpecUnitTestElementComparer.cs</Link>
</Compile>
<Compile Include="..\Machine.Specifications.ReSharperRunner.4.5\MSpecElementNaming.cs">
<Link>MSpecElementNaming.cs</Link>

0 comments on commit dca9111

Please sign in to comment.