public void TestThatProcessIsClosedIfItWontExitGracefullyExit() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess { Close = () => { hasExited = true; return Task.FromResult(true); }, Kill = () => { throw new Exception("Kill should not be called if the process has exited gracefully"); }, HasExitedGet = () => hasExited, ExePathGet = () => "exePath", ExeArgsGet = () => "exeArgs", ReleaseResources = () => { resourcesReleased = true; return Task.FromResult(true); } }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.IsTrue(hasExited); Assert.IsTrue(resourcesReleased); }
public void TestThatProcessIsClosedIfItWontExitGracefullyExit() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess() .Close(() => { hasExited = true; return Task.FromResult(true); }) .Kill(() => { throw new Exception("Kill should not be called if the process has exited gracefully"); }) .HasExited_Get(() => hasExited) .ExePath_Get(() => "exePath") .ExeArgs_Get(() => "exeArgs") .ReleaseResources(() => { resourcesReleased = true; return Task.FromResult(true); } ); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.True(hasExited); Assert.True(resourcesReleased); }
public void TestThatProcessIsKilledIfItWontExitGracefullyExitNorClose() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess { Close = () => Task.FromResult(true), Kill = () => { hasExited = true; return Task.FromResult(true); }, HasExitedGet = () => hasExited, ExePathGet = () => "exePath", ExeArgsGet = () => "exeArgs", ReleaseResources = () => { resourcesReleased = true; return Task.FromResult(true); } }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.IsTrue(hasExited); Assert.IsTrue(resourcesReleased); }
public void TestThatExceptionIsCaughtAndSwallowedIfKillBlowsUp() { IProcess process = new StubIProcess { Close = () => Task.FromResult(true), Kill = () => { throw new Exception("Process would not die!"); }, HasExitedGet = () => false, ExePathGet = () => "exePath", ExeArgsGet = () => "exeArgs", }; IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); }
public void TestThatProcessIsKilledIfItWontExitGracefullyExitNorClose() { bool resourcesReleased = false; bool hasExited = false; IProcess process = new StubIProcess() .Close(() => Task.FromResult(true)) .Kill(() => { hasExited = true; return Task.FromResult(true); }) .HasExited_Get(() => hasExited) .ExePath_Get(() => "exePath") .ExeArgs_Get(() => "exeArgs") .ReleaseResources(() => { resourcesReleased = true; return Task.FromResult(true); } ); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); Assert.True(hasExited); Assert.True(resourcesReleased); }
public void TestThatExceptionIsCaughtAndSwallowedIfKillBlowsUp() { IProcess process = new StubIProcess() .Close(() => Task.FromResult(true)) .Kill(() => { throw new Exception("Process would not die!"); }) .HasExited_Get(() => false) .ExePath_Get(() => "exePath") .ExeArgs_Get(() => "exeArgs"); IProcessStopper processStopper = new ProcessStopper(0); processStopper.StopProcess(process); }