Example #1
0
        private static ICruiseServer CreateLocal(string configFile)
        {
            IProjectStateManager stateManager = new XmlProjectStateManager();
            // Load the extensions configuration
            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);

            // Initialise the IoC container.
            server.InitialiseServices();

            return(server);
        }
		private static ICruiseServer CreateLocal(string configFile)
		{
            IProjectStateManager stateManager = new XmlProjectStateManager();
            // Load the extensions configuration
            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);

            // Initialise the IoC container.
            server.InitialiseServices();

            return server;
		}
        /// <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;
        }
        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);
        }
        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");
        }
		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);
		}