private static void WriteProjectStatus(XmlWriter xmlWriter, ProjectStatus status, IServerSpecifier serverSpecifier) { xmlWriter.WriteStartElement("Project"); xmlWriter.WriteAttributeString("name", status.Name); xmlWriter.WriteAttributeString("category", status.Category); xmlWriter.WriteAttributeString("activity", status.Activity.ToString()); xmlWriter.WriteAttributeString("lastBuildStatus", status.BuildStatus.ToString()); xmlWriter.WriteAttributeString("lastBuildLabel", status.LastSuccessfulBuildLabel); xmlWriter.WriteAttributeString("lastBuildTime", XmlConvert.ToString(status.LastBuildDate, XmlDateTimeSerializationMode.Local)); xmlWriter.WriteAttributeString("nextBuildTime", XmlConvert.ToString(status.NextBuildTime, XmlDateTimeSerializationMode.Local)); xmlWriter.WriteAttributeString("webUrl", status.WebURL); xmlWriter.WriteAttributeString("CurrentMessage", status.CurrentMessage); xmlWriter.WriteAttributeString("BuildStage", status.BuildStage); xmlWriter.WriteAttributeString("serverName", serverSpecifier.ServerName); xmlWriter.WriteAttributeString("description", status.Description); xmlWriter.WriteStartElement("messages"); foreach (Message m in status.Messages) { xmlWriter.WriteStartElement("message"); xmlWriter.WriteAttributeString("text", m.Text); xmlWriter.WriteAttributeString("kind", m.Kind.ToString()); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); }
public void ToStringSerialisesAllValues() { ProjectStatus projectStatus = new ProjectStatus("test project", IntegrationStatus.Success, DateTime.Now); ProjectStatusResponse response = new ProjectStatusResponse(); response.ErrorMessages.Add(new ErrorMessage("Error 1")); response.ErrorMessages.Add(new ErrorMessage("Error 2")); response.RequestIdentifier = "request"; response.Result = ResponseResult.Success; response.Timestamp = DateTime.Now; response.Projects.Add(projectStatus); string actual = response.ToString(); string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture,"<projectStatusResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + "timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" result=\"{1}\">" + "<error>Error 1</error>" + "<error>Error 2</error>" + "<project showForceBuildButton=\"true\" showStartStopButton=\"true\" serverName=\"{5}\" status=\"Running\" buildStatus=\"Success\" name=\"test project\" " + "queuePriority=\"0\" lastBuildDate=\"{3:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\" nextBuildTime=\"{4:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" + "<activity type=\"Sleeping\" />" + "</project>" + "</projectStatusResponse>", response.RequestIdentifier, response.Result, response.Timestamp, projectStatus.LastBuildDate, projectStatus.NextBuildTime, Environment.MachineName); Assert.AreEqual(expected, actual); }
private static void DisplayProject(ProjectStatus project) { WriteLine(string.Format("{0}: {1}", project.Name, project.Status), ConsoleColor.White); WriteLine(string.Format("\tActivity: {0}", project.Activity), ConsoleColor.White); WriteLine(string.Format("\tBuild Status: {0}", project.BuildStatus), ConsoleColor.White); if (!string.IsNullOrEmpty(project.BuildStage)) { XmlDocument stageXml = new XmlDocument(); try { stageXml.LoadXml(project.BuildStage); foreach (XmlElement stageItem in stageXml.SelectNodes("/data/Item")) { string stageTime = stageItem.GetAttribute("Time"); string stageData = stageItem.GetAttribute("Data"); WriteLine(string.Format("\tBuild Stage: {0} ({1})", stageData, stageTime), ConsoleColor.White); } } catch { WriteLine(string.Format("\tBuild Stage: {0}", project.BuildStage), ConsoleColor.White); } } WriteLine(string.Format("\tLast Build: {0:G}", project.LastBuildDate), ConsoleColor.White); WriteLine(string.Format("\tNext Build: {0:G}", project.NextBuildTime), ConsoleColor.White); }
public ProjectGridRow(ProjectStatus status, IServerSpecifier serverSpecifier, string url, string parametersUrl, Translations translations) { this.status = status; this.serverSpecifier = serverSpecifier; this.url = url; this.parametersUrl = parametersUrl; }
private int CompareProjectStatusByQueueAndQueuePriority(ProjectStatus x, ProjectStatus y) { if (x.Queue == y.Queue) { return x.QueuePriority.CompareTo(y.QueuePriority); } return x.Queue.CompareTo(y.Queue); }
public void NameReturnsNameFromStatus() { var client = mocks.DynamicMock<CruiseServerClientBase>(); var server = InitialiseServer(); var status = new ProjectStatus { Name = "Test Project" }; var project = new Project(client, server, status); mocks.ReplayAll(); Assert.AreEqual(status.Name, project.Name); }
public void ServerReturnsUnderlyingServer() { var client = mocks.DynamicMock<CruiseServerClientBase>(); var server = InitialiseServer(); var status = new ProjectStatus(); var project = new Project(client, server, status); mocks.ReplayAll(); Assert.AreSame(server, project.Server); }
public void ShouldReturnNullIfNamedProjectNotFound() { ProjectStatus[] projectStatuses = new ProjectStatus[1]; projectStatuses[0] = new ProjectStatus("no names", IntegrationStatus.Failure, DateTime.Now); CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, null); Assert.IsNull(cruiseServerSnapshot.GetProjectStatus("this doesn't match")); }
public void GetProjectStatusSendsRequest() { ProjectStatus status = new ProjectStatus("Test project", IntegrationStatus.Success, DateTime.Now); ProjectStatusResponse response = new ProjectStatusResponse(); response.Result = ResponseResult.Success; response.Projects.Add(status); CruiseServerClient client = new CruiseServerClient( new ServerStub("GetProjectStatus", typeof(ServerRequest), response)); client.GetProjectStatus(); }
public void CorrectAssignmentOfConstructorArguments() { ProjectStatus[] projectStatuses = new ProjectStatus[0]; QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot(); CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, queueSetSnapshot); Assert.AreSame(projectStatuses, cruiseServerSnapshot.ProjectStatuses); Assert.AreSame(queueSetSnapshot, cruiseServerSnapshot.QueueSetSnapshot); }
public void ShouldFindProjectStatusBasedOnProjectName() { ProjectStatus[] projectStatuses = new ProjectStatus[2]; projectStatuses[0] = new ProjectStatus("test1", IntegrationStatus.Failure, DateTime.Now); projectStatuses[1] = new ProjectStatus("test2", IntegrationStatus.Success, DateTime.Now); CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, null); Assert.AreSame(projectStatuses[0], cruiseServerSnapshot.GetProjectStatus("test1")); Assert.AreSame(projectStatuses[1], cruiseServerSnapshot.GetProjectStatus("test2")); }
public void SaveAndLoadProjectStatus() { ProjectStatus projectStatus = new ProjectStatus("project", "category", ProjectActivity.Building, IntegrationStatus.Failure, ProjectIntegratorState.Running, "http://localhost/ccnet", DateTime.Now, "1.0", "1.0", DateTime.Now, "building", "", 0); BinaryFormatter binaryFormatter = new BinaryFormatter(); using (MemoryStream stream = new MemoryStream()) { binaryFormatter.Serialize(stream, projectStatus); stream.Seek(0, SeekOrigin.Begin); binaryFormatter.Deserialize(stream); } }
public void WhenPollIsCalledRetrievesANewCopyOfTheProjectStatus() { ProjectStatus status = new ProjectStatus(); mockProjectManager.ExpectAndReturn("ProjectName", PROJECT_NAME); mockServerMonitor.ExpectAndReturn("GetProjectStatus", status, PROJECT_NAME); monitor.Poll(); // deliberately called twice: should not go back to server on 2nd // call Assert.AreSame(status, monitor.ProjectStatus); Assert.AreSame(status, monitor.ProjectStatus); }
public void ThePollEventIsFiredWhenPollIsInvoked() { Assert.AreEqual(0, pollCount); ProjectStatus status = new ProjectStatus(); mockProjectManager.ExpectAndReturn("ProjectName", PROJECT_NAME); mockServerMonitor.ExpectAndReturn("GetProjectStatus", status, PROJECT_NAME); monitor.Poll(); Assert.AreEqual(1, pollCount); mockProjectManager.ExpectAndReturn("ProjectName", PROJECT_NAME); mockServerMonitor.ExpectAndReturn("GetProjectStatus", status, PROJECT_NAME); monitor.Poll(); Assert.AreEqual(2, pollCount); }
public void ToStringSerialisesAllValues() { QueueSnapshot queueSnapshot = new QueueSnapshot("queue1"); queueSnapshot.Requests.Add(new QueuedRequestSnapshot("test project", ProjectActivity.Pending)); QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot(); queueSetSnapshot.Queues.Add(queueSnapshot); ProjectStatus projectStatus = new ProjectStatus("test project", IntegrationStatus.Success, DateTime.Now); CruiseServerSnapshot snapshot = new CruiseServerSnapshot( new ProjectStatus[] { projectStatus }, queueSetSnapshot); SnapshotResponse response = new SnapshotResponse(); response.ErrorMessages.Add(new ErrorMessage("Error 1")); response.ErrorMessages.Add(new ErrorMessage("Error 2")); response.RequestIdentifier = "request"; response.Result = ResponseResult.Success; response.Timestamp = DateTime.Now; response.Snapshot = snapshot; string actual = response.ToString(); string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture,"<snapshotResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + "timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" result=\"{1}\">" + "<error>Error 1</error>" + "<error>Error 2</error>" + "<snapshot>" + "<projects>" + "<projectStatus showForceBuildButton=\"true\" showStartStopButton=\"true\" serverName=\"{6}\" status=\"Running\" buildStatus=\"Success\" name=\"test project\" " + "queuePriority=\"0\" lastBuildDate=\"{3:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\" nextBuildTime=\"{4:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" + "<activity type=\"Sleeping\" />" + "<parameters />" + "</projectStatus>" + "</projects>" + "<queueSet>" + "<queue name=\"queue1\">" + "<queueRequest projectName=\"test project\" time=\"{5:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" + "<activity type=\"Pending\" />" + "</queueRequest>" + "</queue>" + "</queueSet>" + "</snapshot>" + "</snapshotResponse>", response.RequestIdentifier, response.Result, response.Timestamp, projectStatus.LastBuildDate, projectStatus.NextBuildTime, DateTime.MinValue, Environment.MachineName); Assert.AreEqual(expected, actual); }
private static void WriteProjectStatus(XmlWriter xmlWriter, ProjectStatus projectStatus) { xmlWriter.WriteStartElement("Project"); xmlWriter.WriteAttributeString("name", projectStatus.Name); xmlWriter.WriteAttributeString("category", projectStatus.Category); xmlWriter.WriteAttributeString("activity", projectStatus.Activity.ToString()); xmlWriter.WriteAttributeString("status", projectStatus.Status.ToString()); xmlWriter.WriteAttributeString("lastBuildStatus", projectStatus.BuildStatus.ToString()); xmlWriter.WriteAttributeString("lastBuildLabel", projectStatus.LastSuccessfulBuildLabel); xmlWriter.WriteAttributeString("lastBuildTime", XmlConvert.ToString(projectStatus.LastBuildDate, XmlDateTimeSerializationMode.Local)); xmlWriter.WriteAttributeString("nextBuildTime", XmlConvert.ToString(projectStatus.NextBuildTime, XmlDateTimeSerializationMode.Local)); xmlWriter.WriteAttributeString("webUrl", projectStatus.WebURL); xmlWriter.WriteAttributeString("buildStage", projectStatus.BuildStage); xmlWriter.WriteAttributeString("serverName", projectStatus.ServerName); xmlWriter.WriteEndElement(); }
public void GetProjectStatusReturnsProjects() { ProjectStatus status = new ProjectStatus("Test project", IntegrationStatus.Success, DateTime.Now); ProjectStatusResponse response = new ProjectStatusResponse(); response.Result = ResponseResult.Success; response.Projects.Add(status); IServerConnection connection = mocks.DynamicMock<IServerConnection>(); SetupResult.For(connection.SendMessage("GetProjectStatus", null)) .IgnoreArguments() .Return(response); mocks.ReplayAll(); CruiseServerClient client = new CruiseServerClient(connection); ProjectStatus[] results = client.GetProjectStatus(); Assert.AreEqual(1, results.Length); Assert.AreEqual(status, results[0]); }
public BuildCondition ShouldRunIntegration() { BuildCondition buildCondition = InnerTrigger.ShouldRunIntegration(); if (buildCondition == BuildCondition.NoBuild) return buildCondition; IntegrationCompleted(); // reset inner trigger ProjectStatus currentStatus = GetCurrentProjectStatus(); if (lastStatus == null) { lastStatus = currentStatus; return BuildCondition.NoBuild; } if (currentStatus.LastBuildDate > lastStatus.LastBuildDate && currentStatus.BuildStatus == TriggerStatus) { lastStatus = currentStatus; return buildCondition; } return BuildCondition.NoBuild; }
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 TestShouldRunIntegrationAllowedByExclusionFilter() { ProjectForceFilter TestSubject = new ProjectForceFilter(); TestSubject.ProjectFilters = new ProjectFilterList(); ProjectFilter Project = new ProjectFilter(); Project.Project = "TestProject"; Project.ServerUri = "TestUri"; Project.ExclusionFilters.Activities = new ProjectActivity[2] { ProjectActivity.Building, ProjectActivity.CheckingModifications }; Project.ExclusionFilters.Conditions = new IntegrationStatus[1] { IntegrationStatus.Failure }; RecorderIRemotingService RemotingRecorder = new RecorderIRemotingService(); RecorderICruiseManager CruiseRecorder = new RecorderICruiseManager(); ProjectStatus Stati = new ProjectStatus(); Stati.Name = "TestProject"; Stati.Activity = ProjectActivity.Sleeping; Stati.BuildStatus = IntegrationStatus.Success; CruiseRecorder.Recordings.GetProjectStatusRecording.ReturnValue = new ProjectStatus[1] { Stati }; RemotingRecorder.Recordings.ConnectTypeStringRecording.ReturnValue = CruiseRecorder; Project.RemoteService = RemotingRecorder; TestSubject.ProjectFilters.Add(Project); bool Condition = TestSubject.ShouldRunIntegration(null, null); Assert.IsTrue(RemotingRecorder.Recordings.ConnectTypeStringRecording.Called); Assert.AreEqual("TestUri", RemotingRecorder.Recordings.ConnectTypeStringRecording.PassedStringuri); Assert.AreEqual(typeof(ICruiseManager), RemotingRecorder.Recordings.ConnectTypeStringRecording.PassedTypeproxyType); Assert.IsTrue(CruiseRecorder.Recordings.GetProjectStatusRecording.Called); Assert.IsTrue(Condition); }
/// <summary> /// Parse an array of project definitions. /// </summary> /// <param name="projectNodes"></param> /// <returns></returns> private List <ProjectStatus> ParseProjects(XmlNodeList projectNodes) { var projects = new List <ProjectStatus>(); foreach (XmlElement node in projectNodes) { var project = new ProjectStatus { Activity = new ProjectActivity(RetrieveAttributeValue(node, "activity", "Unknown")), BuildStage = node.GetAttribute("BuildStage"), BuildStatus = RetrieveAttributeValue(node, "lastBuildStatus", IntegrationStatus.Unknown), Category = node.GetAttribute("category"), LastBuildDate = RetrieveAttributeValue(node, "lastBuildTime", DateTime.MinValue), LastBuildLabel = node.GetAttribute("lastBuildLabel"), Name = node.GetAttribute("name"), NextBuildTime = RetrieveAttributeValue(node, "nextBuildTime", DateTime.MaxValue), ServerName = node.GetAttribute("serverName"), Status = RetrieveAttributeValue(node, "status", ProjectIntegratorState.Unknown), WebURL = node.GetAttribute("webUrl") }; projects.Add(project); } return(projects); }
public Boolean IsAllowed(ProjectStatus status) { Boolean ToAllow = true; if (Conditions != null && Conditions.Length != 0) { foreach (IntegrationStatus Condition in this.Conditions) { if (Condition == status.BuildStatus) return false; } } if (Activities != null && Activities.Length != 0) { foreach (ProjectActivity Activity in this.Activities) { if (Activity == status.Activity) return false; } } return ToAllow; }
private ProjectStatus[] ConvertDashboardProjects(DashboardProject[] dashboardProjects) { ProjectStatus[] projectStatuses = null; if (dashboardProjects != null) { projectStatuses = new ProjectStatus[dashboardProjects.Length]; for (int index = 0; index < dashboardProjects.Length; index++) { DashboardProject dashboardProject = dashboardProjects[index]; projectStatuses[index] = new ProjectStatus( dashboardProject.name, dashboardProject.category, new ProjectActivity(dashboardProject.activity), (IntegrationStatus)Enum.Parse(typeof(IntegrationStatus), dashboardProject.lastBuildStatus), GetIntegratorStateFromString(dashboardProject.status), dashboardProject.webUrl, dashboardProject.lastBuildTime, dashboardProject.lastBuildLabel, dashboardProject.lastBuildLabel, dashboardProject.nextBuildTime, dashboardProject.buildStage, dashboardProject.queue, dashboardProject.queuePriority, dashboardProject.parameters); projectStatuses[index].ServerName = dashboardProject.serverName; } } return projectStatuses; }
public ProjectStatusOnServer(ProjectStatus projectStatus, IServerSpecifier serverSpecifier) { this.serverSpecifier = serverSpecifier; this.projectStatus = projectStatus; }
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, new List<ParameterBase>()); 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, new List<ParameterBase>()); 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 void LastBuildDateGetSetTest() { DateTime timeNow = DateTime.Now; ProjectStatus activity = new ProjectStatus(); activity.LastBuildDate = timeNow; Assert.AreEqual(timeNow, activity.LastBuildDate); }
/// <summary> /// Filters a list of projects and only returns the projects that a user is allowed to view. /// </summary> /// <param name="sessionToken">The session token to use in filtering.</param> /// <param name="projects">The projects to filter.</param> /// <returns>The filtered projects.</returns> private ProjectStatus[] FilterProjects(string sessionToken, ProjectStatus[] projects) { var allowedProjects = new List<ProjectStatus>(); var userName = securityManager.GetUserName(sessionToken); var defaultIsAllowed = (securityManager.GetDefaultRight(SecurityPermission.ViewProject) == SecurityRight.Allow); foreach (ProjectStatus project in projects) { IProjectIntegrator projectIntegrator = GetIntegrator(project.Name); bool isAllowed = true; if (projectIntegrator != null) { IProjectAuthorisation authorisation = projectIntegrator.Project.Security; if ((authorisation != null) && authorisation.RequiresSession(securityManager)) { var thisUserName = userName; if (string.IsNullOrEmpty(thisUserName)) thisUserName = authorisation.GuestAccountName; if (thisUserName == null) { isAllowed = defaultIsAllowed; } else { isAllowed = authorisation.CheckPermission(securityManager, thisUserName, SecurityPermission.ViewProject, SecurityRight.Allow); } } } if (isAllowed) { allowedProjects.Add(project); } } return allowedProjects.ToArray(); }
/// <summary> /// Wraps the specified project status. /// </summary> /// <param name="owningClient">The owning client.</param> /// <param name="projectStatus">The project status.</param> /// <param name="connection">The connection.</param> /// <returns> /// The new <see cref="CCProject"/>. /// </returns> internal static CCProject Wrap(CruiseServerClientBase owningClient, ProjectStatus projectStatus, CCConnection connection) { var project = new CCProject( owningClient, projectStatus.Name, projectStatus.Category, projectStatus.Activity, projectStatus.BuildStatus, projectStatus.Status, projectStatus.WebURL, projectStatus.LastBuildDate, projectStatus.LastBuildLabel, projectStatus.LastSuccessfulBuildLabel, projectStatus.NextBuildTime, projectStatus.BuildStage, projectStatus.Queue, projectStatus.QueuePriority, projectStatus.Parameters) { Connection = connection }; return project; }
/// <summary> /// Initialise a new populated <see cref="CruiseServerSnapshot"/>. /// </summary> /// <param name="projectStatuses"></param> /// <param name="queueSetSnapshot"></param> public CruiseServerSnapshot(ProjectStatus[] projectStatuses, QueueSetSnapshot queueSetSnapshot) { this.projectStatuses = projectStatuses; this.queueSetSnapshot = queueSetSnapshot; }
/// <summary> /// Filters a list of queues and only returns the queues for the projects that a user is allowed to view. /// </summary> /// <param name="sessionToken">The session token to use in filtering.</param> /// <param name="filteredProjects">The already filtered projects.</param> /// <param name="queueSet">The set of queues to filter.</param> /// <returns>The filtered set.</returns> private QueueSetSnapshot FilterQueues(string sessionToken, ProjectStatus[] filteredProjects, QueueSetSnapshot queueSet) { var allowedQueues = new QueueSetSnapshot(); var userName = securityManager.GetUserName(sessionToken); var defaultIsAllowed = (securityManager.GetDefaultRight(SecurityPermission.ViewProject) == SecurityRight.Allow); foreach (QueueSnapshot queue in queueSet.Queues) { if (filteredProjects.Select(x => x.Queue).Contains(queue.QueueName)) allowedQueues.Queues.Add(queue); } return allowedQueues; }