Beispiel #1
0
        public async Task TestStartProcessHappyPath()
        {
            int startCallCount = 0;
            int stopCallCount = 0;
            IProcess process = new StubIProcess()
            {
                Start = () =>
                {
                    startCallCount++;
                    return Task.FromResult(true);
                }
            };

            string exePath = "";
            string exeArgs = "";

            IProcessFactory processFactory = new StubIProcessFactory()
            {
                CreateProcessStringString = (path, args) =>
                {
                    exePath = path;
                    exeArgs = args;
                    return process;
                }
            };

            IProcessStopper processStopper = new StubIProcessStopper
            {
                StopProcessIProcess = (p) =>
                {
                    ++stopCallCount;
                    return Task.FromResult(true);
                }
            };

            ConfigurableApplication application = new ConfigurableApplication(AppPath, _appConfig, processFactory, processStopper);
            await application.Start();

            Assert.AreEqual(1, startCallCount);
            Assert.AreEqual(0, stopCallCount);
            Assert.AreEqual(TestExeArgs, exeArgs);
            Assert.AreEqual(Path.Combine(AppPath, ExeName), exePath);
        }
Beispiel #2
0
        public async Task TestThatStopStopsTheProcess()
        {
            int stopCallCount = 0;
            IProcess process = new StubIProcess()
            {
                Start = () => Task.FromResult(true)
            };

            IProcessStopper processStopper = new StubIProcessStopper
            {
                StopProcessIProcess = (p) =>
                {
                    ++stopCallCount;
                    return Task.FromResult(true);
                }
            };

            IProcessFactory processFactory = new StubIProcessFactory()
            {
                CreateProcessStringString = (path, args) => process
            };
            ConfigurableApplication application = new ConfigurableApplication(AppPath, _appConfig, processFactory, processStopper);
            await application.Start();
            await application.Stop();

            Assert.AreEqual(1, stopCallCount);
        }
Beispiel #3
0
        public async Task TestThatStartFailsIfProcessFailsToStart()
        {
            IProcess process = new StubIProcess()
            {
                Start = () =>
                {
                    throw new Exception("Process failed to start");
                }
            };

            IProcessFactory processFactory = new StubIProcessFactory()
            {
                CreateProcessStringString = (path, args) => process
            };

            IProcessStopper processStopper = new StubIProcessStopper();

            ConfigurableApplication application = new ConfigurableApplication(AppPath, _appConfig, processFactory, processStopper);
            Assert.IsFalse(await application.Start());
        }
Beispiel #4
0
        public async Task TestThatExitedEventIsEmittedWhenProcessFails()
        {
            ProcessStub process = new ProcessStub("", "");
            IProcessFactory processFactory = new StubIProcessFactory()
            {
                CreateProcessStringString = (path, args) => process
            };

            ConfigurableApplication application = new ConfigurableApplication(AppPath, _appConfig, processFactory, new StubIProcessStopper());
            ApplicationExitedArgs appExitedArgs = null;
            int exitedEventCount = 0;
            application.Exited += (sender, args) =>
            {
                appExitedArgs = args;
                ++exitedEventCount;
            };
            await application.Start();
            process.RaiseExitedEvent();

            Assert.AreEqual(1, exitedEventCount);
            Assert.AreEqual(_appIdentity, appExitedArgs.AppIdentity);
        }