コード例 #1
0
        public void TestStdOutputAndStdError()
        {
            using (AssemblyRunner runner = new AssemblyRunner(Exe))
            {
                StringWriter wtr = new StringWriter();
                StringWriter err = new StringWriter();
                ProcessOutputEventHandler handler =
                        delegate(object o, ProcessOutputEventArgs e)
                        { if (e.Error) err.WriteLine(e.Data); else wtr.WriteLine(e.Data); };

                runner.OutputReceived += handler;

                Assert.AreEqual(1, runner.Run("command-line-argrument"));
                Assert.AreEqual("std-err", err.ToString().Trim());

                StringReader rdr = new StringReader(wtr.ToString());
                Assert.AreEqual("WorkingDirectory = " + Environment.CurrentDirectory, rdr.ReadLine());
                Assert.AreEqual("argument[0] = command-line-argrument", rdr.ReadLine());
                Assert.AreEqual("std-input:", rdr.ReadLine());
                Assert.AreEqual(null, rdr.ReadLine());
            }
        }
コード例 #2
0
        public void TestExitedEventUnsubscribe()
        {
            using (AssemblyRunner runner = new AssemblyRunner(Exe))
            {
                int exitCode = -1;
                bool receivedExit = false;
                ProcessExitedEventHandler handler =
                        delegate(object o, ProcessExitedEventArgs e)
                        { receivedExit = true; exitCode = e.ExitCode; };

                runner.ProcessExited += handler;
                runner.ProcessExited -= handler;

                Assert.AreEqual(0, runner.Run());
                Assert.IsFalse(receivedExit);
                Assert.AreEqual(-1, exitCode);
            }
        }
コード例 #3
0
        public void TestRunWithWorkingDirectory()
        {
            using (TempDirectory dir = new TempDirectory())
            using (AssemblyRunner runner = new AssemblyRunner(Exe))
            {
                List<string> lines = new List<string>();
                runner.OutputReceived += delegate(Object o, ProcessOutputEventArgs e) { lines.Add(e.Data); };

                Assert.AreNotEqual(dir.TempPath, runner.WorkingDirectory);
                runner.WorkingDirectory = dir.TempPath;
                Assert.AreEqual(dir.TempPath, runner.WorkingDirectory);

                int exitCode = runner.Run();
                Assert.AreEqual(0, exitCode);
                Assert.AreEqual("WorkingDirectory = " + dir.TempPath, lines[0]);
            }
        }
コード例 #4
0
        public void TestRunWithInput()
        {
            using (AssemblyRunner runner = new AssemblyRunner(Exe))
            {
                List<string> lines = new List<string>();
                runner.OutputReceived += delegate(Object o, ProcessOutputEventArgs e) { lines.Add(e.Data); };
                int exitCode = runner.Run(new StringReader("Hello World\r\nWhatever!\r\nAnother line."));
                Assert.AreEqual(0, exitCode);

                // 0 == WorkingDirectory = 
                // 1 == std-input:
                Assert.AreEqual("Hello World", lines[2]);
                Assert.AreEqual("Whatever!", lines[3]);
                Assert.AreEqual("Another line.", lines[4]);
            }
        }
コード例 #5
0
        public void TestOutputEventUnsubscribe()
        {
            using (AssemblyRunner runner = new AssemblyRunner(Exe))
            {
                bool outputReceived = false;
                ProcessOutputEventHandler handler =
                        delegate(object o, ProcessOutputEventArgs e)
                        { outputReceived = true; };

                runner.OutputReceived += handler;
                runner.OutputReceived -= handler;

                Assert.AreEqual(0, runner.Run());
                Assert.IsFalse(outputReceived);
            }
        }
コード例 #6
0
 public void TestUnhandledExceptionRun()
 {
     using (IRunner runner = new AssemblyRunner(Exe))
     {
         runner.Run("-throw", "System.ArgumentOutOfRangeException");
         Assert.Fail();
     }
 }