예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        public void TestThatProcessIsStoppedGracefullyFirst()
        {
            bool     resourcesReleased = false;
            IProcess process           = new StubIProcess
            {
                Close = () =>
                {
                    throw new Exception("Close should not be called if the process has exited gracefully");
                },
                Kill = () =>
                {
                    throw new Exception("Kill should not be called if the process has exited gracefully");
                },
                HasExited_Get            = () => true,
                IProcessInfo_ExePath_Get = () => "exePath",
                IProcessInfo_ExeArgs_Get = () => "exeArgs",
                ReleaseResources         = () =>
                {
                    resourcesReleased = true;
                    return(Task.FromResult(true));
                }
            };

            IProcessStopper processStopper = new ProcessStopper(0);

            processStopper.StopProcess(process);

            Assert.True(resourcesReleased);
        }
예제 #6
0
        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");

            IProcessStopper processStopper = new ProcessStopper(0);

            processStopper.StopProcess(process);
        }
예제 #7
0
        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);
        }