forked from sdekock/AgUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Silverlight test debugging. Fixed dummy test projects.
- Loading branch information
Steven De Kock
committed
Jul 22, 2011
1 parent
f485422
commit 51577a4
Showing
14 changed files
with
292 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 51 additions & 6 deletions
57
src/AgUnit.Runner.Resharper60/UnitTestFramework/ExtendedDebugTaskRunnerHostController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,70 @@ | ||
extern alias util; | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using AgUnit.Runner.Resharper60.UnitTestFramework.SilverlightPlatform; | ||
using AgUnit.Runner.Resharper60.Util; | ||
using EnvDTE; | ||
using JetBrains.ReSharper.UnitTestExplorer; | ||
using JetBrains.ReSharper.UnitTestFramework; | ||
using JetBrains.Threading; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
using util::JetBrains.Util.Lazy; | ||
using util::JetBrains.Util; | ||
using Thread = System.Threading.Thread; | ||
|
||
namespace AgUnit.Runner.Resharper60.UnitTestFramework | ||
{ | ||
public class ExtendedDebugTaskRunnerHostController : DebugTaskRunnerHostController | ||
{ | ||
public ExtendedDebugTaskRunnerHostController(UnitTestManager manager, UnitTestSessionManager sessionManager, Lazy<IVsDebugger2> debugger2, DTE dte, IThreading threading, IUnitTestLaunch launch, string remotingAddress) | ||
public ExtendedDebugTaskRunnerHostController(UnitTestManager manager, UnitTestSessionManager sessionManager, util::JetBrains.Util.Lazy.Lazy<IVsDebugger2> debugger2, DTE dte, IThreading threading, IUnitTestLaunch launch, string remotingAddress) | ||
: base(manager, sessionManager, debugger2, dte, threading, launch, remotingAddress) | ||
{ } | ||
|
||
// TODO: If we have a Silverlight test run, we should attach the Silverlight debugger here instead of the .NET/COM debugger. | ||
// See the implementation in the version of AgUnit for R# 5.0: https://hg01.codeplex.com/agunit/file/e1d353fe2274/AgUnit.Runner.Resharper50/UnitTestHost/AgUnitHostController.cs | ||
public override void Run(string remotingAddress, IUnitTestRun run) | ||
{ | ||
base.Run(remotingAddress, run); | ||
if (run.IsSilverlightRun()) | ||
{ | ||
RunWithSilverlightDebugger(remotingAddress, run); | ||
} | ||
else | ||
{ | ||
base.Run(remotingAddress, run); | ||
} | ||
} | ||
|
||
private void RunWithSilverlightDebugger(string remotingAddress, IUnitTestRun run) | ||
{ | ||
var targetInfo = CreateTargetInfo(remotingAddress, run); | ||
|
||
this.SetField("myRunId", run.ID); | ||
this.SetField("myTargetInfo", targetInfo); | ||
|
||
new Thread(CallThreadProc) { IsBackground = true }.Start(); | ||
} | ||
|
||
private VsDebugTargetInfo2 CreateTargetInfo(string remotingAddress, IUnitTestRun run) | ||
{ | ||
var runnerPath = GetTaskRunnerPathForRun(run); | ||
var runnerArgs = GetTaskRunnerCommandLineArgs(remotingAddress, run.ID); | ||
var silverlightDebugEngineGuid = new Guid("032F4B8C-7045-4B24-ACCF-D08C9DA108FE"); | ||
|
||
var debugTargetInfo = new VsDebugTargetInfo2 | ||
{ | ||
dlo = 1U, | ||
bstrExe = runnerPath.FullPath, | ||
bstrCurDir = runnerPath.Directory.FullPath, | ||
bstrArg = runnerArgs, | ||
guidLaunchDebugEngine = silverlightDebugEngineGuid, | ||
LaunchFlags = 97U | ||
}; | ||
|
||
debugTargetInfo.cbSize = (uint)Marshal.SizeOf(debugTargetInfo); | ||
|
||
return debugTargetInfo; | ||
} | ||
|
||
private void CallThreadProc() | ||
{ | ||
Logger.Catch(() => this.CallMethod("ThreadProc")); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/AgUnit.Runner.Resharper60/UnitTestFramework/HostProviderWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...Resharper60/UnitTestFramework/SilverlightPlatform/SilverlightPlatformSupportExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ReSharper.UnitTestExplorer; | ||
using JetBrains.ReSharper.UnitTestFramework; | ||
|
||
namespace AgUnit.Runner.Resharper60.UnitTestFramework.SilverlightPlatform | ||
{ | ||
public static class SilverlightPlatformSupportExtensions | ||
{ | ||
public static void EnsureSilverlightPlatformSupport(this IUnitTestLaunch launch, UnitTestManager manager) | ||
{ | ||
var runs = launch.GetRuns(); | ||
|
||
foreach (var run in runs.Values.ToArray()) | ||
{ | ||
foreach (var sequence in run.GetSequences().ToArray()) | ||
{ | ||
ConvertToSilverlightSequenceIfNecessary(sequence, run, launch, manager); | ||
} | ||
} | ||
|
||
launch.RemoveEmptyRuns(); | ||
} | ||
|
||
private static void ConvertToSilverlightSequenceIfNecessary(IList<UnitTestTask> sequence, UnitTestRun run, IUnitTestLaunch launch, UnitTestManager manager) | ||
{ | ||
if (!sequence.IsSilverlightSequence()) | ||
{ | ||
var requiredSilverlightPlatform = sequence.GetRequiredSilverlightPlatform(); | ||
if (requiredSilverlightPlatform != null) | ||
{ | ||
run.GetSequences().Remove(sequence); | ||
|
||
CreateSilverlightSequence(sequence, launch, manager, requiredSilverlightPlatform); | ||
} | ||
} | ||
} | ||
|
||
private static void CreateSilverlightSequence(IList<UnitTestTask> sequence, IUnitTestLaunch launch, UnitTestManager manager, PlatformID silverlightPlatform) | ||
{ | ||
var silverlightRun = launch.GetOrCreateSilverlightRun(silverlightPlatform); | ||
|
||
sequence.AddSilverlightUnitTestTask(silverlightPlatform, manager); | ||
sequence.RemoveAssemblyLoadTasks(); | ||
|
||
silverlightRun.AddTaskSequence(sequence); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...Unit.Runner.Resharper60/UnitTestFramework/SilverlightPlatform/UnitTestLaunchExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using AgUnit.Runner.Resharper60.Util; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ReSharper.TaskRunnerFramework; | ||
using JetBrains.ReSharper.UnitTestExplorer; | ||
using JetBrains.ReSharper.UnitTestFramework; | ||
|
||
namespace AgUnit.Runner.Resharper60.UnitTestFramework.SilverlightPlatform | ||
{ | ||
public static class UnitTestLaunchExtensions | ||
{ | ||
public static void RemoveEmptyRuns(this IUnitTestLaunch launch) | ||
{ | ||
var runs = launch.GetRuns(); | ||
var emptyRuns = runs.Values.Where(run => !run.GetSequences().Any()).ToArray(); | ||
|
||
foreach (var run in emptyRuns) | ||
{ | ||
runs.Remove(run.ID); | ||
} | ||
} | ||
|
||
public static UnitTestRun GetOrCreateSilverlightRun(this IUnitTestLaunch launch, PlatformID silverlightPlatform) | ||
{ | ||
var runs = launch.GetRuns(); | ||
var silverlightRun = runs.Values.FirstOrDefault(run => run.GetSilverlightPlatformVersion() == silverlightPlatform.Version); | ||
|
||
if (silverlightRun == null) | ||
{ | ||
var runtimeEnvironment = new RuntimeEnvironment { PlatformType = PlatformType.x86, PlatformVersion = PlatformVersion.v4_0 }; | ||
silverlightRun = new UnitTestRun((UnitTestLaunch)launch, runtimeEnvironment); | ||
runs.Add(silverlightRun.ID, silverlightRun); | ||
} | ||
|
||
return silverlightRun; | ||
} | ||
|
||
public static Dictionary<string, UnitTestRun> GetRuns(this IUnitTestLaunch launch) | ||
{ | ||
return launch.GetField<Dictionary<string, UnitTestRun>>("myRuns"); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/AgUnit.Runner.Resharper60/UnitTestFramework/SilverlightPlatform/UnitTestRunExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using AgUnit.Runner.Resharper60.Util; | ||
using JetBrains.ReSharper.UnitTestFramework; | ||
|
||
namespace AgUnit.Runner.Resharper60.UnitTestFramework.SilverlightPlatform | ||
{ | ||
public static class UnitTestRunExtensions | ||
{ | ||
public static bool IsSilverlightRun(this IUnitTestRun run) | ||
{ | ||
return run.GetSilverlightPlatformVersion() != null; | ||
} | ||
|
||
public static Version GetSilverlightPlatformVersion(this IUnitTestRun run) | ||
{ | ||
var sequence = run.GetSequences().FirstOrDefault(); | ||
return sequence != null ? sequence.GetSilverlightPlatformVersion() : null; | ||
} | ||
|
||
public static IList<IList<UnitTestTask>> GetSequences(this IUnitTestRun run) | ||
{ | ||
return run.GetField<IList<IList<UnitTestTask>>>("mySequences"); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...it.Runner.Resharper60/UnitTestFramework/SilverlightPlatform/UnitTestSequenceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using AgUnit.Runner.Resharper60.UnitTestFramework.Silverlight; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ReSharper.TaskRunnerFramework; | ||
using JetBrains.ReSharper.UnitTestFramework; | ||
using PlatformID = JetBrains.ProjectModel.PlatformID; | ||
|
||
namespace AgUnit.Runner.Resharper60.UnitTestFramework.SilverlightPlatform | ||
{ | ||
public static class UnitTestSequenceExtensions | ||
{ | ||
public static PlatformID GetRequiredSilverlightPlatform(this IList<UnitTestTask> sequence) | ||
{ | ||
return sequence | ||
.Where(task => task.Element != null) | ||
.Select(task => task.Element.GetProject()) | ||
.Where(project => project != null) | ||
.Select(project => project.PlatformID) | ||
.FirstOrDefault(platform => platform != null && platform.Identifier == FrameworkIdentifier.Silverlight); | ||
} | ||
|
||
public static bool IsSilverlightSequence(this IList<UnitTestTask> sequence) | ||
{ | ||
return sequence.GetSilverlightUnitTestTask() != null; | ||
} | ||
|
||
public static Version GetSilverlightPlatformVersion(this IList<UnitTestTask> sequence) | ||
{ | ||
var silverlightUnitTestTask = sequence.GetSilverlightUnitTestTask(); | ||
return silverlightUnitTestTask != null ? silverlightUnitTestTask.SilverlightPlatformVersion : null; | ||
} | ||
|
||
public static SilverlightUnitTestTask GetSilverlightUnitTestTask(this IList<UnitTestTask> sequence) | ||
{ | ||
return sequence.Select(task => task.RemoteTask).FirstOrDefault() as SilverlightUnitTestTask; | ||
} | ||
|
||
public static void AddSilverlightUnitTestTask(this IList<UnitTestTask> sequence, PlatformID silverlightPlatform, UnitTestManager manager) | ||
{ | ||
var provider = manager.GetProvider(SilverlightUnitTestProvider.RunnerId); | ||
var element = new SilverlightUnitTestElement(provider); | ||
var remoteTask = new SilverlightUnitTestTask(silverlightPlatform.Version); | ||
sequence.Insert(0, new UnitTestTask(element, remoteTask)); | ||
} | ||
|
||
public static void RemoveAssemblyLoadTasks(this IList<UnitTestTask> sequence) | ||
{ | ||
var assemblyLoadTasks = sequence.Where(t => t.RemoteTask is AssemblyLoadTask).ToArray(); | ||
foreach (var assemblyLoadTask in assemblyLoadTasks) | ||
{ | ||
sequence.Remove(assemblyLoadTask); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.