private IResponse GenerateAuditHistory(ICruiseRequest request)
        {
            var velocityContext = new Hashtable();
            var links = new List<IAbsoluteLink>();
            links.Add(new ServerLink(request.UrlBuilder, request.ServerSpecifier, "Server", ActionName));

            ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier, request.RetrieveSessionToken());
            foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
            {
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
                links.Add(new ProjectLink(request.UrlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerAuditHistoryServerPlugin.ActionName));
            }
            velocityContext["projectLinks"] = links;
            string sessionToken = request.RetrieveSessionToken(sessionRetriever);
            if (!string.IsNullOrEmpty(request.ProjectName))
            {
                velocityContext["currentProject"] = request.ProjectName;
                AuditFilterBase filter = AuditFilters.ByProject(request.ProjectName);
                velocityContext["auditHistory"] = farmService.ReadAuditRecords(request.ServerSpecifier, sessionToken, 0, 100, filter);
            }
            else
            {
                velocityContext["auditHistory"] = new ServerLink(request.UrlBuilder, request.ServerSpecifier, string.Empty, DiagnosticsActionName);
                velocityContext["auditHistory"] = farmService.ReadAuditRecords(request.ServerSpecifier, sessionToken, 0, 100);
            }

            return viewGenerator.GenerateView(@"AuditHistory.vm", velocityContext);
        }
        public IResponse Execute(ICruiseRequest request)
        {
            Hashtable velocityContext = new Hashtable();
            ArrayList links = new ArrayList();
            links.Add(new ServerLink(urlBuilder, request.ServerSpecifier, "Server Log", ActionName));

            ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier,
                request.RetrieveSessionToken());
            foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
            {
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
                links.Add(new ProjectLink(urlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerLogProjectPlugin.ActionName));
            }
            velocityContext["projectLinks"] = links;
            if (string.IsNullOrEmpty(request.ProjectName))
            {
                velocityContext["log"] = HttpUtility.HtmlEncode(farmService.GetServerLog(request.ServerSpecifier, request.RetrieveSessionToken()));
            }
            else
            {
                velocityContext["currentProject"] = request.ProjectSpecifier.ProjectName;
                velocityContext["log"] = HttpUtility.HtmlEncode(farmService.GetServerLog(request.ProjectSpecifier, request.RetrieveSessionToken()));
            }

            return viewGenerator.GenerateView(@"ServerLog.vm", velocityContext);
        }
		public void ReturnsServerLogFromRequestedServerForSpecificProject()
		{
			// Setup
			IServerSpecifier serverSpecifier = new DefaultServerSpecifier("foo");
			IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "foo-project");
			string serverLog = "server log";
			Hashtable expectedHashtable = new Hashtable();
			expectedHashtable["log"] = serverLog;
			expectedHashtable["projectLinks"] = new IsAnything();
			expectedHashtable["currentProject"] = projectSpecifier.ProjectName;

			IResponse response = new HtmlFragmentResponse("foo");

			requestMock.SetupResult("ServerSpecifier", serverSpecifier);			
			requestMock.SetupResult("ProjectName", projectSpecifier.ProjectName);
			requestMock.SetupResult("ProjectSpecifier", projectSpecifier);
			farmServiceMock.ExpectAndReturn("GetServerLog", serverLog, projectSpecifier, null);
			farmServiceMock.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", new ProjectStatusListAndExceptions(new ProjectStatusOnServer[0], null), serverSpecifier, null);			
			viewGeneratorMock.ExpectAndReturn("GenerateView", response, @"ServerLog.vm", new HashtableConstraint(expectedHashtable));

			// Execute
			Assert.AreEqual(response, action.Execute((ICruiseRequest) requestMock.MockInstance));

			VerifyAll();
		}
        public IResponse Execute(ICruiseRequest request)
        {
            Hashtable velocityContext = new Hashtable();
            var links = new List<IAbsoluteLink>();
            links.Add(new ServerLink(request.UrlBuilder, request.ServerSpecifier, "Server Security Configuration", ActionName));

            ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier, request.RetrieveSessionToken());
            foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
            {
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
                links.Add(new ProjectLink(request.UrlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerSecurityConfigurationServerPlugin.ActionName));
            }
            velocityContext["projectLinks"] = links;
            string sessionToken = request.RetrieveSessionToken(sessionRetriever);
            string securityConfig = farmService.GetServerSecurity(request.ServerSpecifier, sessionToken);
            XmlDocument document = new XmlDocument();
            document.LoadXml(securityConfig);
            if (string.IsNullOrEmpty(request.ProjectName))
            {
                securityConfig = document.SelectSingleNode("/security/manager").OuterXml;
            }
            else
            {
                velocityContext["currentProject"] = request.ProjectSpecifier.ProjectName;
                string xpath = string.Format(System.Globalization.CultureInfo.CurrentCulture,"/security/projects/projectSecurity[name='{0}']/authorisation", request.ProjectSpecifier.ProjectName);
                securityConfig = document.SelectSingleNode(xpath).OuterXml;
            }
            string xmlData = FormatXml(securityConfig);
            velocityContext["log"] = xmlData;

            return viewGenerator.GenerateView(@"SecurityConfiguration.vm", velocityContext);
        }
		public void Setup()
		{
			cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest));
			requestMock = new DynamicMock(typeof(IRequest));
			linkFactoryMock = new DynamicMock(typeof(ILinkFactory));
			velocityViewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator));
			farmServiceMock = new DynamicMock(typeof(IFarmService));

			viewBuilder = new TopControlsViewBuilder(
				(ICruiseRequest) cruiseRequestMock.MockInstance,
				(ILinkFactory) linkFactoryMock.MockInstance,
				(IVelocityViewGenerator) velocityViewGeneratorMock.MockInstance,
				(IFarmService) farmServiceMock.MockInstance,
				null, null);

			serverSpecifier = new DefaultServerSpecifier("myServer");
			projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "myProject");
			buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild");
			expectedVelocityContext = new Hashtable();
			response = new HtmlFragmentResponse("foo");
			link1 = new GeneralAbsoluteLink("1");
			link2 = new GeneralAbsoluteLink("2");
			link3 = new GeneralAbsoluteLink("3");
			link4 = new GeneralAbsoluteLink("4");
		}
Beispiel #6
0
        public ProjectGridRow[] GenerateProjectGridRows(ProjectStatusOnServer[] statusList, string forceBuildActionName,
		                                                ProjectGridSortColumn sortColumn, bool sortIsAscending, string categoryFilter,
                                                        ICruiseUrlBuilder urlBuilder, Translations translations)
        {
            ArrayList rows = new ArrayList();
            foreach (ProjectStatusOnServer statusOnServer in statusList)
            {
                ProjectStatus status = statusOnServer.ProjectStatus;
                IServerSpecifier serverSpecifier = statusOnServer.ServerSpecifier;
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, status.Name);

                if ((categoryFilter != string.Empty) && (categoryFilter != status.Category))
                    continue;

                rows.Add(
                    new ProjectGridRow(status,
                                       serverSpecifier,
                                       urlBuilder.BuildProjectUrl(ProjectReportProjectPlugin.ACTION_NAME, projectSpecifier),
                                       urlBuilder.BuildProjectUrl(ProjectParametersAction.ActionName, projectSpecifier),
                                       translations));
            }

            rows.Sort(GetComparer(sortColumn, sortIsAscending));

            return (ProjectGridRow[]) rows.ToArray(typeof (ProjectGridRow));
        }
		public void ShouldReturnWarningMessageIfNoBuildsAvailable()
		{
			IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
			cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);
			farmServiceMock.ExpectAndReturn("GetMostRecentBuildSpecifiers", new IBuildSpecifier[0], projectSpecifier, 1, null);
			
			IResponse returnedReponse = plugin.Execute(cruiseRequest);
			Assert.IsTrue(returnedReponse is HtmlFragmentResponse);
			Assert.AreEqual("There are no complete builds for this project", ((HtmlFragmentResponse) returnedReponse).ResponseFragment);
		}
        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override bool Equals(object obj)
        {
            DefaultProjectSpecifier other = obj as DefaultProjectSpecifier;

            if (other != null)
            {
                return(this.ProjectName == other.ProjectName && this.ServerSpecifier.Equals(other.ServerSpecifier));
            }
            return(false);
        }
		public void Setup()
		{
			cruiseManagerWrapperMock = new DynamicMock(typeof(ICruiseManagerWrapper));

			nameBuildRetriever = new CruiseManagerBuildNameRetriever((ICruiseManagerWrapper) cruiseManagerWrapperMock.MockInstance);

			serverName = "my Server";
			projectName = "my Project";
			buildName = "myLogfile.xml";
			projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier(serverName), projectName);
			buildSpecifier = new DefaultBuildSpecifier(this.projectSpecifier, buildName);
			buildSpecifiers = new IBuildSpecifier[] {CreateBuildSpecifier("log3"), CreateBuildSpecifier("log2"), CreateBuildSpecifier("log1")};
		}
		public void ShouldReturnRedirectToActualBuildReportPageIfBuildAvailable()
		{
			IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
			IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild");
			cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);
			farmServiceMock.ExpectAndReturn("GetMostRecentBuildSpecifiers", new IBuildSpecifier[] { buildSpecifier }, projectSpecifier, 1, null);
			linkFactoryMock.ExpectAndReturn("CreateBuildLink", new GeneralAbsoluteLink("foo", "buildUrl"), buildSpecifier, BuildReportBuildPlugin.ACTION_NAME);

			IResponse returnedReponse = plugin.Execute(cruiseRequest);
			Assert.IsTrue(returnedReponse is RedirectResponse);
			Assert.AreEqual("buildUrl", ((RedirectResponse) returnedReponse).Url);
			
		}
		public void ShouldReturnCorrectMessageIfBuildForcedSuccessfully()
		{
			DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(
				new DefaultServerSpecifier("myServer"), "myProject");
			cruiseRequestMock.SetupResult("ProjectSpecifier", projectSpecifier);
			cruiseRequestMock.SetupResult("ProjectName", "myProject");

            mockFarmService.Expect("ForceBuild", projectSpecifier, (string)null);

			IResponse response = reportAction.Execute(cruiseRequest);
			Assert.IsTrue(response is XmlFragmentResponse);
			Assert.AreEqual("<ForceBuildResult>Build Forced for myProject</ForceBuildResult>",
			                ((XmlFragmentResponse) response).ResponseFragment);
		}
Beispiel #12
0
        public ProjectGridRow[] GenerateProjectGridRows(IFarmService farmService, ProjectStatusOnServer[] statusList, string forceBuildActionName,
            ProjectGridSortColumn sortColumn, bool sortIsAscending)
        {
            ArrayList rows = new ArrayList();
            foreach (ProjectStatusOnServer statusOnServer in statusList)
            {
                ProjectStatus status = statusOnServer.ProjectStatus;
                IServerSpecifier serverSpecifier = statusOnServer.ServerSpecifier;
                string projectName = status.Name;
                IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, projectName);

                string baseUrl = Regex.Replace(statusOnServer.ProjectStatus.WebURL, @"default\.aspx\?.*", "");

                string projectLink = baseUrl + linkFactory.CreateProjectLink(projectSpecifier, ProjectReportProjectPlugin.ACTION_NAME).Url;

                IBuildSpecifier[] buildSpecifiers = farmService.GetMostRecentBuildSpecifiers(projectSpecifier, 1);
                string mostRecentBuildUrl;
                if (buildSpecifiers.Length == 1)
                {
                    mostRecentBuildUrl = baseUrl + linkFactory.CreateProjectLink(projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME).Url;
                }
                else
                {
                    mostRecentBuildUrl = projectLink;
                }

                rows.Add(
                    new ProjectGridRow(
                        projectName, statusOnServer.ServerSpecifier.ServerName, status.BuildStatus.ToString(),
                        CalculateHtmlColor(status.BuildStatus),
                        status.LastBuildDate,
                        status.LastBuildDuration,
                        (status.LastBuildLabel != null ? status.LastBuildLabel : "no build available"),
                        status.Status.ToString(),
                        status.Activity.ToString(),
                        urlBuilder.BuildFormName(forceBuildActionName),
                        projectLink,
                        mostRecentBuildUrl,
                        ChangeSet.Convert(status.Modifications),
                        status.Forcee,
                        status.CurrentBuildStartTime,
                        status.BuildCondition.ToString()
                    ));
            }

            rows.Sort(GetComparer(sortColumn, sortIsAscending));

            return (ProjectGridRow[])rows.ToArray(typeof(ProjectGridRow));
        }
		public void ShouldPassValidModelToBuilderAndReturnBuildersResult()
		{
			IResponse response = new HtmlFragmentResponse("foo");
			// Setup
			IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
			cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);
			string expectedMessage = "Please confirm you want to delete myProject, and choose which extra delete actions you want to perform";
			viewBuilderMock.ExpectAndReturn("BuildView", response, new DeleteProjectModel(projectSpecifier, expectedMessage, true, true, true, true));

			// Execute
			IResponse returnedResponse = showDeleteProjectAction.Execute(cruiseRequest);

			// Verify
			Assert.AreEqual(response, returnedResponse);
			VerifyAll();
		}
		public void ShouldCallFarmServiceAndIfSuccessfulShowSuccessMessage()
		{
			IResponse response = new HtmlFragmentResponse("foo");
			// Setup
			IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
			cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);
			requestMock.ExpectAndReturn("GetChecked", true, "PurgeWorkingDirectory");
			requestMock.ExpectAndReturn("GetChecked", false, "PurgeArtifactDirectory");
			requestMock.ExpectAndReturn("GetChecked", true, "PurgeSourceControlEnvironment");
			farmServiceMock.Expect("DeleteProject", projectSpecifier, true, false, true, null);
			string expectedMessage = "Project Deleted";
			viewBuilderMock.ExpectAndReturn("BuildView", response, new DeleteProjectModel(projectSpecifier, expectedMessage, false, true, false, true));

			// Execute
			IResponse returnedResponse = doDeleteProjectAction.Execute(cruiseRequest);

			// Verify
			Assert.AreEqual(response, returnedResponse);
			VerifyAll();
		}
		public void ShouldGetProjectDetailsAndUseCorrectTemplate()
		{
			// Setup
			ExternalLink[] links = new ExternalLink[] { new ExternalLink("foo", "bar") };
			IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
			//IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild");
            IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "log20050818103522Lbuild.0.0.0.9.xml");

			Hashtable expectedContext = new Hashtable();

            DynamicMock requestStub = new DynamicMock(typeof(IRequest));
            IRequest request = (IRequest)requestStub.MockInstance;

            cruiseRequestMock.SetupResult("Request", request);
            requestStub.SetupResult("ApplicationPath", "myAppPath");
            
            farmServiceMock.ExpectAndReturn("GetRSSFeed", "", projectSpecifier);
            
			expectedContext["projectName"] = "myProject";
			expectedContext["externalLinks"] = links;
			expectedContext["noLogsAvailable"] = false;
			expectedContext["mostRecentBuildUrl"] = "buildUrl";

            expectedContext["applicationPath"] = "myAppPath";
            expectedContext["rssDataPresent"] = false;
            expectedContext["rss"] = new GeneralAbsoluteLink("RSS", @"http://localhost/myServer");


			IResponse response = new HtmlFragmentResponse("myView");

            cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);
            cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);
			farmServiceMock.ExpectAndReturn("GetMostRecentBuildSpecifiers", new IBuildSpecifier[] { buildSpecifier }, projectSpecifier, 1, null);
			farmServiceMock.ExpectAndReturn("GetExternalLinks", links, projectSpecifier, null);
			linkFactoryMock.ExpectAndReturn("CreateProjectLink", new GeneralAbsoluteLink("foo", "buildUrl"), projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME);

            linkFactoryMock.ExpectAndReturn("CreateProjectLink", new GeneralAbsoluteLink("RSS", @"myServer"), projectSpecifier, ThoughtWorks.CruiseControl.WebDashboard.Plugins.RSS.RSSFeed.ACTION_NAME);


            farmServiceMock.ExpectAndReturn("GetMostRecentBuildSpecifiers", new IBuildSpecifier[] { buildSpecifier }, projectSpecifier, ProjectReportProjectPlugin.AmountOfBuildsToRetrieve, null);
            expectedContext["graphDayInfo"] = new NMock.Constraints.IsTypeOf(typeof(ArrayList));
            
            expectedContext["highestAmountPerDay"] = 1;
            expectedContext["dateMultiPlier"] = 1;

            expectedContext["OKPercent"] = 100;
            expectedContext["NOKPercent"] = 0;

            expectedContext["server"] = new DefaultServerSpecifier("myServer");
            expectedContext["StatusMessage"] = string.Empty;
            expectedContext["status"] = null;
            expectedContext["StartStopButtonName"] = "StartBuild";
            expectedContext["StartStopButtonValue"] = "Start";
            expectedContext["ForceAbortBuildButtonName"] = "ForceBuild";
            expectedContext["ForceAbortBuildButtonValue"] = "Force";

			viewGeneratorMock.ExpectAndReturn("GenerateView", response, @"ProjectReport.vm", new HashtableConstraint(expectedContext));


			// Execute
			IResponse returnedResponse = plugin.Execute(cruiseRequest);

			// Verify
			Assert.AreEqual(response, returnedResponse);
			VerifyAll();
		}
		public void ReturnsLatestLogNameFromCorrectProjectOnCorrectServer()
		{
            string buildName = "mylogformyserverformyproject";
            MockRepository mocks = new MockRepository();
            ServerAggregatingCruiseManagerWrapper serverWrapper = InitialiseServerWrapper(mocks,
                delegate(CruiseServerClientBase manager)
                {
                    SetupResult.For(manager.GetLatestBuildName(null))
                        .IgnoreArguments()
                        .Return(buildName);
                });
            mocks.ReplayAll();

			DefaultProjectSpecifier myProjectMyServer = new DefaultProjectSpecifier(new DefaultServerSpecifier("myserver"), "myproject");
            Assert.AreEqual(new DefaultBuildSpecifier(myProjectMyServer, buildName),
                serverWrapper.GetLatestBuildSpecifier(myProjectMyServer, null));
		}
		public void ShouldGenerateBuildViewIfServerAndProjectAndBuildSpecified()
		{
			// Setup
			IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
			IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild");
			cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "myServer");
			cruiseRequestWrapperMock.ExpectAndReturn("ProjectName", "myProject");
			cruiseRequestWrapperMock.ExpectAndReturn("BuildName", "myBuild");
			cruiseRequestWrapperMock.ExpectAndReturn("BuildSpecifier", buildSpecifier);
			cruiseRequestWrapperMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);

			pluginLinkCalculatorMock.ExpectAndReturn("GetBuildPluginLinks", links, buildSpecifier);
			string recentBuildsView = "";
			recentBuildsViewBuilderMock.ExpectAndReturn("BuildRecentBuildsTable", recentBuildsView, buildSpecifier, null);

			IBuildSpecifier nextBuildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "next");
			IBuildSpecifier previousBuildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "previous");
			IAbsoluteLink latestLink = new GeneralAbsoluteLink("test latest");
			IAbsoluteLink nextLink = new GeneralAbsoluteLink("test next");
			IAbsoluteLink previousLink = new GeneralAbsoluteLink("test previous");

			buildNameRetrieverMock.ExpectAndReturn("GetNextBuildSpecifier", nextBuildSpecifier, buildSpecifier, null);
			buildNameRetrieverMock.ExpectAndReturn("GetPreviousBuildSpecifier", previousBuildSpecifier, buildSpecifier, null);

			string action = BuildReportBuildPlugin.ACTION_NAME;

			linkFactoryMock.ExpectAndReturn("CreateProjectLink", latestLink, projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME);
			linkFactoryMock.ExpectAndReturn("CreateBuildLink", nextLink, nextBuildSpecifier, "", action);
			linkFactoryMock.ExpectAndReturn("CreateBuildLink", previousLink, previousBuildSpecifier, "", action);

			velocityContext["links"] = links;
			velocityContext["recentBuildsTable"] = recentBuildsView;
			velocityContext["latestLink"] = latestLink;
			velocityContext["nextLink"] = nextLink;
			velocityContext["previousLink"] = previousLink;

			velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"BuildSideBar.vm", new HashtableConstraint(velocityContext));

			// Execute
			HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest);

			// Verify
			Assert.AreEqual(velocityResponse, returnedResponse);
			VerifyAll();
		}
		public void ShouldGenerateProjectViewIfServerAndProjectButNoBuildSpecified()
		{
			// Setup
			IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
			cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "myServer");
			cruiseRequestWrapperMock.ExpectAndReturn("ProjectName", "myProject");
			cruiseRequestWrapperMock.ExpectAndReturn("BuildName", "");
			cruiseRequestWrapperMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);

			pluginLinkCalculatorMock.ExpectAndReturn("GetProjectPluginLinks", links, projectSpecifier);
			string recentBuildsView = "";
			recentBuildsViewBuilderMock.ExpectAndReturn("BuildRecentBuildsTable", recentBuildsView, projectSpecifier, null);

			velocityContext["links"] = links;
			velocityContext["recentBuildsTable"] = recentBuildsView;

			velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"ProjectSideBar.vm", new HashtableConstraint(velocityContext));

			// Execute
            HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest);

			// Verify
			Assert.AreEqual(velocityResponse, returnedResponse);
			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, new List<ParameterBase>());
			ProjectStatus projectStatusB = new ProjectStatus("B", "CategoryY", ProjectActivity.Sleeping, 
                                                    IntegrationStatus.Success, ProjectIntegratorState.Running, "url",
                                                    DateTime.Today, "1", null, DateTime.Today, "", "", 0, new List<ParameterBase>());
			ProjectStatus projectStatusC = new ProjectStatus("C", "CategoryX", ProjectActivity.Sleeping, 
                                                    IntegrationStatus.Success, ProjectIntegratorState.Running, "url",
                                                    DateTime.Today, "1", null, DateTime.Today, "", "", 0, new List<ParameterBase>());

			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 ShouldReturnProjectsSortedByServerIfServerNameColumnSpecifiedAsSortSeed()
		{
			// Setup
			IServerSpecifier serverSpecifierA = new DefaultServerSpecifier("Aserver");
			IServerSpecifier serverSpecifierB = new DefaultServerSpecifier("Bserver");
			IProjectSpecifier projectA = new DefaultProjectSpecifier(serverSpecifierA, "a");
			IProjectSpecifier projectB = new DefaultProjectSpecifier(serverSpecifierB, "b");

			ProjectStatus projectStatus1 = new ProjectStatus("a", "category",
				ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url",
                DateTime.Today, "1", null, DateTime.Today, "", "", 0, new List<ParameterBase>());
			ProjectStatus projectStatus2 = new ProjectStatus("b", "category",
				ProjectActivity.Sleeping, IntegrationStatus.Failure, ProjectIntegratorState.Running, "url",
                DateTime.Today.AddHours(1), "1", null, DateTime.Today, "", "", 0, new List<ParameterBase>());
			ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[]
				{
					new ProjectStatusOnServer(projectStatus1, serverSpecifierA),
					new ProjectStatusOnServer(projectStatus2, serverSpecifierB)
				};
			SetupProjectLinkExpectation(projectA);
			SetupProjectLinkExpectation(projectB);

			// Execute
            mocks.ReplayAll();
            ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.ServerName, true, "", urlBuilderMock, new Translations("en-US"));

			// Verify
			Assert.AreEqual(2, rows.Length);
			Assert.AreEqual("a", rows[0].Name);
			Assert.AreEqual("b", rows[1].Name);

			// Setup
			SetupProjectLinkExpectation(projectA);
			SetupProjectLinkExpectation(projectB);

			// Execute
            rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.ServerName, false, "", urlBuilderMock, new Translations("en-US"));

			// Verify
			Assert.AreEqual(2, rows.Length);
			Assert.AreEqual("b", rows[0].Name);
			Assert.AreEqual("a", rows[1].Name);

			VerifyAll();
		}
		private IResponse GenerateUserList(ICruiseRequest request, string message, string error)
		{
			Hashtable velocityContext = new Hashtable();
			velocityContext["message"] = message;
			velocityContext["error"] = error;

			var links = new List<IAbsoluteLink>();
			links.Add(new ServerLink(request.UrlBuilder, request.ServerSpecifier, "User List", ActionName));

			ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier, request.RetrieveSessionToken());
			foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
			{
				DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
				links.Add(new ProjectLink(request.UrlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerUserListServerPlugin.ActionName));
			}
			velocityContext["projectLinks"] = links;
			string sessionToken = request.RetrieveSessionToken(sessionRetriever);
			List<UserDetails> allUsers = farmService.ListAllUsers(request.ServerSpecifier, sessionToken);
			foreach (UserDetails user in allUsers)
			{
				if (user.DisplayName == null) user.DisplayName = string.Empty;
			}
			velocityContext["users"] = allUsers;
			if (!string.IsNullOrEmpty(request.ProjectName))
			{
				velocityContext["currentProject"] = request.ProjectName;
				velocityContext["diagnosticsCall"] = new ProjectLink(request.UrlBuilder, request.ProjectSpecifier, string.Empty, DiagnosticsActionName);
			}
			else
			{
				velocityContext["diagnosticsCall"] = new ServerLink(request.UrlBuilder, request.ServerSpecifier, string.Empty, DiagnosticsActionName);
			}

			return viewGenerator.GenerateView(@"UserList.vm", velocityContext);
		}
                GetBuildGraph(int amountOfBuilds, Boolean buildsAreInSameDay)
        {        
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultBuildSpecifier[] builds;
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultProjectSpecifier ProjectSpecifier;
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultServerSpecifier ServerSpecifier;
            CruiseControl.WebDashboard.Dashboard.DefaultLinkFactory LinkFactory;
            CruiseControl.WebDashboard.Dashboard.DefaultBuildNameFormatter BuildNameFormatter;
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultUrlBuilder UrlBuilder;
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultCruiseUrlBuilder CruiseUrlBuilder;
            CruiseControl.Core.Project project;

            project = new CruiseControl.Core.Project();
            project.Name = "TestProject";

            ServerSpecifier = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultServerSpecifier("local");

            ProjectSpecifier = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultProjectSpecifier(ServerSpecifier,project.Name);
            
            builds = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultBuildSpecifier[amountOfBuilds];

            for(int i=0; i < amountOfBuilds; i++)
            {
                if (buildsAreInSameDay)                
                    builds[i] = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultBuildSpecifier( ProjectSpecifier , string.Format(System.Globalization.CultureInfo.CurrentCulture,"log20050801015223Lbuild.0.0.0.{0}.xml", i) );
                  else
                    builds[i] = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultBuildSpecifier( ProjectSpecifier , string.Format(System.Globalization.CultureInfo.CurrentCulture,"log200508{0}015223Lbuild.0.0.0.{1}.xml", (i+1).ToString("00"), i) );
            }

            UrlBuilder = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultUrlBuilder();
            CruiseUrlBuilder = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultCruiseUrlBuilder(UrlBuilder);
            BuildNameFormatter = new CruiseControl.WebDashboard.Dashboard.DefaultBuildNameFormatter();
            
            LinkFactory = new  CruiseControl.WebDashboard.Dashboard.DefaultLinkFactory(UrlBuilder,CruiseUrlBuilder,BuildNameFormatter);
        
            return new CruiseControl.WebDashboard.Plugins.Statistics.BuildGraph(builds, LinkFactory, new Translations("en-US"));
        }