コード例 #1
0
        /// <summary>
        /// Generates a local <see cref="ICruiseServer"/> instance.
        /// </summary>
        /// <param name="configFile">The configuration file to use.</param>
        /// <returns>
        /// The new <see cref="ICruiseServer"/> instance.
        /// </returns>
        private ICruiseServer CreateLocal(string configFile)
        {
            var stateManager  = new XmlProjectStateManager();
            var configuration = ConfigurationManager.GetSection("cruiseServer") as ServerConfiguration;
            List <ExtensionConfiguration> extensionList = null;

            if (configuration != null)
            {
                extensionList = configuration.Extensions;
            }

            PathUtils.ConfigFileLocation = Path.IsPathRooted(configFile)
                                               ? configFile
                                               : Path.Combine(Environment.CurrentDirectory, configFile);
            var server = new CruiseServer(
                NewConfigurationService(configFile),
                new ProjectIntegratorListFactory(),
                new NetReflectorProjectSerializer(),
                stateManager,
                new SystemIoFileSystem(),
                new ExecutionEnvironment(),
                extensionList);

            server.InitialiseServices();
            this.ServerInstance = server;
            return(server);
        }
コード例 #2
0
        public void StartAndAbortExtensions()
        {
            List <ExtensionConfiguration> extensions    = new List <ExtensionConfiguration>();
            ExtensionConfiguration        extensionStub = new ExtensionConfiguration();

            extensionStub.Type = "ThoughtWorks.CruiseControl.UnitTests.Remote.ServerExtensionStub,ThoughtWorks.CruiseControl.UnitTests";
            extensions.Add(extensionStub);

            configServiceMock.Setup(service => service.Load()).Returns(configuration).Verifiable();
            projectIntegratorListFactoryMock.Setup(factory => factory.CreateProjectIntegrators(configuration.Projects, It.IsAny <IntegrationQueueSet>()))
            .Returns(integratorList).Verifiable();
            server = new CruiseServer((IConfigurationService)configServiceMock.Object,
                                      (IProjectIntegratorListFactory)projectIntegratorListFactoryMock.Object,
                                      (IProjectSerializer)projectSerializerMock.Object,
                                      (IProjectStateManager)stateManagerMock.Object,
                                      fileSystem,
                                      executionEnvironment,
                                      extensions);
            Assert.IsTrue(ServerExtensionStub.HasInitialised);

            server.Start();
            Assert.IsTrue(ServerExtensionStub.HasStarted);

            server.Abort();
            Assert.IsTrue(ServerExtensionStub.HasAborted);
        }
コード例 #3
0
        public void StartAndAbortExtensions()
        {
            List <ExtensionConfiguration> extensions    = new List <ExtensionConfiguration>();
            ExtensionConfiguration        extensionStub = new ExtensionConfiguration();

            extensionStub.Type = "ThoughtWorks.CruiseControl.UnitTests.Remote.ServerExtensionStub,ThoughtWorks.CruiseControl.UnitTests";
            extensions.Add(extensionStub);

            configServiceMock.ExpectAndReturn("Load", configuration);
            projectIntegratorListFactoryMock.ExpectAndReturn("CreateProjectIntegrators", integratorList, configuration.Projects, integrationQueue);
            server = new CruiseServer((IConfigurationService)configServiceMock.MockInstance,
                                      (IProjectIntegratorListFactory)projectIntegratorListFactoryMock.MockInstance,
                                      (IProjectSerializer)projectSerializerMock.MockInstance,
                                      (IProjectStateManager)stateManagerMock.MockInstance,
                                      fileSystem,
                                      executionEnvironment,
                                      extensions);
            Assert.IsTrue(ServerExtensionStub.HasInitialised);

            server.Start();
            Assert.IsTrue(ServerExtensionStub.HasStarted);

            server.Abort();
            Assert.IsTrue(ServerExtensionStub.HasAborted);
        }
コード例 #4
0
        public void IntegrationCompletedIsFired()
        {
            string             enforcer    = "JohnDoe";
            string             projectName = "Project 4";
            IntegrationRequest request     = new IntegrationRequest(BuildCondition.ForceBuild, enforcer, null);

            // Need to set up a new integrator that can return an event
            IProjectIntegrator integrator4;

            integrator4 = mocks.DynamicMock <IProjectIntegrator>();
            SetupResult.For(integrator4.Name).Return("Project 4");
            integrator4.IntegrationCompleted += null;
            IEventRaiser startEventRaiser = LastCall.IgnoreArguments()
                                            .GetEventRaiser();

            // Initialise a new cruise server with the new integrator
            mocks.ReplayAll();
            integratorList.Add(integrator4);
            configServiceMock.ExpectAndReturn("Load", configuration);
            projectIntegratorListFactoryMock.ExpectAndReturn("CreateProjectIntegrators", integratorList, configuration.Projects, integrationQueue);
            server = new CruiseServer((IConfigurationService)configServiceMock.MockInstance,
                                      (IProjectIntegratorListFactory)projectIntegratorListFactoryMock.MockInstance,
                                      (IProjectSerializer)projectSerializerMock.MockInstance,
                                      (IProjectStateManager)stateManagerMock.MockInstance,
                                      fileSystem,
                                      executionEnvironment,
                                      null);

            bool eventFired = false;

            server.IntegrationCompleted += delegate(object o, IntegrationCompletedEventArgs e)
            {
                eventFired = true;
                Assert.AreEqual(projectName, e.ProjectName);
                Assert.AreEqual(IntegrationStatus.Success, e.Status);
                Assert.AreSame(request, e.Request);
            };


            startEventRaiser.Raise(integrator4,
                                   new IntegrationCompletedEventArgs(request, projectName, IntegrationStatus.Success));
            Assert.IsTrue(eventFired, "IntegrationCompleted not fired");
        }
コード例 #5
0
        public void IntegrationCompletedIsFired()
        {
            string             enforcer    = "JohnDoe";
            string             projectName = "Project 4";
            IntegrationRequest request     = new IntegrationRequest(BuildCondition.ForceBuild, enforcer, null);

            // Need to set up a new integrator that can return an event
            IProjectIntegrator integrator4;

            integrator4 = mocks.Create <IProjectIntegrator>().Object;
            Mock.Get(integrator4).SetupGet(_integrator4 => _integrator4.Name).Returns("Project 4");

            // Initialise a new cruise server with the new integrator
            integratorList.Add(integrator4);
            configServiceMock.Setup(service => service.Load()).Returns(configuration).Verifiable();
            projectIntegratorListFactoryMock.Setup(factory => factory.CreateProjectIntegrators(configuration.Projects, It.IsAny <IntegrationQueueSet>()))
            .Returns(integratorList).Verifiable();
            server = new CruiseServer((IConfigurationService)configServiceMock.Object,
                                      (IProjectIntegratorListFactory)projectIntegratorListFactoryMock.Object,
                                      (IProjectSerializer)projectSerializerMock.Object,
                                      (IProjectStateManager)stateManagerMock.Object,
                                      fileSystem,
                                      executionEnvironment,
                                      null);

            bool eventFired = false;

            server.IntegrationCompleted += delegate(object o, IntegrationCompletedEventArgs e)
            {
                eventFired = true;
                Assert.AreEqual(projectName, e.ProjectName);
                Assert.AreEqual(IntegrationStatus.Success, e.Status);
                Assert.AreSame(request, e.Request);
            };


            Mock.Get(integrator4).Raise(_integrator4 => _integrator4.IntegrationCompleted += null,
                                        new IntegrationCompletedEventArgs(request, projectName, IntegrationStatus.Success));
            Assert.IsTrue(eventFired, "IntegrationCompleted not fired");
        }
コード例 #6
0
            public void ContextSetup()
            {
                _masterModel   = new MasterModel();
                _cruiseServer1 = _masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "https://example.com/server1";
                    x.Name = "Server 1";
                });
                _cruiseServer2 = _masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "https://example.com/server2";
                    x.Name = "Server 2";
                });
                _cruiseServerNotReferenced = _masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "https://example.com/server3";
                    x.Name = "Server 3";
                });

                _zBuildLightsProject1 = _masterModel.CreateProject();
                _zBuildLightsProject1.CruiseProjectAssociations = new[]
                {
                    new CruiseProjectAssociation {
                        Name = "Project 1.1", ServerId = _cruiseServer1.Id
                    },
                    new CruiseProjectAssociation {
                        Name = "Project 1.2", ServerId = _cruiseServer1.Id
                    },
                    new CruiseProjectAssociation {
                        Name = "Project 2.1", ServerId = _cruiseServer2.Id
                    }
                };

                _zBuildLightsProject2 = _masterModel.CreateProject();
                _zBuildLightsProject2.CruiseProjectAssociations = new[]
                {
                    new CruiseProjectAssociation {
                        Name = "Project A", ServerId = _cruiseServer2.Id
                    }
                };

                var ccReaderDataServer1 = new Projects
                {
                    Items = new ProjectsProject[]
                    {
                        New.ProjectsProject.Name("Project 1.1")
                        .Activity(CcBuildActivity.Sleeping)
                        .Status(CcBuildStatus.Success),
                        New.ProjectsProject.Name("Project 1.2")
                        .Activity(CcBuildActivity.Sleeping)
                        .Status(CcBuildStatus.Success),
                        New.ProjectsProject.Name("Detractor")
                        .Activity(CcBuildActivity.Building)
                        .Status(CcBuildStatus.Failure)
                    }
                };

                var ccReaderDataServer2 = new Projects
                {
                    Items = new ProjectsProject[]
                    {
                        New.ProjectsProject.Name("Project 2.1")
                        .Activity(CcBuildActivity.Sleeping)
                        .Status(CcBuildStatus.Success),
                        New.ProjectsProject.Name("Project A")
                        .Activity(CcBuildActivity.Sleeping)
                        .Status(CcBuildStatus.Success),
                        New.ProjectsProject.Name("Detractor")
                        .Activity(CcBuildActivity.Building)
                        .Status(CcBuildStatus.Failure)
                    }
                };

                _cruiseReader = new StubCcReader()
                                .WithResponse(_cruiseServer1.Url, NetworkResponse.Success(ccReaderDataServer1))
                                .WithResponse(_cruiseServer2.Url, NetworkResponse.Success(ccReaderDataServer2));

                var updater = new ProjectStatusUpdater(_cruiseReader);

                updater.UpdateAllProjectStatuses(_masterModel);
            }
コード例 #7
0
        protected void SetUp()
        {
            projectSerializerMock = new Mock <IProjectSerializer>();

            integratorMock1 = new Mock <IProjectIntegrator>();
            integratorMock2 = new Mock <IProjectIntegrator>();
            integratorMock3 = new Mock <IProjectIntegrator>();
            integrator1     = (IProjectIntegrator)integratorMock1.Object;
            integrator2     = (IProjectIntegrator)integratorMock2.Object;
            integrator3     = (IProjectIntegrator)integratorMock3.Object;
            integratorMock1.SetupGet(integrator => integrator.Name).Returns("Project 1");
            integratorMock2.SetupGet(integrator => integrator.Name).Returns("Project 2");
            integratorMock3.SetupGet(integrator => integrator.Name).Returns("Project 3");

            fileSystem           = mocks.Create <IFileSystem>().Object;
            executionEnvironment = mocks.Create <IExecutionEnvironment>().Object;

            Mock.Get(executionEnvironment).SetupGet(_executionEnvironment => _executionEnvironment.IsRunningOnWindows).Returns(true);
            Mock.Get(executionEnvironment).Setup(_executionEnvironment => _executionEnvironment.GetDefaultProgramDataFolder(ApplicationType.Server)).Returns(applicationDataPath);
            Mock.Get(fileSystem).Setup(_fileSystem => _fileSystem.DirectoryExists(applicationDataPath)).Returns(true);

            configuration = new Configuration();
            project1      = new Project();
            project1.Name = "Project 1";
            integratorMock1.SetupGet(integrator => integrator.Project).Returns(project1);

            project2      = new Project();
            project2.Name = "Project 2";
            integratorMock2.SetupGet(integrator => integrator.Project).Returns(project1);

            mockProject         = new Mock <IProject>();
            mockProjectInstance = (IProject)mockProject.Object;
            mockProject.SetupGet(project => project.Name).Returns("Project 3");
            mockProject.SetupGet(project => project.QueueName).Returns("Project 3");
            mockProject.SetupGet(project => project.StartupMode).Returns(ProjectStartupMode.UseLastState);
            integratorMock3.SetupGet(integrator => integrator.Project).Returns(mockProjectInstance);

            configuration.AddProject(project1);
            configuration.AddProject(project2);
            configuration.AddProject(mockProjectInstance);

            integratorList = new ProjectIntegratorList();
            integratorList.Add(integrator1);
            integratorList.Add(integrator2);
            integratorList.Add(integrator3);

            configServiceMock = new Mock <IConfigurationService>();
            configServiceMock.Setup(service => service.Load()).Returns(configuration).Verifiable();

            projectIntegratorListFactoryMock = new Mock <IProjectIntegratorListFactory>();
            projectIntegratorListFactoryMock.Setup(factory => factory.CreateProjectIntegrators(configuration.Projects, It.IsAny <IntegrationQueueSet>()))
            .Returns(integratorList).Verifiable();

            stateManagerMock = new Mock <IProjectStateManager>();
            stateManagerMock.Setup(_manager => _manager.CheckIfProjectCanStart(It.IsAny <string>())).Returns(true);

            server = new CruiseServer((IConfigurationService)configServiceMock.Object,
                                      (IProjectIntegratorListFactory)projectIntegratorListFactoryMock.Object,
                                      (IProjectSerializer)projectSerializerMock.Object,
                                      (IProjectStateManager)stateManagerMock.Object,
                                      fileSystem,
                                      executionEnvironment,
                                      null);
        }
コード例 #8
0
        protected void SetUp()
        {
            projectSerializerMock = new DynamicMock(typeof(IProjectSerializer));

            integratorMock1 = new DynamicMock(typeof(IProjectIntegrator));
            integratorMock2 = new DynamicMock(typeof(IProjectIntegrator));
            integratorMock3 = new DynamicMock(typeof(IProjectIntegrator));
            integrator1     = (IProjectIntegrator)integratorMock1.MockInstance;
            integrator2     = (IProjectIntegrator)integratorMock2.MockInstance;
            integrator3     = (IProjectIntegrator)integratorMock3.MockInstance;
            integratorMock1.SetupResult("Name", "Project 1");
            integratorMock2.SetupResult("Name", "Project 2");
            integratorMock3.SetupResult("Name", "Project 3");

            fileSystem           = mocks.DynamicMock <IFileSystem>();
            executionEnvironment = mocks.DynamicMock <IExecutionEnvironment>();

            SetupResult.For(executionEnvironment.IsRunningOnWindows).Return(true);
            SetupResult.For(executionEnvironment.GetDefaultProgramDataFolder(ApplicationType.Server)).Return(applicationDataPath);
            SetupResult.For(fileSystem.DirectoryExists(applicationDataPath)).Return(true);
            mocks.ReplayAll();

            integrationQueue = null;             // We have no way of injecting currently.

            configuration = new Configuration();
            project1      = new Project();
            project1.Name = "Project 1";
            integratorMock1.SetupResult("Project", project1);

            project2      = new Project();
            project2.Name = "Project 2";
            integratorMock2.SetupResult("Project", project1);

            mockProject = new DynamicMock(typeof(IProject));
            mockProject.SetupResult("Name", "Project 3");
            mockProject.SetupResult("QueueName", "Project 3");
            mockProject.SetupResult("QueueName", "Project 3");
            mockProjectInstance = (IProject)mockProject.MockInstance;
            mockProject.SetupResult("Name", "Project 3");
            mockProject.SetupResult("StartupMode", ProjectStartupMode.UseLastState);
            integratorMock3.SetupResult("Project", mockProjectInstance);

            configuration.AddProject(project1);
            configuration.AddProject(project2);
            configuration.AddProject(mockProjectInstance);

            integratorList = new ProjectIntegratorList();
            integratorList.Add(integrator1);
            integratorList.Add(integrator2);
            integratorList.Add(integrator3);

            configServiceMock = new DynamicMock(typeof(IConfigurationService));
            configServiceMock.ExpectAndReturn("Load", configuration);

            projectIntegratorListFactoryMock = new DynamicMock(typeof(IProjectIntegratorListFactory));
            projectIntegratorListFactoryMock.ExpectAndReturn("CreateProjectIntegrators", integratorList, configuration.Projects, integrationQueue);

            stateManagerMock = new DynamicMock(typeof(IProjectStateManager));
            stateManagerMock.SetupResult("CheckIfProjectCanStart", true, typeof(string));

            server = new CruiseServer((IConfigurationService)configServiceMock.MockInstance,
                                      (IProjectIntegratorListFactory)projectIntegratorListFactoryMock.MockInstance,
                                      (IProjectSerializer)projectSerializerMock.MockInstance,
                                      (IProjectStateManager)stateManagerMock.MockInstance,
                                      fileSystem,
                                      executionEnvironment,
                                      null);
        }
コード例 #9
0
        /// <summary>
        /// Initialises the server.
        /// </summary>
        /// <param name="mocks">The mocks repository.</param>
        /// <param name="buildName">Name of the build.</param>
        /// <param name="buildLog">The build log.</param>
        /// <returns>The initialised server.</returns>
        private static CruiseServer InitialiseServer(MockRepository mocks, string buildName, string buildLog)
        {
            // Add some projects
            var projects = new ProjectList();
            var project  = new Project
            {
                Name = testProjectName
            };

            projects.Add(project);

            // Mock the configuration
            var configuration = mocks.Create <IConfiguration>(MockBehavior.Strict).Object;

            Mock.Get(configuration).SetupGet(_configuration => _configuration.Projects)
            .Returns(projects);
            Mock.Get(configuration).SetupGet(_configuration => _configuration.SecurityManager)
            .Returns(new NullSecurityManager());

            // Mock the configuration service
            var configService = mocks.Create <IConfigurationService>(MockBehavior.Strict).Object;

            Mock.Get(configService).Setup(_configService => _configService.Load())
            .Returns(configuration);
            Mock.Get(configService).Setup(_configService => _configService.AddConfigurationUpdateHandler(It.IsAny <ConfigurationUpdateHandler>())).Verifiable();

            // Mock the integration repostory
            var repository = mocks.Create <IIntegrationRepository>(MockBehavior.Strict).Object;

            Mock.Get(repository).Setup(_repository => _repository.GetBuildLog(buildName))
            .Returns(buildLog);

            // Mock the project integrator
            var projectIntegrator = mocks.Create <IProjectIntegrator>(MockBehavior.Strict).Object;

            Mock.Get(projectIntegrator).SetupGet(_projectIntegrator => _projectIntegrator.Project)
            .Returns(project);
            Mock.Get(projectIntegrator).SetupGet(_projectIntegrator => _projectIntegrator.IntegrationRepository)
            .Returns(repository);

            // Mock the queue manager
            var queueManager = mocks.Create <IQueueManager>(MockBehavior.Strict).Object;

            Mock.Get(queueManager).Setup(_queueManager => _queueManager.AssociateIntegrationEvents(It.IsAny <EventHandler <IntegrationStartedEventArgs> >(), It.IsAny <EventHandler <IntegrationCompletedEventArgs> >())).Verifiable();
            Mock.Get(queueManager).Setup(_queueManager => _queueManager.GetIntegrator(testProjectName))
            .Returns(projectIntegrator);

            // Mock the queue manager factory
            var queueManagerFactory = mocks.Create <IQueueManagerFactory>(MockBehavior.Strict).Object;

            Mock.Get(queueManagerFactory).Setup(_queueManagerFactory => _queueManagerFactory.Create(null, configuration, null))
            .Returns(queueManager);
            IntegrationQueueManagerFactory.OverrideFactory(queueManagerFactory);

            // Mock the execution environment
            var execEnviron = mocks.Create <IExecutionEnvironment>(MockBehavior.Strict).Object;

            Mock.Get(execEnviron).Setup(_execEnviron => _execEnviron.GetDefaultProgramDataFolder(ApplicationType.Server))
            .Returns(string.Empty);

            // Initialise the server
            var server = new CruiseServer(
                configService,
                null,
                null,
                null,
                null,
                execEnviron,
                null);

            return(server);
        }
コード例 #10
0
        /// <summary>
        /// Initialises the server.
        /// </summary>
        /// <param name="mocks">The mocks repository.</param>
        /// <param name="buildName">Name of the build.</param>
        /// <param name="buildLog">The build log.</param>
        /// <returns>The initialised server.</returns>
        private static CruiseServer InitialiseServer(MockRepository mocks, string buildName, string buildLog)
        {
            // Add some projects
            var projects = new ProjectList();
            var project  = new Project
            {
                Name = testProjectName
            };

            projects.Add(project);

            // Mock the configuration
            var configuration = mocks.StrictMock <IConfiguration>();

            SetupResult.For(configuration.Projects)
            .Return(projects);
            SetupResult.For(configuration.SecurityManager)
            .Return(new NullSecurityManager());

            // Mock the configuration service
            var configService = mocks.StrictMock <IConfigurationService>();

            SetupResult.For(configService.Load())
            .Return(configuration);
            Expect.Call(() => { configService.AddConfigurationUpdateHandler(null); })
            .IgnoreArguments();

            // Mock the integration repostory
            var repository = mocks.StrictMock <IIntegrationRepository>();

            SetupResult.For(repository.GetBuildLog(buildName))
            .Return(buildLog);

            // Mock the project integrator
            var projectIntegrator = mocks.StrictMock <IProjectIntegrator>();

            SetupResult.For(projectIntegrator.Project)
            .Return(project);
            SetupResult.For(projectIntegrator.IntegrationRepository)
            .Return(repository);

            // Mock the queue manager
            var queueManager = mocks.StrictMock <IQueueManager>();

            Expect.Call(() => { queueManager.AssociateIntegrationEvents(null, null); })
            .IgnoreArguments();
            SetupResult.For(queueManager.GetIntegrator(testProjectName))
            .Return(projectIntegrator);

            // Mock the queue manager factory
            var queueManagerFactory = mocks.StrictMock <IQueueManagerFactory>();

            SetupResult.For(queueManagerFactory.Create(null, configuration, null))
            .Return(queueManager);
            IntegrationQueueManagerFactory.OverrideFactory(queueManagerFactory);

            // Mock the execution environment
            var execEnviron = mocks.StrictMock <IExecutionEnvironment>();

            SetupResult.For(execEnviron.GetDefaultProgramDataFolder(ApplicationType.Server))
            .Return(string.Empty);

            // Initialise the server
            mocks.ReplayAll();
            var server = new CruiseServer(
                configService,
                null,
                null,
                null,
                null,
                execEnviron,
                null);

            return(server);
        }