public void Setup() { ProjectStatusOnServer server = new ProjectStatusOnServer(new ProjectStatus("myProject", IntegrationStatus.Success, DateTime.Now), new DefaultServerSpecifier("myServer")); ProjectStatusListAndExceptions statusList = new ProjectStatusListAndExceptions( new ProjectStatusOnServer[] { server }, new CruiseServerException[] { }); farmServiceMock = new DynamicMock(typeof(IFarmService)); farmServiceMock.SetupResult("GetProjectStatusListAndCaptureExceptions", statusList, typeof(IServerSpecifier), typeof(string)); viewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator)); linkFactoryMock = new DynamicMock(typeof(ILinkFactory)); ServerLocation serverConfig = new ServerLocation(); serverConfig.ServerName = "myServer"; configuration.Servers = new ServerLocation[] { serverConfig }; var urlBuilderMock = new DynamicMock(typeof(ICruiseUrlBuilder)); urlBuilderMock.SetupResult("BuildProjectUrl", string.Empty, typeof(string), typeof(IProjectSpecifier)); plugin = new ProjectReportProjectPlugin((IFarmService)farmServiceMock.MockInstance, (IVelocityViewGenerator)viewGeneratorMock.MockInstance, (ILinkFactory)linkFactoryMock.MockInstance, configuration, (ICruiseUrlBuilder)urlBuilderMock.MockInstance); cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest)); cruiseRequest = (ICruiseRequest )cruiseRequestMock.MockInstance; }
public void Setup() { ProjectStatusOnServer server = new ProjectStatusOnServer(new ProjectStatus("myProject", IntegrationStatus.Success, DateTime.Now), new DefaultServerSpecifier("myServer")); ProjectStatusListAndExceptions statusList = new ProjectStatusListAndExceptions( new ProjectStatusOnServer[] { server }, new CruiseServerException[] { }); farmServiceMock = new Mock <IFarmService>(); farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(It.IsAny <IServerSpecifier>(), It.IsAny <string>())).Returns(statusList); viewGeneratorMock = new Mock <IVelocityViewGenerator>(); linkFactoryMock = new Mock <ILinkFactory>(); ServerLocation serverConfig = new ServerLocation(); serverConfig.ServerName = "myServer"; configuration.Servers = new ServerLocation[] { serverConfig }; var urlBuilderMock = new Mock <ICruiseUrlBuilder>(); urlBuilderMock.Setup(builder => builder.BuildProjectUrl(It.IsAny <string>(), It.IsAny <IProjectSpecifier>())).Returns(string.Empty); plugin = new ProjectReportProjectPlugin((IFarmService)farmServiceMock.Object, (IVelocityViewGenerator)viewGeneratorMock.Object, (ILinkFactory)linkFactoryMock.Object, configuration, (ICruiseUrlBuilder)urlBuilderMock.Object); cruiseRequestMock = new Mock <ICruiseRequest>(); cruiseRequest = (ICruiseRequest )cruiseRequestMock.Object; }
public void WhenOneProjectStatusIsReturnedThisIsContainedInTheReturnedXml() { ProjectStatus projectStatus = CreateProjectStatus(); ServerLocation ServerSpecifier = new ServerLocation(); ServerSpecifier.ServerName = "localhost"; ProjectStatusOnServer projectStatusOnServer = new ProjectStatusOnServer(projectStatus, ServerSpecifier); mockFarmService.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", new ProjectStatusListAndExceptions( new ProjectStatusOnServer[] { projectStatusOnServer }, new CruiseServerException[0]), (string)null); XmlFragmentResponse response = (XmlFragmentResponse)reportAction.Execute(null); string xml = response.ResponseFragment; XmlDocument doc = XPathAssert.LoadAsDocument(xml); XPathAssert.Matches(doc, "/Projects/Project/@name", "HelloWorld"); XPathAssert.Matches(doc, "/Projects/Project/@activity", "Sleeping"); XPathAssert.Matches(doc, "/Projects/Project/@lastBuildStatus", "Success"); XPathAssert.Matches(doc, "/Projects/Project/@lastBuildLabel", "build_7"); XPathAssert.Matches(doc, "/Projects/Project/@lastBuildTime", LastBuildTime); XPathAssert.Matches(doc, "/Projects/Project/@nextBuildTime", NextBuildTime); XPathAssert.Matches(doc, "/Projects/Project/@webUrl", "http://blah"); XPathAssert.Matches(doc, "/Projects/Project/@category", "category"); mockFarmService.Verify(); }
public void ReturnedXmlValidatesAgainstSchema() { ProjectStatus projectStatus = CreateProjectStatus(); ServerLocation ServerSpecifier = new ServerLocation(); ServerSpecifier.ServerName = "localhost"; ProjectStatusOnServer projectStatusOnServer = new ProjectStatusOnServer(projectStatus, ServerSpecifier); mockFarmService.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", new ProjectStatusListAndExceptions( new ProjectStatusOnServer[] { projectStatusOnServer }, new CruiseServerException[0]), (string)null); XmlFragmentResponse response = (XmlFragmentResponse)reportAction.Execute(null); string xml = response.ResponseFragment; XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); xmlReaderSettings.Schemas.Add(ReadSchemaFromResources("XmlReportActionSchema.xsd")); XmlReader rdr = XmlReader.Create(new StringReader(xml), xmlReaderSettings); while (rdr.Read()) { } mockFarmService.Verify(); }
public void ShouldReturnEmptyListOfRowsWhenNoProjectStatusesAvailable() { ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[0]; Assert.AreEqual(0, projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")).Length); VerifyAll(); }
public void ShouldReturnProjectsSortedByCategoryIfCategoryColumnSpecifiedAsSortSeed() { // Setup IProjectSpecifier projectA = new DefaultProjectSpecifier(serverSpecifier, "A"); IProjectSpecifier projectB = new DefaultProjectSpecifier(serverSpecifier, "B"); IProjectSpecifier projectC = new DefaultProjectSpecifier(serverSpecifier, "C"); ProjectStatus projectStatusA = new ProjectStatus("A", "CategoryX", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0); ProjectStatus projectStatusB = new ProjectStatus("B", "CategoryY", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0); ProjectStatus projectStatusC = new ProjectStatus("C", "CategoryX", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0); ProjectStatusOnServer[] status = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatusA, serverSpecifier), new ProjectStatusOnServer(projectStatusB, serverSpecifier), new ProjectStatusOnServer(projectStatusC, serverSpecifier) }; SetupProjectLinkExpectation(projectA); SetupProjectLinkExpectation(projectB); SetupProjectLinkExpectation(projectC); // Execute mocks.ReplayAll(); mocks.ReplayAll(); ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(status, "myAction", ProjectGridSortColumn.Category, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(3, rows.Length); Assert.AreEqual("C", rows[0].Name); Assert.AreEqual("A", rows[1].Name); Assert.AreEqual("B", rows[2].Name); // Setup SetupProjectLinkExpectation(projectA); SetupProjectLinkExpectation(projectB); SetupProjectLinkExpectation(projectC); // Execute rows = projectGrid.GenerateProjectGridRows(status, "myAction", ProjectGridSortColumn.Category, false, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(3, rows.Length); Assert.AreEqual("B", rows[0].Name); Assert.AreEqual("C", rows[1].Name); Assert.AreEqual("A", rows[2].Name); VerifyAll(); }
public void ShouldDisplayCurrentProjectMessagesInProjectGridRow() { // Setup ProjectStatus projectStatus1 = new ProjectStatus(projectSpecifier.ProjectName, "category", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "my label", null, DateTime.Today, "", "", 0); projectStatus1.Messages = new Message[1] { new Message("Test Message") }; ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier) }; SetupProjectLinkExpectation(); // Execute mocks.ReplayAll(); ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.IsNotNull(rows[0].CurrentMessage); Assert.AreEqual("Test Message", rows[0].CurrentMessage); VerifyAll(); // Setup projectStatus1 = new ProjectStatus(projectSpecifier.ProjectName, "category", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Stopped, "url", DateTime.Today, "my label", null, DateTime.Today, "", "", 0); projectStatus1.Messages = new Message[2] { new Message(string.Empty), new Message("Second Message") }; statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier) }; SetupProjectLinkExpectation(); // Execute rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.IsNotNull(rows[0].CurrentMessage); Assert.AreEqual("Second Message", rows[0].CurrentMessage); VerifyAll(); }
public void GenerateXmlContentForSpecifiedProject() { ProjectStatusOnServer status = new ProjectStatusOnServer(ProjectStatusFixture.New("wrong"), serverSpecifier); ProjectStatusOnServer status2 = new ProjectStatusOnServer(ProjectStatusFixture.New("test"), serverSpecifier); mockFarmService.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", ProjectStatusList(status, status2), null); IResponse response = report.Execute((ICruiseRequest)mockRequest.MockInstance); Assert.IsInstanceOfType(typeof(XmlFragmentResponse), response); string xml = ((XmlFragmentResponse)response).ResponseFragment; XPathAssert.Matches(XPathAssert.LoadAsDocument(xml), "/CruiseControl/Projects/Project/@name", "test"); }
public void GenerateXmlContentForSpecifiedProject() { ProjectStatusOnServer status = new ProjectStatusOnServer(ProjectStatusFixture.New("wrong"), serverSpecifier); ProjectStatusOnServer status2 = new ProjectStatusOnServer(ProjectStatusFixture.New("test"), serverSpecifier); mockFarmService.Setup(service => service.GetProjectStatusListAndCaptureExceptions(null)).Returns(ProjectStatusList(status, status2)).Verifiable(); IResponse response = report.Execute((ICruiseRequest)mockRequest.Object); Assert.That(response, Is.InstanceOf <XmlFragmentResponse>()); string xml = ((XmlFragmentResponse)response).ResponseFragment; XPathAssert.Matches(XPathAssert.LoadAsDocument(xml), "/CruiseControl/Projects/Project/@name", "test"); }
public void ShouldReturnProjectsSortedByLastBuildDateIfLastBuildDateColumnSpecifiedAsSortSeed() { // Setup IProjectSpecifier projectA = new DefaultProjectSpecifier(serverSpecifier, "a"); IProjectSpecifier projectB = new DefaultProjectSpecifier(serverSpecifier, "b"); ProjectStatus projectStatus1 = new ProjectStatus("b", "category", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0); ProjectStatus projectStatus2 = new ProjectStatus("a", "category", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today.AddHours(1), "1", null, DateTime.Today, "", "", 0); ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier), new ProjectStatusOnServer(projectStatus2, serverSpecifier) }; SetupProjectLinkExpectation(projectB); SetupProjectLinkExpectation(projectA); // Execute mocks.ReplayAll(); ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.LastBuildDate, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(2, rows.Length); Assert.AreEqual("b", rows[0].Name); Assert.AreEqual("a", rows[1].Name); // Setup SetupProjectLinkExpectation(projectB); SetupProjectLinkExpectation(projectA); // Execute rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.LastBuildDate, false, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(2, rows.Length); Assert.AreEqual("a", rows[0].Name); Assert.AreEqual("b", rows[1].Name); VerifyAll(); }
public void ShouldCopyLastBuildDateToProjectRow() { // Setup DateTime date = DateTime.Today; ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ProjectStatusFixture.New(projectSpecifier.ProjectName, IntegrationStatus.Success, date), serverSpecifier) }; SetupProjectLinkExpectation(); // Execute ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(DateUtil.FormatDate(date), rows[0].LastBuildDate); VerifyAll(); }
public void ShouldGenerateFarmServerProjectAndBuildLinksIfServerProjectAndBuildSpecified() { // Setup cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("myServer").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("myServer").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("myProject").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("myProject").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("myProject").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.BuildName).Returns("myBuild").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerSpecifier).Returns(serverSpecifier).Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerSpecifier).Returns(serverSpecifier).Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectSpecifier).Returns(projectSpecifier).Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.BuildSpecifier).Returns(buildSpecifier).Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.Request).Returns(requestMock.Object).Verifiable(); requestMock.Setup(_request => _request.GetText("Category")).Returns("").Verifiable(); ProjectStatus ps = new ProjectStatus("myProject", "", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "Queue 1", 1, new List <ParameterBase>()); ProjectStatusOnServer[] psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifier) }; ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]); farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(serverSpecifier, null)).Returns(pslae).Verifiable(); expectedVelocityContext["serverName"] = "myServer"; expectedVelocityContext["categoryName"] = ""; expectedVelocityContext["projectName"] = "myProject"; expectedVelocityContext["buildName"] = "myBuild"; linkFactoryMock.Setup(factory => factory.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME)).Returns(link1).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateServerLink(serverSpecifier, ServerReportServerPlugin.ACTION_NAME)).Returns(link2).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateProjectLink(projectSpecifier, ProjectReportProjectPlugin.ACTION_NAME)).Returns(link3).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateBuildLink(buildSpecifier, BuildReportBuildPlugin.ACTION_NAME)).Returns(link4).Verifiable(); expectedVelocityContext["farmLink"] = link1; expectedVelocityContext["serverLink"] = link2; expectedVelocityContext["projectLink"] = link3; expectedVelocityContext["buildLink"] = link4; velocityViewGeneratorMock.Setup(generator => generator.GenerateView(@"TopMenu.vm", It.IsAny <Hashtable>())). Callback <string, Hashtable>((name, context) => Assert.AreEqual(context, expectedVelocityContext)).Returns(response).Verifiable(); // Execute & Verify Assert.AreEqual(response, viewBuilder.Execute()); VerifyAll(); }
public void ShouldCopyProjectNameToProjectRow() { // Setup ProjectStatus projectStatus1 = ProjectStatusFixture.New(projectSpecifier.ProjectName); ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier) }; // Execute SetupProjectLinkExpectation(); ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(1, rows.Length); Assert.AreEqual(projectSpecifier.ProjectName, rows[0].Name); VerifyAll(); }
public void ShouldGenerateFarmServerProjectAndBuildLinksIfServerProjectAndBuildSpecified() { // Setup cruiseRequestMock.ExpectAndReturn("ServerName", "myServer"); cruiseRequestMock.ExpectAndReturn("ServerName", "myServer"); cruiseRequestMock.ExpectAndReturn("ProjectName", "myProject"); cruiseRequestMock.ExpectAndReturn("ProjectName", "myProject"); cruiseRequestMock.ExpectAndReturn("ProjectName", "myProject"); cruiseRequestMock.ExpectAndReturn("BuildName", "myBuild"); cruiseRequestMock.ExpectAndReturn("ServerSpecifier", serverSpecifier); cruiseRequestMock.ExpectAndReturn("ServerSpecifier", serverSpecifier); cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier); cruiseRequestMock.ExpectAndReturn("BuildSpecifier", buildSpecifier); cruiseRequestMock.ExpectAndReturn("Request", requestMock.MockInstance); requestMock.ExpectAndReturn("GetText", "", new object[] { "Category" }); ProjectStatus ps = new ProjectStatus("myProject", "", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "Queue 1", 1, new List <ParameterBase>()); ProjectStatusOnServer[] psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifier) }; ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]); farmServiceMock.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", pslae, serverSpecifier, null); expectedVelocityContext["serverName"] = "myServer"; expectedVelocityContext["categoryName"] = ""; expectedVelocityContext["projectName"] = "myProject"; expectedVelocityContext["buildName"] = "myBuild"; linkFactoryMock.ExpectAndReturn("CreateFarmLink", link1, "Dashboard", FarmReportFarmPlugin.ACTION_NAME); linkFactoryMock.ExpectAndReturn("CreateServerLink", link2, serverSpecifier, ServerReportServerPlugin.ACTION_NAME); linkFactoryMock.ExpectAndReturn("CreateProjectLink", link3, projectSpecifier, ProjectReportProjectPlugin.ACTION_NAME); linkFactoryMock.ExpectAndReturn("CreateBuildLink", link4, buildSpecifier, BuildReportBuildPlugin.ACTION_NAME); expectedVelocityContext["farmLink"] = link1; expectedVelocityContext["serverLink"] = link2; expectedVelocityContext["projectLink"] = link3; expectedVelocityContext["buildLink"] = link4; velocityViewGeneratorMock.ExpectAndReturn("GenerateView", response, "TopMenu.vm", new HashtableConstraint(expectedVelocityContext)); // Execute & Verify Assert.AreEqual(response, viewBuilder.Execute()); VerifyAll(); }
public void ShouldCopyProjectCategoryToProjectRow() { // Setup ProjectStatus projectStatus1 = new ProjectStatus(projectSpecifier.ProjectName, "category", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "my label", null, DateTime.Today, "", "", 0); ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier) }; SetupProjectLinkExpectation(); // Execute mocks.ReplayAll(); ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual("category", rows[0].Category); VerifyAll(); // Setup projectStatus1 = new ProjectStatus(projectSpecifier.ProjectName, "category1", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Stopped, "url", DateTime.Today, "my label", null, DateTime.Today, "", "", 0); statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier) }; SetupProjectLinkExpectation(); // Execute rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual("category1", rows[0].Category); VerifyAll(); }
public void ShouldHandleResultsWithNoBuildLabel() { // Setup ProjectStatus projectStatus1 = ProjectStatusFixture.New(projectSpecifier.ProjectName, null); ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier) }; // Execute SetupProjectLinkExpectation(); ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(1, rows.Length); Assert.AreEqual("no build available", rows[0].LastBuildLabel); VerifyAll(); }
public void ExecuteGeneratesReport() { var projectName = "daProject"; var farmService = this.mocks.StrictMock <IFarmService>(); var cruiseRequest = this.mocks.StrictMock <ICruiseRequest>(); var sessionRetriever = this.mocks.StrictMock <ISessionRetriever>(); var server = this.mocks.StrictMock <IServerSpecifier>(); var project = new ProjectStatus(projectName, IntegrationStatus.Success, new DateTime(2010, 1, 2, 3, 4, 5)); project.ServerName = "TESTMACHINE"; var status = new ProjectStatusOnServer(project, server); var snapshot = new ProjectStatusListAndExceptions( new ProjectStatusOnServer[] { status }, new CruiseServerException[0]); SetupResult.For(cruiseRequest.ProjectName).Return(projectName); SetupResult.For(cruiseRequest.ServerSpecifier).Return(server); SetupResult.For(cruiseRequest.RetrieveSessionToken(sessionRetriever)).Return(null); SetupResult.For(farmService.GetProjectStatusListAndCaptureExceptions(server, null)) .Return(snapshot); this.mocks.ReplayAll(); var report = new ProjectXmlReport(farmService, sessionRetriever); var response = report.Execute(cruiseRequest); this.mocks.VerifyAll(); Assert.IsInstanceOf <XmlFragmentResponse>(response); var actual = response as XmlFragmentResponse; var expected = "<CruiseControl>" + "<Projects>" + "<Project name=\"daProject\" category=\"\" activity=\"Sleeping\" " + "status=\"Running\" lastBuildStatus=\"Success\" lastBuildLabel=\"\" " + "lastBuildTime=\"" + XmlConvert.ToString(project.LastBuildDate, XmlDateTimeSerializationMode.Local) + "\" nextBuildTime=\"" + XmlConvert.ToString(project.NextBuildTime, XmlDateTimeSerializationMode.Local) + "\" " + "webUrl=\"\" buildStage=\"\" serverName=\"TESTMACHINE\" />" + "</Projects>" + "<Queues />" + "</CruiseControl>"; Assert.AreEqual(expected, actual.ResponseFragment); }
public void ShouldCreateLinkToProjectReport() { // Setup ProjectStatus projectStatus1 = new ProjectStatus(projectSpecifier.ProjectName, "category", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0, new List <ParameterBase>()); ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier) }; SetupProjectLinkExpectation(); // Execute ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual("myLinkUrl", rows[0].Url); VerifyAll(); }
public void ShouldGenerateServerViewIfServerButNoProjectSpecified() { // Setup IServerSpecifier serverSpecifier = new DefaultServerSpecifier("myServer"); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("myServer").Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("").Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerSpecifier).Returns(serverSpecifier).Verifiable(); pluginLinkCalculatorMock.Setup(calculator => calculator.GetServerPluginLinks(serverSpecifier)).Returns(links).Verifiable(); ProjectStatus ps = new ProjectStatus("", "myCategory", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "", 0, new List <ParameterBase>()); ProjectStatusOnServer[] psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifier) }; ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]); farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(serverSpecifier, null)).Returns(pslae).Verifiable(); IAbsoluteLink link = new GeneralAbsoluteLink("link"); IAbsoluteLink[] categoryLinks = new GeneralAbsoluteLink[] { new GeneralAbsoluteLink("myCategory", "?Category=myCategory") }; linkFactoryMock.Setup(factory => factory.CreateServerLink(serverSpecifier, ServerReportServerPlugin.ACTION_NAME)).Returns(link).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateServerLink(serverSpecifier, ServerReportServerPlugin.ACTION_NAME)).Returns(link).Verifiable(); velocityContext["links"] = links; velocityContext["serverlink"] = link; velocityContext["showCategories"] = true; velocityContext["categorylinks"] = categoryLinks; velocityViewGeneratorMock.Setup(generator => generator.GenerateView(@"ServerSideBar.vm", It.IsAny <Hashtable>())). Callback <string, Hashtable>((name, context) => Assert.AreEqual(context, velocityContext)).Returns(velocityResponse).Verifiable(); // Execute HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.Object as ICruiseRequest); // Verify Assert.AreEqual(velocityResponse, returnedResponse); VerifyAll(); }
public void ShouldGenerateFarmViewIfNoServerSpecified() { // Setup cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("").Verifiable(); pluginLinkCalculatorMock.Setup(calculator => calculator.GetFarmPluginLinks()).Returns(links).Verifiable(); farmServiceMock.Setup(service => service.GetServerSpecifiers()).Returns(serverSpecifiers).Verifiable(); linkListFactoryMock.Setup(factory => factory.CreateServerLinkList(serverSpecifiers, "ViewServerReport")).Returns(serverLinks).Verifiable(); ProjectStatus ps = new ProjectStatus("", "", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "", 0, new List <ParameterBase>()); ProjectStatusOnServer[] psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifiers[0]) }; ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]); farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(serverSpecifiers[0], null)).Returns(pslae).Verifiable(); velocityContext["links"] = links; velocityContext["serverlinks"] = serverLinks; velocityContext["showCategories"] = false; velocityContext["categorylinks"] = null; CruiseControl.WebDashboard.Dashboard.DefaultLinkFactory x = new DefaultLinkFactory(new DefaultUrlBuilder(), null, null); IAbsoluteLink farmLink = x.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME); linkFactoryMock.Setup(factory => factory.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME)).Returns(farmLink).Verifiable(); velocityContext["farmLink"] = farmLink; System.Diagnostics.Debug.WriteLine("starting"); velocityViewGeneratorMock.Setup(generator => generator.GenerateView(@"FarmSideBar.vm", It.IsAny <Hashtable>())). Callback <string, Hashtable>((name, context) => Assert.AreEqual(context, velocityContext)).Returns(velocityResponse).Verifiable(); // Execute HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.Object as ICruiseRequest); // Verify Assert.AreEqual(velocityResponse, returnedResponse); VerifyAll(); }
public void ShouldGenerateFarmViewIfNoServerSpecified() { // Setup cruiseRequestWrapperMock.ExpectAndReturn("ServerName", ""); pluginLinkCalculatorMock.ExpectAndReturn("GetFarmPluginLinks", links); farmServiceMock.ExpectAndReturn("GetServerSpecifiers", serverSpecifiers); linkListFactoryMock.ExpectAndReturn("CreateServerLinkList", serverLinks, serverSpecifiers, "ViewServerReport"); ProjectStatus ps = new ProjectStatus("", "", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "", 0); ProjectStatusOnServer[] psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifiers[0]) }; ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]); farmServiceMock.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", pslae, serverSpecifiers[0], (string)null); velocityContext["links"] = links; velocityContext["serverlinks"] = serverLinks; velocityContext["showCategories"] = false; velocityContext["categorylinks"] = null; CruiseControl.WebDashboard.Dashboard.DefaultLinkFactory x = new DefaultLinkFactory(new DefaultUrlBuilder(), null, null); IAbsoluteLink farmLink = x.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME); linkFactoryMock.ExpectAndReturn("CreateFarmLink", farmLink, "Dashboard", FarmReportFarmPlugin.ACTION_NAME); velocityContext["farmLink"] = farmLink; System.Diagnostics.Debug.WriteLine("starting"); velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"FarmSideBar.vm", new HashtableConstraint(velocityContext)); // Execute HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest); // Verify Assert.AreEqual(velocityResponse, returnedResponse); VerifyAll(); }
public void ShouldGenerateServerViewIfServerButNoProjectSpecified() { // Setup IServerSpecifier serverSpecifier = new DefaultServerSpecifier("myServer"); cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "myServer"); cruiseRequestWrapperMock.ExpectAndReturn("ProjectName", ""); cruiseRequestWrapperMock.ExpectAndReturn("ServerSpecifier", serverSpecifier); pluginLinkCalculatorMock.ExpectAndReturn("GetServerPluginLinks", links, serverSpecifier); ProjectStatus ps = new ProjectStatus("", "myCategory", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "", 0); ProjectStatusOnServer[] psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifier) }; ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]); farmServiceMock.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", pslae, serverSpecifier, (string)null); IAbsoluteLink link = new GeneralAbsoluteLink("link"); IAbsoluteLink[] categoryLinks = new GeneralAbsoluteLink[] { new GeneralAbsoluteLink("myCategory", "?Category=myCategory") }; linkFactoryMock.ExpectAndReturn("CreateServerLink", link, serverSpecifier, ServerReportServerPlugin.ACTION_NAME); linkFactoryMock.ExpectAndReturn("CreateServerLink", link, serverSpecifier, ServerReportServerPlugin.ACTION_NAME); velocityContext["links"] = links; velocityContext["serverlink"] = link; velocityContext["showCategories"] = true; velocityContext["categorylinks"] = categoryLinks; velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"ServerSideBar.vm", new HashtableConstraint(velocityContext)); // Execute HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest); // Verify Assert.AreEqual(velocityResponse, returnedResponse); VerifyAll(); }
public ProjectStatusListAndExceptions(ProjectStatusOnServer[] statusAndServerList, CruiseServerException[] exceptions) { this.statusAndServerList = statusAndServerList; this.exceptions = exceptions; }
public void ShouldCopyBuildStatusToProjectRow() { // Setup ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ProjectStatusFixture.New(projectSpecifier.ProjectName, IntegrationStatus.Success), serverSpecifier) }; SetupProjectLinkExpectation(); mocks.ReplayAll(); // Execute ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual("Success", rows[0].BuildStatus); Assert.AreEqual(Color.Green.Name, rows[0].BuildStatusHtmlColor); // Setup statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ProjectStatusFixture.New(projectSpecifier.ProjectName, IntegrationStatus.Failure), serverSpecifier) }; SetupProjectLinkExpectation(); // Execute rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual("Failure", rows[0].BuildStatus); Assert.AreEqual(Color.Red.Name, rows[0].BuildStatusHtmlColor); // Setup statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ProjectStatusFixture.New(projectSpecifier.ProjectName, IntegrationStatus.Unknown), serverSpecifier) }; SetupProjectLinkExpectation(); // Execute rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual("Unknown", rows[0].BuildStatus); Assert.AreEqual(Color.Blue.Name, rows[0].BuildStatusHtmlColor); // Setup statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ProjectStatusFixture.New(projectSpecifier.ProjectName, IntegrationStatus.Exception), serverSpecifier) }; SetupProjectLinkExpectation(); // Execute rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.Name, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual("Exception", rows[0].BuildStatus); Assert.AreEqual(Color.Red.Name, rows[0].BuildStatusHtmlColor); VerifyAll(); }