Skip to content

Instantly share code, notes, and snippets.

@jamesrcounts
Created July 2, 2012 01:52
Show Gist options
  • Select an option

  • Save jamesrcounts/3030471 to your computer and use it in GitHub Desktop.

Select an option

Save jamesrcounts/3030471 to your computer and use it in GitHub Desktop.
Patch for VisualStudioReporter

Alternate method seems to work more reliably. Old version only works under MSTEST, since the module we looked for was an MSTEST module. This version gets the parent process and checks if the parent process was VS11. Actually old version isn't working for me under MSTEST either, not sure when it stopped working since I haven't been using VS2012 much.

I should say that it doesn't work with FirstWorkingReporter. It works when used directly.

Index: ApprovalTests/Reporters/VisualStudioReporter.cs
===================================================================
--- ApprovalTests/Reporters/VisualStudioReporter.cs (revision 415)
+++ ApprovalTests/Reporters/VisualStudioReporter.cs (working copy)
@@ -1,5 +1,4 @@
-using System.Linq;
-
+using System.Diagnostics;
namespace ApprovalTests.Reporters
{
public class VisualStudioReporter : GenericDiffReporter
@@ -20,9 +19,13 @@
return base.IsWorkingInThisEnvironment(forFile) && LaunchedFromVisualStudio();
}
- private bool LaunchedFromVisualStudio()
+ // http://msdn.microsoft.com/en-us/netframework/aa569609.aspx#Question3
+ private static bool LaunchedFromVisualStudio()
{
- return Approvals.CurrentCaller.Methods.Any(m => m.Module.Assembly.FullName.StartsWith("Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=11."));
+ var currentProcess = Process.GetCurrentProcess();
+ PerformanceCounter pc = new PerformanceCounter("Process", "Creating Process Id", currentProcess.ProcessName);
+ Process p = Process.GetProcessById((int)pc.RawValue);
+ return PATH == p.MainModule.FileName;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment