/// <summary> /// Loads the service app which should be added to the pool of service apps. /// </summary> /// <param name="appName">Name of the application.</param> /// <param name="dao">The DAO.</param> /// <returns>A string containing an error message if a recoverable error occured.</returns> /// <exception cref="System.IndexOutOfRangeException">The ServiceApp could not be found in the container.</exception> /// <exception cref="System.InvalidOperationException">The ServiceApp is not in a stopped state.</exception> public string InitializeServiceApp(string appName, IServiceAppDao dao) { ServiceAppProcess process = this.ServiceAppProcesses[appName]; if (process == null) { var e = new IndexOutOfRangeException(string.Format("ServiceApp '{0}' could not be found to initialize.", appName)); this._log.Error("Error in InitializeServiceApp", e); throw e; } else if (process.IsProcessRunning) { var e = new InvalidOperationException(string.Format("ServiceApp '{0}' must be stopped before it can be reinitialized.", appName)); this._log.Error("Error in InitializeServiceApp", e); throw e; } if (process.ServiceApp.StartupTypeEnum != StartupType.Disabled) { process.Start(); return(string.Empty); } else { return(string.Format("ServiceApp '{0}' is disabled", appName)); } }
public void Start_ServiceAppProcessCanStartSucessfully() { ILog log = Substitute.For <ILog>(); bool monitorMethodCalled = false; IProcessWrapperFactory procFactory = Substitute.For <IProcessWrapperFactory>(); procFactory.CreateProcess().Returns(new FakeStandardProcess()); var serviceApp = new ServiceApp { Name = "Test", AppVersion = new Version() }; ServiceAppProcess appProcToTest = new ServiceAppProcess(serviceApp, log, procFactory); appProcToTest.MonitorProcessCallback = () => { monitorMethodCalled = true; }; Task t = appProcToTest.Start(); bool success = t.Wait(500); if (!success) { Assert.Fail("Start() took too long to finish"); } log.DidNotReceive().Error(Arg.Any <object>(), Arg.Any <Exception>()); log.DidNotReceive().Warn(Arg.Any <object>(), Arg.Any <Exception>()); Assert.IsTrue(monitorMethodCalled, "MonitorProcessCallback() not called."); }