Ejemplo n.º 1
0
        public void StartAndWaitForExit_StartProcessThatDoesNothing_ErrorOutputIsEmpty()
        {
            var runner = new ExecutableRunner();

            string standardOutput, errorOutput;

            runner.StartAndWaitForExit("cmd", "/c rem", out standardOutput, out errorOutput);

            Assert.IsTrue(String.IsNullOrWhiteSpace(errorOutput));
        }
Ejemplo n.º 2
0
        public void StartAndWaitForExit_EchoErrorOutput_ErrorOutputIsBeingCaptured()
        {
            var runner = new ExecutableRunner();

            string standardOutput, errorOutput;

            runner.StartAndWaitForExit("cmd", "/c echo message 1>&2", TimeSpan.FromSeconds(1), out standardOutput, out errorOutput);

            Assert.AreEqual("message", errorOutput.Trim());
        }
Ejemplo n.º 3
0
        public void StartAndWaitForExit_EchoErrorOutput_OnErrorLineFiringEvent()
        {
            var runner = new ExecutableRunner();

            var lines = new List <string>();

            runner.OnErrorLine += line => lines.Add(line.Trim());
            runner.StartAndWaitForExit("cmd", "/c echo message 1>&2", TimeSpan.FromSeconds(1));

            Assert.Contains("message", lines);
        }
Ejemplo n.º 4
0
        public void SetEnvironmentVariable_StartAndWaitForExitEchoVariable_ValueOfVariable()
        {
            var runner = new ExecutableRunner();

            runner.SetEnvironmentVariable("testname", "testvalue");

            string standardOutput, errorOutput;

            runner.StartAndWaitForExit("cmd", "/c echo %testname%", TimeSpan.FromSeconds(1), out standardOutput, out errorOutput);

            Assert.AreEqual("testvalue", standardOutput.Trim());
        }
Ejemplo n.º 5
0
        public static void NotePad(string str)
        {
            var tempPath = Path.GetTempPath();
            var guidName = Guid.NewGuid().ToString().Replace("-", "") + ".txt";
            var fi       = new FileInfo(Path.Combine(tempPath, guidName));

            File.WriteAllText(fi.FullName, str);
            var notepadExe = new FileInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe");

            if (!notepadExe.Exists)
            {
                notepadExe = new FileInfo(@"C:\Program Files\Notepad++\notepad++.exe");
            }

            if (!notepadExe.Exists)
            {
                notepadExe = new FileInfo(@"C:\Windows\System32\notepad.exe");
            }

            ExecutableRunner.RunExecutable(notepadExe.FullName, fi.FullName, tempPath);
        }
Ejemplo n.º 6
0
        public void StartAndWaitForExit_PingWithTimeout_ThrowsTimeoutException()
        {
            var runner = new ExecutableRunner();

            Assert.Throws <TimeoutException>(() => runner.StartAndWaitForExit("ping", "-n 10 127.0.0.1", TimeSpan.FromSeconds(1)));
        }