public static void Launch() { var debugSessionID = Environment.GetEnvironmentVariable("DEBUG_SESSION_ID"); if (string.IsNullOrWhiteSpace(debugSessionID)) { ApplicationTestRunner.RunAllTests(Assembly.GetExecutingAssembly()); } else { var debugStopOnEntry = (Environment.GetEnvironmentVariable("DEBUG_STOP_ON_ENTRY") ?? string.Empty).Equals("true", StringComparison.OrdinalIgnoreCase); if (debugStopOnEntry && !Debugger.IsAttached) { Debugger.Launch(); } using (var debuggingInstance = new Debugging(debugSessionID)) { debuggingInstance.InitializeDebugConnection(); debuggingInstance.SetupRpcDebuggingHook(); // Run all tests (blocking) ApplicationTestRunner.RunAllTests(Assembly.GetExecutingAssembly()); Console.WriteLine("Tests completed"); } } }
public static void Launch() { var debugSessionID = Environment.GetEnvironmentVariable("DEBUG_SESSION_ID"); if (string.IsNullOrWhiteSpace(debugSessionID)) { ApplicationTestRunner.RunAllTests(Assembly.GetExecutingAssembly()); } else { var debugStopOnEntry = (Environment.GetEnvironmentVariable("DEBUG_STOP_ON_ENTRY") ?? string.Empty).Equals("true", StringComparison.OrdinalIgnoreCase); if (debugStopOnEntry && !Debugger.IsAttached) { Debugger.Launch(); } using (var debuggingInstance = new Debugging(debugSessionID)) { debuggingInstance.InitializeDebugConnection(); debuggingInstance.SetupRpcDebuggingHook(); var cancelToken = new CancellationTokenSource(); debuggingInstance.OnDebuggerDisconnect += () => { // If the C# debugger is not attached, we don't care about running the rest of the tests // so exit program if (!Debugger.IsAttached) { cancelToken.Cancel(); Environment.Exit(0); } }; // Run all tests (blocking) ApplicationTestRunner.RunAllTests(Assembly.GetExecutingAssembly(), cancelToken.Token); Console.WriteLine("Tests completed"); } } }