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"); }
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 void Setup() { urlBuilderMock = new Mock <IUrlBuilder>(); serverSpecifier = new DefaultServerSpecifier("myserver"); projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "myproject"); buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "mybuild"); cruiseUrlBuilder = new DefaultCruiseUrlBuilder((IUrlBuilder)urlBuilderMock.Object); }
public void Setup() { urlBuilderMock = new DynamicMock(typeof(IUrlBuilder)); serverSpecifier = new DefaultServerSpecifier("myserver"); projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "myproject"); buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "mybuild"); cruiseUrlBuilder = new DefaultCruiseUrlBuilder((IUrlBuilder)urlBuilderMock.MockInstance); }
public override bool Equals(object obj) { if (obj is DefaultServerSpecifier) { DefaultServerSpecifier other = obj as DefaultServerSpecifier; return(this.ServerName == other.ServerName); } return(false); }
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); ProjectStatus projectStatus2 = new ProjectStatus("b", "category", ProjectActivity.Sleeping, IntegrationStatus.Failure, ProjectIntegratorState.Running, "url", DateTime.Today.AddHours(1), "1", null, DateTime.Today, "", "", 0); 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(); }
public void ReturnsServerLogFromRequestedServer() { // Setup IServerSpecifier serverSpecifier = new DefaultServerSpecifier("foo"); string serverLog = "server log"; HtmlFragmentResponse response = new HtmlFragmentResponse("foo"); requestMock.SetupGet(_request => _request.ServerSpecifier).Returns(serverSpecifier); farmServiceMock.Setup(service => service.GetServerLog(serverSpecifier, null)).Returns(serverLog).Verifiable(); farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(serverSpecifier, null)).Returns(new ProjectStatusListAndExceptions(new ProjectStatusOnServer[0], null)).Verifiable(); viewGeneratorMock.Setup(generator => generator.GenerateView(@"ServerLog.vm", It.Is <Hashtable>(t => t.Count == 2 && (string)t["log"] == serverLog && t.ContainsKey("projectLinks")))).Returns(response).Verifiable(); // Execute Assert.AreEqual(response, action.Execute((ICruiseRequest)requestMock.Object)); VerifyAll(); }
public void ShouldGenerateServerLinks() { string action = "ViewServerReport"; IServerSpecifier serverSpecifier1 = new DefaultServerSpecifier("myserver"); IServerSpecifier serverSpecifier2 = new DefaultServerSpecifier("myotherserver"); IAbsoluteLink link1 = new GeneralAbsoluteLink("link 1"); IAbsoluteLink link2 = new GeneralAbsoluteLink("link 2"); linkFactoryMock.ExpectAndReturn("CreateServerLink", link1, serverSpecifier1, action); linkFactoryMock.ExpectAndReturn("CreateServerLink", link2, serverSpecifier2, action); IAbsoluteLink[] returnedLinks = linkListFactory.CreateServerLinkList(new IServerSpecifier[] { serverSpecifier1, serverSpecifier2 }, action); Assert.AreEqual(2, returnedLinks.Length); Assert.AreEqual(link1, returnedLinks[0]); Assert.AreEqual(link2, returnedLinks[1]); VerifyAll(); }
public void Setup() { serverSpecifier = new DefaultServerSpecifier(serverName); projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, projectName); buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, buildName); linkFactoryMock = new Mock <ILinkFactory>(); configurationMock = new Mock <IPluginConfiguration>(); Plugins = new DefaultPluginLinkCalculator((ILinkFactory)linkFactoryMock.Object, (IPluginConfiguration)configurationMock.Object); pluginMock1 = new Mock <IPlugin>(); pluginMock2 = new Mock <IPlugin>(); action1 = new ImmutableNamedAction("Action Name 1", null); action2 = new ImmutableNamedAction("Action Name 2", null); action3 = new ImmutableNamedAction("Action Name 3", null); pluginMock1.SetupGet(plugin => plugin.LinkDescription).Returns("Description 1").Verifiable(); pluginMock1.SetupGet(plugin => plugin.NamedActions).Returns(new INamedAction[] { action1 }).Verifiable(); pluginMock2.SetupGet(plugin => plugin.LinkDescription).Returns("Description 2").Verifiable(); pluginMock2.SetupGet(plugin => plugin.NamedActions).Returns(new INamedAction[] { action2 }).Verifiable(); link1 = (IAbsoluteLink) new Mock <IAbsoluteLink>().Object; link2 = (IAbsoluteLink) new Mock <IAbsoluteLink>().Object; }
public void Setup() { serverSpecifier = new DefaultServerSpecifier(serverName); projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, projectName); buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, buildName); linkFactoryMock = new DynamicMock(typeof(ILinkFactory)); configurationMock = new DynamicMock(typeof(IPluginConfiguration)); Plugins = new DefaultPluginLinkCalculator((ILinkFactory)linkFactoryMock.MockInstance, (IPluginConfiguration)configurationMock.MockInstance); pluginMock1 = new DynamicMock(typeof(IPlugin)); pluginMock2 = new DynamicMock(typeof(IPlugin)); action1 = new ImmutableNamedAction("Action Name 1", null); action2 = new ImmutableNamedAction("Action Name 2", null); action3 = new ImmutableNamedAction("Action Name 3", null); pluginMock1.ExpectAndReturn("LinkDescription", "Description 1"); pluginMock1.ExpectAndReturn("NamedActions", new INamedAction[] { action1 }); pluginMock2.ExpectAndReturn("LinkDescription", "Description 2"); pluginMock2.ExpectAndReturn("NamedActions", new INamedAction[] { action2 }); link1 = (IAbsoluteLink) new DynamicMock(typeof(IAbsoluteLink)).MockInstance; link2 = (IAbsoluteLink) new DynamicMock(typeof(IAbsoluteLink)).MockInstance; }
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 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 void Setup() { configurationMock = new Mock <IRemoteServicesConfiguration>(); cruiseManagerFactoryMock = new Mock <ICruiseServerClientFactory>(); cruiseManagerMock = new Mock <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.Object, (ICruiseServerClientFactory)cruiseManagerFactoryMock.Object ); 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 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 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(); var requestStub = new Mock <IRequest>(); IRequest request = (IRequest)requestStub.Object; cruiseRequestMock.SetupGet(r => r.Request).Returns(request); requestStub.SetupGet(r => r.ApplicationPath).Returns("myAppPath"); farmServiceMock.Setup(service => service.GetRSSFeed(projectSpecifier, It.IsAny <string>())).Returns("").Verifiable(); 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"); HtmlFragmentResponse response = new HtmlFragmentResponse("myView"); cruiseRequestMock.SetupGet(r => r.ProjectSpecifier).Returns(projectSpecifier).Verifiable(); farmServiceMock.Setup(service => service.GetMostRecentBuildSpecifiers(projectSpecifier, 1, null)).Returns(new IBuildSpecifier[] { buildSpecifier }).Verifiable(); farmServiceMock.Setup(service => service.GetExternalLinks(projectSpecifier, null)).Returns(links).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateProjectLink(projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME)).Returns(new GeneralAbsoluteLink("foo", "buildUrl")).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateProjectLink(projectSpecifier, ThoughtWorks.CruiseControl.WebDashboard.Plugins.RSS.RSSFeed.ACTION_NAME)).Returns(new GeneralAbsoluteLink("RSS", @"myServer")).Verifiable(); farmServiceMock.Setup(service => service.GetMostRecentBuildSpecifiers(projectSpecifier, ProjectReportProjectPlugin.AmountOfBuildsToRetrieve, null)).Returns(new IBuildSpecifier[] { buildSpecifier }).Verifiable(); expectedContext["graphDayInfo"] = new 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.Setup(generator => generator.GenerateView(@"ProjectReport.vm", It.IsAny <Hashtable>())). Callback <string, Hashtable>((name, context) => Assert.AreEqual(context, expectedContext)).Returns(response).Verifiable(); // Execute IResponse returnedResponse = plugin.Execute(cruiseRequest); // Verify Assert.AreEqual(response, returnedResponse); VerifyAll(); }