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 WhenARequestIsFoundInTheCacheItIsReturned()
		{
			IResponse expectedResponse = new HtmlFragmentResponse("<html />");
			IRequest request = CreateRequest();

			mockCache.ExpectAndReturn("Get", expectedResponse, request);

			IResponse actualResponse = proxy.Execute(request);
			Assert.AreSame(expectedResponse, actualResponse);

			VerifyAll();
		}
		public void WhenARequestIsNotFoundInTheCacheTheWrappedActionIsCalledAndInsertedIntoTheCache()
		{
			IResponse generatedResponse = new HtmlFragmentResponse("<html />");
			IRequest request = CreateRequest();

			mockCache.ExpectAndReturn("Get", null, request);
			mockAction.ExpectAndReturn("Execute", generatedResponse, request);
			mockCache.Expect("Insert", request, generatedResponse);

			IResponse actualResponse = proxy.Execute(request);
			Assert.AreSame(generatedResponse, actualResponse);

			VerifyAll();
		}
		public void ShouldNotProxyAndShowErrorMessageIfProjectMissing()
		{
			IResponse response = new HtmlFragmentResponse("foo");
			// Setup
			cruiseRequestMock.ExpectAndReturn("ProjectName", "");
			errorViewBuilderMock.ExpectAndReturn("BuildView", response, new IsTypeOf(typeof(string)));
			proxiedActionMock.ExpectNoCall("Execute", typeof(ICruiseRequest));

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

			// Verify
			Assert.AreEqual(response, returnedResponse);
			VerifyAll();
		}
		public void ShouldProxyIfProjectPresent()
		{
			IResponse response = new HtmlFragmentResponse("foo");
			// Setup
			cruiseRequestMock.ExpectAndReturn("ProjectName", "myProject");
			errorViewBuilderMock.ExpectNoCall("BuildView", typeof(string));
			proxiedActionMock.ExpectAndReturn("Execute", response, cruiseRequest);

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

			// Verify
			Assert.AreEqual(response, returnedResponse);
			VerifyAll();
		}
		public void ShouldGetCruiseRequestForRequestAndProxyAction()
		{
			IResponse response = new HtmlFragmentResponse("foo");
			// Setup
			cruiseRequestFactoryMock.ExpectAndReturn("CreateCruiseRequest", cruiseRequest, request,
                (ICruiseUrlBuilder)urlBuilderMock.MockInstance, null);
			proxiedActionMock.ExpectAndReturn("Execute", response, cruiseRequest);

			// Execute
			IResponse returnedResponse = proxy.Execute(request);

			// Verify
			Assert.AreEqual(response, returnedResponse);
			VerifyAll();
		}
		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();
		}
Пример #9
0
		public void ShouldGiveHtmlFragmentIfStringConstructorUsed()
		{
			HtmlFragmentResponse responseFragment = new HtmlFragmentResponse("Some HTML");

			Assert.AreEqual("Some HTML", responseFragment.ResponseFragment );
		}
		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 ShouldBuildViewForAllBuilds()
		{
			IBuildSpecifier[] buildSpecifiers = new IBuildSpecifier [] {build2Specifier, build1Specifier };
			IAbsoluteLink[] buildLinks = new IAbsoluteLink[] { new GeneralAbsoluteLink("link1"), new GeneralAbsoluteLink("link2") };
			string buildRows = "renderred Links";
			IResponse allBuildsResponse = new HtmlFragmentResponse("foo");
			Hashtable context1 = new Hashtable();
			Hashtable context2 = new Hashtable();

			farmServiceMock.ExpectAndReturn("GetBuildSpecifiers", new IBuildSpecifier [] { build2Specifier, build1Specifier }, projectSpecifier, null);
			linkListFactoryMock.ExpectAndReturn("CreateStyledBuildLinkList", buildLinks, buildSpecifiers, BuildReportBuildPlugin.ACTION_NAME);
			context1["links"] = buildLinks;
			velocityTransformerMock.ExpectAndReturn("Transform", buildRows, @"BuildRows.vm", new HashtableConstraint(context1));

			context2["buildRows"] = buildRows;
			IAbsoluteLink allBuildsLink = new GeneralAbsoluteLink("foo");
			linkFactoryMock.ExpectAndReturn("CreateProjectLink", allBuildsLink, projectSpecifier, "", ViewAllBuildsProjectPlugin.ACTION_NAME);
			context2["allBuildsLink"] = allBuildsLink;
			velocityViewGeneratorMock.ExpectAndReturn("GenerateView", allBuildsResponse, @"AllBuilds.vm", new HashtableConstraint(context2));

			Assert.AreEqual(allBuildsResponse, lister.GenerateAllBuildsView(projectSpecifier, null));

			VerifyAll();
		}