public void ShouldGenerateFarmLinkIfNothingSpecified() { // Setup cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.BuildName).Returns("").Verifiable(); cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.Request).Returns(requestMock.Object).Verifiable(); requestMock.Setup(_request => _request.GetText("Category")).Returns("").Verifiable(); expectedVelocityContext["serverName"] = ""; expectedVelocityContext["categoryName"] = ""; expectedVelocityContext["projectName"] = ""; expectedVelocityContext["buildName"] = ""; linkFactoryMock.Setup(factory => factory.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME)).Returns(link1).Verifiable(); expectedVelocityContext["farmLink"] = link1; 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 IResponse Execute(IRequest request) { Hashtable velocityContext = new Hashtable(); IResponse decoratedActionResponse = decoratedAction.Execute(request); if (decoratedActionResponse is HtmlFragmentResponse) { velocityContext["breadcrumbs"] = (TopControlsViewBuilder.Execute()).ResponseFragment; velocityContext["sidebar"] = (SideBarViewBuilder.Execute(cruiseRequest)).ResponseFragment; velocityContext["mainContent"] = ((HtmlFragmentResponse)decoratedActionResponse).ResponseFragment; velocityContext["dashboardversion"] = versionProvider.GetVersion(); if (request.ApplicationPath == "/") { velocityContext["applicationPath"] = string.Empty; } else { velocityContext["applicationPath"] = request.ApplicationPath; } velocityContext["renderedAt"] = DateUtil.FormatDate(DateTime.Now); velocityContext["loginView"] = LoginViewBuilder.Execute().ResponseFragment; // set to no refresh if refresh interval lower than 5 seconds Int32 refreshIntervalInSeconds = Int32.MaxValue; if (request.RefreshInterval >= 5) { refreshIntervalInSeconds = request.RefreshInterval; } velocityContext["refreshinterval"] = refreshIntervalInSeconds; string headerSuffix = string.Empty; if (!string.IsNullOrEmpty(loginViewBuilder.BuildServerName)) { headerSuffix = LoginViewBuilder.BuildServerName; } if (!string.IsNullOrEmpty(LoginViewBuilder.ProjectName)) { headerSuffix = string.Concat(headerSuffix, " - ", loginViewBuilder.ProjectName); } velocityContext["headersuffix"] = headerSuffix; GeneratejQueryLinks(velocityContext); return(velocityViewGenerator.GenerateView(TEMPLATE_NAME, velocityContext)); } else { return(decoratedActionResponse); } }
public void ShouldGenerateFarmLinkIfNothingSpecified() { // Setup cruiseRequestMock.ExpectAndReturn("ServerName", ""); cruiseRequestMock.ExpectAndReturn("ServerName", ""); cruiseRequestMock.ExpectAndReturn("ProjectName", ""); cruiseRequestMock.ExpectAndReturn("BuildName", ""); cruiseRequestMock.ExpectAndReturn("Request", requestMock.MockInstance); requestMock.ExpectAndReturn("GetText", "", new object[] { "Category" }); expectedVelocityContext["serverName"] = ""; expectedVelocityContext["categoryName"] = ""; expectedVelocityContext["projectName"] = ""; expectedVelocityContext["buildName"] = ""; linkFactoryMock.ExpectAndReturn("CreateFarmLink", link1, "Dashboard", FarmReportFarmPlugin.ACTION_NAME); expectedVelocityContext["farmLink"] = link1; velocityViewGeneratorMock.ExpectAndReturn("GenerateView", response, "TopMenu.vm", new HashtableConstraint(expectedVelocityContext)); // Execute & Verify Assert.AreEqual(response, viewBuilder.Execute()); VerifyAll(); }