コード例 #1
0
        public void TestKill()
        {
            string tempfile = Path.GetTempFileName();

            try
            {
                Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"));
                ProcessRunner runner = new ProcessRunner("cmd.exe");
                Assert.IsFalse(runner.IsRunning);
                runner.Kill();                 // always safe to call

                runner.Start("/K", "ECHO Hello > " + tempfile);
                Assert.IsTrue(runner.IsRunning);

                try                 //make sure we can't start twice.
                {
                    runner.Start("/C", "ECHO", "HELO");
                    Assert.Fail();
                }
                catch (InvalidOperationException)
                { }

                Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), false));
                runner.Kill();
                string output = File.ReadAllText(tempfile).Trim();
                Assert.AreEqual("Hello", output);
            }
            finally
            { File.Delete(tempfile); }
        }
コード例 #2
0
        bool Get32BitFlags(string assembly)
        {
            assembly = Path.Combine(binPath, assembly);
            string corflags = FileUtility.GetSdkPath("corflags.exe");

            Assert.IsNotNull(corflags, "corflags.exe not found, this test requires the .NET SDK!");
            ProcessRunner pr = new ProcessRunner();

            Console.WriteLine(corflags + " \"" + assembly + "\"");
            pr.Start(corflags, "\"" + assembly + "\"");
            if (!pr.WaitForExit(5000))
            {
                pr.Kill();
                throw new InvalidOperationException("Timeout running corflags");
            }
            else
            {
                Console.WriteLine(pr.StandardOutput);
                Match m = Regex.Match(pr.StandardOutput, @"32BIT\s*:\s*([01])");
                if (m.Success)
                {
                    return(m.Groups[1].Value == "1");
                }
                else
                {
                    throw new InvalidOperationException("Invalid corflags output");
                }
            }
        }
コード例 #3
0
        public void Cancel()
        {
            runner.Start(GetConsoleAppFileName(), "-forever");

            string processName = Path.GetFileName(GetConsoleAppFileName());

            processName = Path.ChangeExtension(processName, null);

            // Check console app is running.
            Process[] runningProcesses = Process.GetProcessesByName(processName);
            Assert.AreEqual(1, runningProcesses.Length, "Process is not running.");

            Assert.IsTrue(runner.IsRunning, "IsRunning should be true.");
            runner.Kill();
            Assert.IsFalse(runner.IsRunning, "IsRunning should be false.");

            // Check console app has been shutdown.
            runningProcesses = Process.GetProcessesByName(processName);
            if (runningProcesses.Length == 1)
            {
                // Windows kills the process asynchronously, so sometimes we have to wait a bit
                if (!runningProcesses[0].WaitForExit(2500))
                {
                    Assert.Fail("Process should have stopped.");
                }
            }
            else
            {
                Assert.AreEqual(0, runningProcesses.Length, "Process should have stopped.");
            }
        }
コード例 #4
0
 /// <summary>
 /// Stops the currently running PartCover instance.
 /// </summary>
 public void Stop()
 {
     if (runner != null)
     {
         runner.Kill();
         OnStopped();
     }
 }
コード例 #5
0
        public void Cancel()
        {
            runner.Start(GetConsoleAppFileName(), "-forever");

            string processName = Path.GetFileName(GetConsoleAppFileName());

            processName = Path.ChangeExtension(processName, null);

            // Check console app is running.
            Process[] runningProcesses = Process.GetProcessesByName(processName);
            Assert.AreEqual(1, runningProcesses.Length, "Process is not running.");

            Assert.IsTrue(runner.IsRunning, "IsRunning should be true.");
            runner.Kill();
            Assert.IsFalse(runner.IsRunning, "IsRunning should be false.");

            // Check console app has been shutdown.
            runningProcesses = Process.GetProcessesByName(processName);
            Assert.AreEqual(0, runningProcesses.Length, "Process should have stopped.");
        }
コード例 #6
0
 protected override void OnStop()
 {
     runner.Kill();
 }
コード例 #7
0
 public void Kill()
 {
     runner.Kill();
 }