Ejemplo n.º 1
0
        public void KillByPIdThrowsExceptionIfKillMissing()
        {
            var fileSystemMock = new Mock <IFileSystem>(MockBehavior.Strict);

            fileSystemMock.Setup(fs => fs.CheckIfFileExists(It.IsAny <string>())).Returns(false);
            Assert.Throws <CruiseControlException>(
                () => ProcessExecutor.KillByPId(fileSystemMock.Object, int.MinValue));
        }
Ejemplo n.º 2
0
        public void KillByPIdKillsProcess()
        {
            var sleeper = new Process
            {
                StartInfo = new ProcessStartInfo("sleeper")
            };

            sleeper.Start();
            var started = SpinWait.SpinUntil(() => Process.GetProcessesByName("sleeper").Length > 0,
                                             TimeSpan.FromSeconds(5));

            Assert.IsTrue(started);
            var fileSystemMock = new Mock <IFileSystem>(MockBehavior.Strict);

            fileSystemMock.Setup(fs => fs.CheckIfFileExists(It.IsAny <string>())).Returns(true);
            ProcessExecutor.KillByPId(fileSystemMock.Object, sleeper.Id);
            var stopped = SpinWait.SpinUntil(() => Process.GetProcessesByName("sleeper").Length == 0,
                                             TimeSpan.FromSeconds(5));

            Assert.IsTrue(stopped);
        }