public void AskToIntegrateFailsIfUnableToLock() { var project = new ProjectStub(); var queue = new TestQueue(); var context = new IntegrationContext(project); queue.Lock(); Assert.Throws<Exception>(() => queue.AskToIntegrate(context)); }
public void CompletingAnIntegrationFailsIfUnableToLock() { var project = new ProjectStub(); var queue = new TestQueue(); var context = new IntegrationContext(project); queue.AskToIntegrate(context); queue.Lock(); Assert.Throws<Exception>(context.Complete); }
public void CompletingAnIntegrationRemovesItFromActiveRequests() { var project = new ProjectStub(); var queue = new Queue(); var context = new IntegrationContext(project); queue.AskToIntegrate(context); context.Complete(); Assert.AreEqual(0, queue.GetActiveRequests().Count()); Assert.AreEqual(0, queue.GetPendingRequests().Count()); }
public void StartFailsIfAlreadyStarted() { var project = new ProjectStub("Test") { OnLoadState = () => { } }; project.Start(); // Give the project time to start Thread.Sleep(100); Assert.Throws<InvalidOperationException>(project.Start); }
public void AskToIntegrateWillTriggerProjectIfFirst() { var project = new ProjectStub(); var queue = new Queue(); var context = new IntegrationContext(project); queue.AskToIntegrate(context); var canIntegrate = context.Wait(TimeSpan.FromSeconds(5)); Assert.IsTrue(canIntegrate); var active = queue.GetActiveRequests(); Assert.AreEqual(1, active.Count()); Assert.AreEqual(0, queue.GetPendingRequests().Count()); Assert.AreSame(active.First(), context); }
public void ValidateValidatesChildren() { var validated = false; var project = new ProjectStub { Name = "Project", OnValidate = vl => validated = true }; var server = new Server("Server", project); var validationStub = new ValidationLogStub(); server.Validate(validationStub); Assert.IsTrue(validated); }
public void StartStartsTheProject() { var stateLoaded = false; var project = new ProjectStub("Test") { OnLoadState = () => stateLoaded = true }; project.Start(); // Give the project time to start Thread.Sleep(100); Assert.AreEqual(ProjectState.Running, project.State); Assert.IsTrue(stateLoaded); }
public void CompletingReleasingSubsequentItems() { var queue = new Queue(); var project1 = new ProjectStub(); var project2 = new ProjectStub(); var context1 = new IntegrationContext(project1); var context2 = new IntegrationContext(project2); queue.AskToIntegrate(context1); queue.AskToIntegrate(context2); context1.Complete(); var active = queue.GetActiveRequests(); Assert.AreEqual(1, active.Count()); Assert.AreEqual(0, queue.GetPendingRequests().Count()); Assert.AreSame(context2, active.First()); }
public void AskToIntegrateWillQueueSubsequentItems() { var queue = new Queue(); var project1 = new ProjectStub(); var project2 = new ProjectStub(); var context1 = new IntegrationContext(project1); var context2 = new IntegrationContext(project2); queue.AskToIntegrate(context1); queue.AskToIntegrate(context2); var active = queue.GetActiveRequests(); var pending = queue.GetPendingRequests(); Assert.AreEqual(1, active.Count()); Assert.AreEqual(1, pending.Count()); Assert.AreSame(active.First(), context1); Assert.AreSame(pending.First(), context2); }
public void StartInitialisesTriggers() { var initialised = false; var trigger = new TriggerStub { OnInitialise = () => initialised = true }; var project = new ProjectStub("Test") { OnLoadState = () => { } }; project.Triggers.Add(trigger); project.Start(); // Give the project time to start Thread.Sleep(100); Assert.IsTrue(initialised); }
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 StartHandlesError() { var project = new ProjectStub(); var server = new Server(project); var application = new Application { Configuration = server }; var error = Assert.Throws<InvalidOperationException>(application.Start); Assert.AreEqual("Cannot start a project without a name", error.Message); }
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 IntegrateResetsTriggers() { var reset = false; var dummy = new TriggerStub { OnResetAction = () => reset = true }; var executionFactoryMock = new Mock<ITaskExecutionFactory>(MockBehavior.Strict); InitialiseExecutionContext(executionFactoryMock); var project = new ProjectStub("test") { TaskExecutionFactory = executionFactoryMock.Object }; project.Triggers.Add(dummy); var request = new IntegrationRequest("Dummy"); project.Integrate(request); Assert.IsTrue(reset); }
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 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 ValidateValidatesChildren() { var validated = false; var projectStub = new ProjectStub { OnValidate = vl => validated = true }; var validationMock = new Mock<IValidationLog>(); var queue = new Queue("Test", projectStub); queue.Validate(validationMock.Object); Assert.IsTrue(validated); }
public void StopStopsProjects() { var started = false; var stopped = false; var project = new ProjectStub { Name = "Test", OnStart = () => started = true, OnStop = () => stopped = true, OnLoadState = () => { } }; var server = new Server(project); var application = new Application { Configuration = server }; application.Start(); // Give the projects time to start SpinWait.SpinUntil(() => started, TimeSpan.FromSeconds(5)); Assert.IsTrue(started); application.Stop(); // Give the projects time to stop SpinWait.SpinUntil(() => stopped, TimeSpan.FromSeconds(5)); Assert.IsTrue(stopped); }
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); }
public void LoadConfigurationFailsErrorInValidation() { var path = Path.Combine(Environment.CurrentDirectory, "ccnet.config"); var project = new ProjectStub { OnValidate = vl => { throw new ConfigurationException("Oops"); } }; var server = new Server("Test", project); var stream = new MemoryStream(); var serviceMock = new Mock<IConfigurationService>(MockBehavior.Strict); serviceMock.Setup(s => s.Load(stream)).Returns(server); var fileSystemMock = new Mock<IFileSystem>(MockBehavior.Strict); fileSystemMock.Setup(fs => fs.OpenFileForRead(path)).Returns(stream); var application = new Application { ConfigurationService = serviceMock.Object, FileSystem = fileSystemMock.Object, ValidationLog = new LoggingValidationLog() }; Assert.Throws<ConfigurationException>(application.LoadConfiguration); }
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); }