public void OnRestartKillAllIntegratorsRefreshConfigAndStartupNewIntegrators() { integratorMock1.Setup(integrator => integrator.Start()).Verifiable(); integratorMock2.Setup(integrator => integrator.Start()).Verifiable(); server.Start(); integratorMock1.Setup(integrator => integrator.Stop(true)).Verifiable(); integratorMock1.Setup(integrator => integrator.WaitForExit()).Verifiable(); integratorMock2.Setup(integrator => integrator.Stop(true)).Verifiable(); integratorMock2.Setup(integrator => integrator.WaitForExit()).Verifiable(); configuration = new Configuration(); configuration.AddProject(project1); integratorList = new ProjectIntegratorList(); integratorList.Add(integrator1); configServiceMock.Setup(service => service.Load()).Returns(configuration).Verifiable(); projectIntegratorListFactoryMock.Setup(factory => factory.CreateProjectIntegrators(configuration.Projects, It.IsAny <IntegrationQueueSet>())) .Returns(integratorList).Verifiable(); server.Restart(); integratorMock1.Verify(integrator => integrator.Start(), Times.Exactly(2)); integratorMock2.Verify(integrator => integrator.Start(), Times.Exactly(1)); VerifyAll(); }
public void OnRestartKillAllIntegratorsRefreshConfigAndStartupNewIntegrators() { integratorMock1.Expect("Start"); integratorMock2.Expect("Start"); server.Start(); integratorMock1.Expect("Stop", true); integratorMock1.Expect("WaitForExit"); integratorMock2.Expect("Stop", true); integratorMock2.Expect("WaitForExit"); configuration = new Configuration(); configuration.AddProject(project1); integratorList = new ProjectIntegratorList(); integratorList.Add(integrator1); configServiceMock.ExpectAndReturn("Load", configuration); projectIntegratorListFactoryMock.ExpectAndReturn("CreateProjectIntegrators", integratorList, configuration.Projects, integrationQueue); integratorMock1.Expect("Start"); integratorMock2.ExpectNoCall("Start"); server.Restart(); VerifyAll(); }
public void IntegrationStartedIsFired() { 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.IntegrationStarted += 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.IntegrationStarted += delegate(object o, IntegrationStartedEventArgs e) { eventFired = true; Assert.AreEqual(projectName, e.ProjectName); Assert.AreSame(request, e.Request); }; startEventRaiser.Raise(integrator4, new IntegrationStartedEventArgs(request, projectName)); Assert.IsTrue(eventFired, "IntegrationStarted not fired"); }
public void IntegrationStartedIsFired() { 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.IntegrationStarted += delegate(object o, IntegrationStartedEventArgs e) { eventFired = true; Assert.AreEqual(projectName, e.ProjectName); Assert.AreSame(request, e.Request); }; Mock.Get(integrator4).Raise(_integrator4 => _integrator4.IntegrationStarted += null, new IntegrationStartedEventArgs(request, projectName)); Assert.IsTrue(eventFired, "IntegrationStarted not fired"); }
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); }
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); }