示例#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 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);
        }
示例#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);
                },
                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);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#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")
                .ExeArgs_Get(() => "exeArgs");

            IProcessStopper processStopper = new ProcessStopper(0);
            processStopper.StopProcess(process);
        }