Пример #1
0
        public void ProcessThread_Start_GivenValid_ExpectNewProcessCreated()
        {
            var mockConfig = new Mock <IJobConfig>();
            var mockChildProcessTracker = new Mock <IChildProcessTracker>();
            var mockProcessFactory      = new Mock <IProcessFactory>();
            var mockProcess             = new Mock <IProcess>();

            mockProcess.Setup(o => o.WaitForExit(It.IsAny <int>())).Returns(true);
            var process = mockProcess.Object;

            mockProcessFactory.Setup(o => o.Start(_startInfo)).Returns(process);
            var expectedConfig = mockConfig.Object;


            var processThread = new ProcessThreadForTesting(_startInfo, mockChildProcessTracker.Object, mockProcessFactory.Object, expectedConfig);
            var done          = false;

            processThread.OnProcessDied += (config) => done = true;

            processThread.Start();


            while (!done)
            {
            }

            mockChildProcessTracker.Verify(o => o.Add(process), Times.Once);
            mockProcessFactory.Verify(o => o.Start(_startInfo), Times.Once); // also need to verify a restart
            mockProcess.Verify(o => o.WaitForExit(It.IsAny <int>()));
        }
Пример #2
0
        public void ProcessThread_Kill_GivenDeadProcess_DoNotThrow()
        {
            var mockConfig = new Mock <IJobConfig>();
            var mockChildProcessTracker = new Mock <IChildProcessTracker>();
            var mockProcessFactory      = new Mock <IProcessFactory>();
            var mockProcess             = new Mock <IProcess>();

            mockProcess.Setup(o => o.WaitForExit(It.IsAny <int>())).Returns(true);
            var process = mockProcess.Object;

            mockProcessFactory.Setup(o => o.Start(_startInfo)).Returns(process);
            var expectedConfig = mockConfig.Object;
            var processThread  = new ProcessThreadForTesting(_startInfo, mockChildProcessTracker.Object, mockProcessFactory.Object, expectedConfig);
            var done           = false;

            processThread.OnProcessDied += (config) => done = true;

            processThread.Start();

            while (!done)
            {
            }

            try
            {
                processThread.Kill();
            }
            catch
            {
                Assert.Fail("kill throws exception when it should not");
            }
        }