コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }