Пример #1
0
 public void AskToIntegrateFailsIfUnableToLock()
 {
     var project = new ProjectStub();
     var queue = new TestQueue();
     var context = new IntegrationContext(project);
     queue.Lock();
     Assert.Throws<Exception>(() => queue.AskToIntegrate(context));
 }
Пример #2
0
 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);
 }
Пример #3
0
 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());
 }
Пример #4
0
        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);
        }
Пример #5
0
 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);
 }
Пример #6
0
 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);
 }
Пример #7
0
        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);
        }
Пример #8
0
 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());
 }
Пример #9
0
 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);
 }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
 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);
 }
Пример #13
0
        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);
        }
Пример #14
0
 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);
 }
Пример #15
0
        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);
        }
Пример #16
0
        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);
        }
Пример #17
0
 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);
 }
Пример #18
0
        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);
        }
Пример #19
0
        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);
        }
Пример #20
0
 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);
 }
Пример #21
0
 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);
 }