コード例 #1
0
ファイル: ProcessStopperTest.cs プロジェクト: ReubenBond/Yams
        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
ファイル: ProcessStopperTest.cs プロジェクト: Microsoft/Yams
        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
ファイル: ProcessStopperTest.cs プロジェクト: ReubenBond/Yams
        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
ファイル: ProcessStopperTest.cs プロジェクト: ReubenBond/Yams
        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
ファイル: ProcessStopperTest.cs プロジェクト: Microsoft/Yams
        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
ファイル: ProcessStopperTest.cs プロジェクト: Microsoft/Yams
        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);
        }