Skip to content

Commit

Permalink
Implemented Silverlight test debugging. Fixed dummy test projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven De Kock committed Jul 22, 2011
1 parent f485422 commit 51577a4
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 170 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using JetBrains.ReSharper.TaskRunnerFramework;
Expand Down Expand Up @@ -38,7 +37,7 @@ public override TaskResult Finish(TaskExecutionNode node)

public override void ExecuteRecursive(TaskExecutionNode node)
{
Debugger.Break();
//Debugger.Break();

try
{
Expand Down
13 changes: 8 additions & 5 deletions src/AgUnit.Runner.Resharper60/AgUnit.Runner.Resharper60.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<ReferencePath>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\JetBrains\ReSharper\v6.0\vs10.0@InstallDir)</ReferencePath>
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/ReSharper.Plugin AgUnit.Runner.Resharper60.dll /ReSharper.LogFile C:\resharper.log /ReSharper.LogLevel Verbose ..\src\DummyTests\VS2010\DummyTests.sln</StartArguments>
<ReferencePath>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\JetBrains\ReSharper\v6.0\vs10.0@InstallDir)</ReferencePath>
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/ReSharper.Plugin AgUnit.Runner.Resharper60.dll /ReSharper.LogFile C:\resharper.log /ReSharper.LogLevel Verbose ..\src\DummyTests\VS2010\DummyTests.sln</StartArguments>
<OutputPath>..\..\output\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down Expand Up @@ -127,11 +127,14 @@
<Compile Include="UnitTestFramework\HostProviderWrapper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\PluginInfo.cs" />
<Compile Include="UnitTestFramework\SilverlightPlatform\SilverlightPlatformSupportExtensions.cs" />
<Compile Include="UnitTestFramework\SilverlightPlatform\UnitTestRunExtensions.cs" />
<Compile Include="UnitTestFramework\SilverlightPlatform\UnitTestSequenceExtensions.cs" />
<Compile Include="UnitTestProvider\MSTest\SilverlightMsTestMetadataExplorer.cs" />
<Compile Include="UnitTestFramework\Silverlight\SilverlightUnitTestElement.cs" />
<Compile Include="UnitTestFramework\Silverlight\SilverlightUnitTestProvider.cs" />
<Compile Include="UnitTestFramework\Silverlight\SilverlightUnitTestTask.cs" />
<Compile Include="UnitTestFramework\UnitTestLaunchExtensions.cs" />
<Compile Include="UnitTestFramework\SilverlightPlatform\UnitTestLaunchExtensions.cs" />
<Compile Include="Util\ReflectionExtensions.cs" />
<Compile Include="Util\Tuple.cs" />
</ItemGroup>
Expand Down
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"));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern alias util;
using AgUnit.Runner.Resharper60.UnitTestFramework.SilverlightPlatform;
using JetBrains.ReSharper.UnitTestFramework;

namespace AgUnit.Runner.Resharper60.UnitTestFramework
Expand Down
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);
}
}
}
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");
}
}
}
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");
}
}
}
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);
}
}
}
}
Loading

0 comments on commit 51577a4

Please sign in to comment.