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 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 Setup() { configurationMock = new DynamicMock(typeof (IRemoteServicesConfiguration)); cruiseManagerFactoryMock = new DynamicMock(typeof(ICruiseServerClientFactory)); cruiseManagerMock = new DynamicMock(typeof (ICruiseServerClient)); serverSpecifier = new DefaultServerSpecifier("myserver"); projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "myproject"); buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "mybuild"); buildSpecifierForUnknownServer = new DefaultBuildSpecifier(new DefaultProjectSpecifier(new DefaultServerSpecifier("unknownServer"), "myProject"), "myBuild"); managerWrapper = new ServerAggregatingCruiseManagerWrapper( (IRemoteServicesConfiguration) configurationMock.MockInstance, (ICruiseServerClientFactory)cruiseManagerFactoryMock.MockInstance ); serverLocation = new ServerLocation(); serverLocation.Name = "myserver"; serverLocation.Url = "http://myurl"; serverLocation.AllowForceBuild = true; otherServerLocation = new ServerLocation(); otherServerLocation.Name = "myotherserver"; otherServerLocation.Url = "http://myotherurl"; }
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(); }
/// <summary> /// Save the server details /// </summary> /// <param name="request"></param> /// <param name="velocityContext"></param> private void SaveServer(IRequest request, Hashtable velocityContext) { // Retrieve the details string newName = request.GetText("newName"); string oldName = request.GetText("oldName"); string serverUri = request.GetText("serverUri"); bool serverForceBuild = request.GetChecked("serverForceBuild"); bool serverStartStop = request.GetChecked("serverStartStop"); bool backwardsCompatible = request.GetChecked("serverBackwardsCompatible"); // Validate the details if (string.IsNullOrEmpty(newName)) { velocityContext["Error"] = this.translations.Translate("Name is a compulsory value"); return; } if (string.IsNullOrEmpty(serverUri)) { velocityContext["Error"] = this.translations.Translate("URI is a compulsory value"); return; } // Find the server XmlDocument configFile = LoadConfig(); XmlElement serverEl = configFile.SelectSingleNode( string.Format( "/dashboard/remoteServices/servers/server[@name='{0}']", oldName)) as XmlElement; ServerLocation location = null; if (serverEl == null) { // If the element wasn't found, start a new one serverEl = configFile.CreateElement("server"); configFile.SelectSingleNode("/dashboard/remoteServices/servers") .AppendChild(serverEl); // Add the new server location = new ServerLocation(); ServerLocation[] locations = new ServerLocation[servicesConfiguration.Servers.Length + 1]; servicesConfiguration.Servers.CopyTo(locations, 0); locations[servicesConfiguration.Servers.Length] = location; servicesConfiguration.Servers = locations; } else { // Get the existing server config foreach (ServerLocation locationToCheck in servicesConfiguration.Servers) { if (locationToCheck.Name == oldName) { location = locationToCheck; break; } } } // Set all the properties serverEl.SetAttribute("name", newName); serverEl.SetAttribute("url", serverUri); serverEl.SetAttribute("allowForceBuild", serverForceBuild ? "true" : "false"); serverEl.SetAttribute("allowStartStopBuild", serverStartStop ? "true" : "false"); serverEl.SetAttribute("backwardsCompatible", backwardsCompatible ? "true" : "false"); SaveConfig(configFile); if (location != null) { location.Name = newName; location.Url = serverUri; location.AllowForceBuild = serverForceBuild; location.AllowStartStopBuild = serverStartStop; location.BackwardCompatible = backwardsCompatible; } velocityContext["Result"] = this.translations.Translate("Server has been saved"); CachingDashboardConfigurationLoader.ClearCache(); }
public void ReturnsServerConfiguration() { ServerLocation[] servers = new ServerLocation[] {serverLocation, otherServerLocation}; configurationMock.ExpectAndReturn("Servers", servers); IServerSpecifier specifier = managerWrapper.GetServerConfiguration("myserver"); Assert.AreEqual(true, specifier.AllowForceBuild); VerifyAll(); }
private ServerAggregatingCruiseManagerWrapper InitialiseServerWrapper(MockRepository mocks, Action<CruiseServerClientBase> additionalSetup) { IRemoteServicesConfiguration configuration = mocks.DynamicMock<IRemoteServicesConfiguration>(); ICruiseServerClientFactory cruiseManagerFactory = mocks.DynamicMock<ICruiseServerClientFactory>(); CruiseServerClientBase cruiseManager = mocks.DynamicMock<CruiseServerClientBase>(); ServerLocation[] servers = new ServerLocation[] { serverLocation, otherServerLocation }; SetupResult.For(configuration.Servers) .Return(servers); SetupResult.For(cruiseManagerFactory.GenerateClient("http://myurl", new ClientStartUpSettings())) .IgnoreArguments() .Return(cruiseManager); ServerAggregatingCruiseManagerWrapper serverWrapper = new ServerAggregatingCruiseManagerWrapper( configuration, cruiseManagerFactory); if (additionalSetup != null) additionalSetup(cruiseManager); return serverWrapper; }
public void ReturnsServerNames() { ServerLocation[] servers = new ServerLocation[] {serverLocation, otherServerLocation}; configurationMock.SetupResult("Servers", servers); IServerSpecifier[] serverSpecifiers = managerWrapper.GetServerSpecifiers(); Assert.AreEqual(2, serverSpecifiers.Length); Assert.AreEqual("myserver", serverSpecifiers[0].ServerName); Assert.AreEqual("myotherserver", serverSpecifiers[1].ServerName); VerifyAll(); }