Permalink
Browse files

Finally fix InUnitTestRunner on WinRT

Instead of vainly attempting to get a listing of the DLLs in our own
directory, pull the loaded module list. The first item will be the entry
point, which in the VS test runner is something we can recognize.
  • Loading branch information...
paulcbetts committed Dec 28, 2012
1 parent 433ac2c commit 430775262107d3f145424d67ecb1bc2f4ad9a4e4
Showing with 17 additions and 8 deletions.
  1. +17 −8 ReactiveUI/RxApp.cs
View
@@ -10,6 +10,7 @@
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reflection;
+using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
@@ -267,6 +268,8 @@ static bool inUnitTestRunner()
"MSBUILD",
"NBEHAVE",
"TESTPLATFORM",
+ "VSTEST",
+ "EXECUTIONENGINE",
};
string[] designEnvironments = new[] {
@@ -300,15 +303,13 @@ static bool inUnitTestRunner()
#elif WINRT
if (DesignMode.DesignModeEnabled) return true;
- var depPackages = Package.Current.Dependencies.Select(x => x.Id.FullName);
- if (depPackages.Any(x => testAssemblies.Any(name => x.ToUpperInvariant().Contains(name)))) return true;
-
- var fileTask = Task.Run(async () => {
- var files = await Package.Current.InstalledLocation.GetFilesAsync();
- return files.Select(x => x.Path).ToArray();
- });
+ var modList = new List<string>();
+ EnumerateLoadedModules64(GetCurrentProcess(), (name, basePtr, size, dontcare) => {
+ modList.Add(name);
+ return true;
+ }, IntPtr.Zero);
- return fileTask.Result.Any(x => testAssemblies.Any(name => x.ToUpperInvariant().Contains(name)));
+ return modList.Any(x => testAssemblies.Any(name => x.ToUpperInvariant().Contains(name)));
#else
// Try to detect whether we're in design mode - bonus points,
// without access to any WPF references :-/
@@ -489,6 +490,14 @@ static string getArchSuffixForPath(string path)
var m = re.Match(Path.GetFileName(path));
return m.Success ? m.Groups[1].Value : "";
}
+
+ internal delegate bool EnumLoadedModulesCallback([MarshalAs(UnmanagedType.LPStr)] string moduleName, ulong moduleBase, uint moduleSize, IntPtr dontCare);
+
+ [DllImport("dbghelp.dll")]
+ internal static extern bool EnumerateLoadedModules64(IntPtr hProcess, EnumLoadedModulesCallback callback, IntPtr useZero);
+
+ [DllImport("kernel32.dll")]
+ internal static extern IntPtr GetCurrentProcess();
}
public class NullDefaultPropertyBindingProvider : IDefaultPropertyBindingProvider

0 comments on commit 4307752

Please sign in to comment.