public void KillProcessesForProjectKillsAProcess()
 {
     var fileSystemMock = InitialiseFileSystemMockForExecute();
     var info = new ProcessInfo("sleeper");
     var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object };
     var projectName = "aProject";
     var thread = new Thread(
         () => executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt"));
     thread.Start();
     var started = SpinWait.SpinUntil(() => Process.GetProcessesByName("sleeper").Length > 0,
                                      TimeSpan.FromSeconds(5));
     Assert.IsTrue(started);
     ProcessExecutor.KillProcessesForProject(fileSystemMock.Object, projectName);
     var stopped = SpinWait.SpinUntil(() => Process.GetProcessesByName("sleeper").Length == 0,
                                      TimeSpan.FromSeconds(5));
     Assert.IsTrue(stopped);
 }
 public void ExecuteWritesToStdIn()
 {
     var fileSystemMock = InitialiseFileSystemMockForExecute();
     var info = new ProcessInfo("sleeper", "1") { StandardInputContent = "SomeData" };
     var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object };
     var projectName = "aProject";
     var waitHandle = new ManualResetEvent(false);
     ProcessResult result = null;
     var thread = new Thread(
         () =>
         {
             try
             {
                 result = executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt");
             }
             finally
             {
                 waitHandle.Set();
             }
         });
     thread.Start();
     waitHandle.WaitOne(TimeSpan.FromSeconds(30));
     Assert.IsTrue(result.Succeeded);
 }
 public void ExecutePassesOnOutput()
 {
     var fileSystemMock = InitialiseFileSystemMockForExecute();
     var info = new ProcessInfo("sleeper", "1");
     var output = new List<ProcessOutputEventArgs>();
     var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object };
     executor.ProcessOutput += (o, e) => output.Add(e);
     var projectName = "aProject";
     var waitHandle = new ManualResetEvent(false);
     ProcessResult result = null;
     var thread = new Thread(
         () =>
         {
             try
             {
                 result = executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt");
             }
             finally
             {
                 waitHandle.Set();
             }
         });
     thread.Start();
     waitHandle.WaitOne(TimeSpan.FromSeconds(30));
     CollectionAssert.IsNotEmpty(output);
     Assert.IsTrue(result.Succeeded);
 }
 public void ExecuteChangesPriority()
 {
     var fileSystemMock = InitialiseFileSystemMockForExecute();
     var info = new ProcessInfo("sleeper", "1", null, ProcessPriorityClass.BelowNormal);
     var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object };
     var projectName = "aProject";
     var waitHandle = new ManualResetEvent(false);
     ProcessResult result = null;
     var thread = new Thread(
         () =>
         {
             try
             {
                 result = executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt");
             }
             finally
             {
                 waitHandle.Set();
             }
         });
     thread.Start();
     waitHandle.WaitOne(TimeSpan.FromSeconds(30));
     Assert.IsTrue(result.Succeeded);
 }
 public void ExecuteTimesOut()
 {
     var fileSystemMock = InitialiseFileSystemMockForExecute();
     var info = new ProcessInfo("sleeper") { TimeOut = TimeSpan.FromSeconds(1) };
     var executor = new ProcessExecutor { FileSystem = fileSystemMock.Object };
     var projectName = "aProject";
     var waitHandle = new ManualResetEvent(false);
     ProcessResult result = null;
     var thread = new Thread(
         () =>
         {
             try
             {
                 result = executor.Execute(info, projectName, "aTask", "C:\\somewhere.txt");
             }
             finally
             {
                 waitHandle.Set();
             }
         });
     thread.Start();
     waitHandle.WaitOne(TimeSpan.FromSeconds(30));
     Assert.IsTrue(result.TimedOut);
 }