public void StopMessageStopsProject() { var stopped = false; var project = new ProjectStub { Name = "Test", OnLoadState = () => { }, OnStop = () => stopped = true }; var request = new Messages.Blank(); project.Start(); Thread.Sleep(100); project.Stop(request); Thread.Sleep(500); Assert.IsTrue(stopped); }
public void IntegrationAsksHostAndStopsOnDenied() { var triggered = false; var trigger = GenerateRunOnceTrigger(() => triggered = true); var ran = false; var task = new TaskStub { OnRunAction = tc => { ran = true; return null; } }; var hostMock = new Mock<ServerItem>(MockBehavior.Strict); hostMock.Setup(h => h.AskToIntegrate(It.IsAny<IntegrationContext>())) .Callback((IntegrationContext c) => c.Cancel()); var project = new ProjectStub("Test", task) { Host = hostMock.Object, OnLoadState = () => { }, OnSaveState = () => { }, Clock = new SystemClock() }; project.Triggers.Add(trigger); project.Start(); // Give the project time to start Thread.Sleep(100); project.Stop(); // Give the project time to stop Thread.Sleep(1000); Assert.IsTrue(triggered); Assert.IsFalse(ran); Assert.IsNull(project.MainThreadException); }
public void IntegrationHandlesExceptionDuringIntegration() { var triggered = false; var trigger = GenerateRunOnceTrigger(() => triggered = true); var executionFactoryMock = new Mock<ITaskExecutionFactory>(MockBehavior.Strict); InitialiseExecutionContext(executionFactoryMock); var project = new ProjectStub("Test") { TaskExecutionFactory = executionFactoryMock.Object, OnLoadState = () => { }, OnSaveState = () => { }, Clock = new SystemClock(), OnIntegrate = ir => { throw new Exception(); } }; project.Triggers.Add(trigger); project.Start(); // Give the project time to start Thread.Sleep(100); project.Stop(); // Give the project time to stop Thread.Sleep(1000); Assert.IsTrue(triggered); Assert.IsNull(project.MainThreadException); Assert.AreEqual(IntegrationStatus.Error, project.PersistedState.LastIntegration.Status); }
public void IntegrationStartsFromTrigger() { var triggered = false; var trigger = GenerateRunOnceTrigger(() => triggered = true); var ran = false; var task = new TaskStub { OnRunAction = tc => { ran = true; return null; } }; var executionFactoryMock = new Mock<ITaskExecutionFactory>(MockBehavior.Strict); InitialiseExecutionContext(executionFactoryMock); var project = new ProjectStub("Test", task) { TaskExecutionFactory = executionFactoryMock.Object, OnLoadState = () => { }, OnSaveState = () => { }, Clock = new SystemClock() }; project.Triggers.Add(trigger); project.Start(); // Give the project time to start Thread.Sleep(100); project.Stop(); // Give the project time to stop Thread.Sleep(1000); Assert.IsTrue(triggered); Assert.IsTrue(ran); Assert.IsNull(project.MainThreadException); }
public void StopCleansUpTriggers() { var cleaned = false; var trigger = new TriggerStub { OnCleanUp = () => cleaned = true, OnCheckAction = () => null }; var project = new ProjectStub("Test") { OnLoadState = () => { } }; project.Triggers.Add(trigger); project.Start(); // Give the project time to start Thread.Sleep(100); project.Stop(); // Give the project time to stop Thread.Sleep(1000); Assert.IsTrue(cleaned); Assert.IsNull(project.MainThreadException); }
public void StopStopsAStartedProject() { var project = new ProjectStub("Test") { OnLoadState = () => { } }; project.Start(); // Give the project time to start Thread.Sleep(100); project.Stop(); // Give the project time to stop Thread.Sleep(1000); Assert.AreEqual(ProjectState.Stopped, project.State); Assert.IsNull(project.MainThreadException); }