Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }