public async Task TestThatStopStopsTheProcess() { int stopCallCount = 0; IProcess process = new StubIProcess() { Start = () => Task.FromResult(true) }; IProcessStopper processStopper = new StubIProcessStopper { StopProcess_IProcess = (p) => { ++stopCallCount; return(Task.FromResult(true)); } }; IProcessFactory processFactory = new StubIProcessFactory() { CreateProcess_String_String = (path, args) => process }; ConfigurableApplication application = new ConfigurableApplication(ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); await application.Start(); await application.Stop(); Assert.Equal(1, stopCallCount); }
public async Task TestThatStartFailsIfProcessFailsToStart() { IProcess process = new StubIProcess() .Start(args => { throw new Exception("Process failed to start"); }); IProcessFactory processFactory = new StubIProcessFactory() .CreateProcess((identity, path, initialization, health, shutdown) => process); IProcessStopper processStopper = new StubIProcessStopper(); ConfigurableApplication application = new ConfigurableApplication( ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); Assert.False(await application.Start()); }
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); }
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() { CreateProcess_String_String = (path, args) => { exePath = path; exeArgs = args; return(process); } }; IProcessStopper processStopper = new StubIProcessStopper { StopProcess_IProcess = (p) => { ++stopCallCount; return(Task.FromResult(true)); } }; ConfigurableApplication application = new ConfigurableApplication(ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); await application.Start(); Assert.Equal(1, startCallCount); Assert.Equal(0, stopCallCount); Assert.Equal(ApplicationTestFixture.TestExeArgs, exeArgs); Assert.Equal(Path.Combine(ApplicationTestFixture.AppPath, ApplicationTestFixture.ExeName), exePath); }
public async Task TestStartProcessHappyPath() { int startCallCount = 0; int stopCallCount = 0; string exePath = ""; string exeArgs = ""; IProcess process = new StubIProcess() .Start(args => { exeArgs = args; startCallCount++; return(Task.FromResult(true)); } ); IProcessFactory processFactory = new StubIProcessFactory() .CreateProcess((identity, path, initialization, health, shutdown) => { exePath = path; return(process); }); IProcessStopper processStopper = new StubIProcessStopper() .StopProcess(p => { ++stopCallCount; return(Task.FromResult(true)); } ); ConfigurableApplication application = new ConfigurableApplication( ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); await application.Start(); Assert.Equal(1, startCallCount); Assert.Equal(0, stopCallCount); Assert.Equal(ApplicationTestFixture.TestExeArgs, exeArgs); Assert.Equal(Path.Combine(ApplicationTestFixture.AppPath, ApplicationTestFixture.ExeName), exePath); }
public async Task TestThatStartFailsIfProcessFailsToStart() { IProcess process = new StubIProcess() { Start = () => { throw new Exception("Process failed to start"); } }; IProcessFactory processFactory = new StubIProcessFactory() { CreateProcess_String_String = (path, args) => process }; IProcessStopper processStopper = new StubIProcessStopper(); ConfigurableApplication application = new ConfigurableApplication(ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); Assert.False(await application.Start()); }
public async Task TestThatExitedEventIsEmittedWhenProcessFails() { ProcessStub process = new ProcessStub(""); IProcessFactory processFactory = new StubIProcessFactory() .CreateProcess((identity, path, initialization, health, shutdown) => process); ConfigurableApplication application = new ConfigurableApplication(ApplicationTestFixture.AppPath, _appConfig, processFactory, new StubIProcessStopper()); ApplicationExitedArgs appExitedArgs = null; int exitedEventCount = 0; application.Exited += (sender, args) => { appExitedArgs = args; ++exitedEventCount; }; await application.Start(); process.RaiseExitedEvent(); Assert.Equal(1, exitedEventCount); Assert.Equal(_appConfig.Identity, appExitedArgs.AppIdentity); }
public async Task TestThatStopStopsTheProcess() { int stopCallCount = 0; IProcess process = new StubIProcess().Start(args => Task.FromResult(true)); IProcessStopper processStopper = new StubIProcessStopper() .StopProcess(p => { ++stopCallCount; return(Task.FromResult(true)); } ); IProcessFactory processFactory = new StubIProcessFactory() .CreateProcess((identity, path, initialization, health, shutdown) => process); ConfigurableApplication application = new ConfigurableApplication( ApplicationTestFixture.AppPath, _appConfig, processFactory, processStopper); await application.Start(); await application.Stop(); Assert.Equal(1, stopCallCount); }
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); }
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); }
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()); }