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()); } }
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); } }
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]); } }
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]); } }
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); } }
public void TestUnhandledExceptionRun() { using (IRunner runner = new AssemblyRunner(Exe)) { runner.Run("-throw", "System.ArgumentOutOfRangeException"); Assert.Fail(); } }