public void TestExited()
 {
     var exited = false;
     var runner = new ImpersonationProcessRunner();
     var spec = new ProcessRunSpec()
     {
         ExecutablePath = "whoami",
         BufferedInputOutput = true,
         Credentials = creds,
         ExitHandler = (sender, args) => exited = true
     };
     var process = runner.Run(spec);
     process.WaitForExit();
     Assert.True(exited);
 }
 public void TestHandle()
 {
     var runner = new ImpersonationProcessRunner();
     var spec = new ProcessRunSpec()
     {
         ExecutablePath = "powershell",
         Arguments = new[] { "-Command", "$x = [Console]::In.ReadLine()" },
         BufferedInputOutput = true,
         Credentials = creds
     };
     var proc = runner.Run(spec);
     Assert.NotNull(proc.Handle);
     var pid = GetProcessId(proc.Handle);
     var realProc = Process.GetProcessById(pid);
     try
     {
         Assert.NotNull(realProc);
         Assert.Equal("powershell", realProc.ProcessName);
     }
     finally
     {
         realProc.Kill();
     }
 }
 public void TestStderr()
 {
     var runner = new ImpersonationProcessRunner();
     var spec = new ProcessRunSpec()
     {
         ExecutablePath = "powershell",
         Arguments = new[] { "-Command", "[Console]::Error.WriteLine('hi')" },
         BufferedInputOutput = true,
         Credentials = creds
     };
     var proc = runner.Run(spec);
     Assert.Equal("hi", proc.StandardError.ReadToEnd().Trim());
 }
 public void TestStdout()
 {
     var runner = new ImpersonationProcessRunner();
     var spec = new ProcessRunSpec()
     {
         ExecutablePath = "whoami",
         BufferedInputOutput = true,
         Credentials = creds
     };
     var proc = runner.Run(spec);
     Assert.Matches(new Regex(username), proc.StandardOutput.ReadToEnd());
 }