SideBarViewBuilderTest.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » UnitTests » WebDashboard » Dashboard » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » UnitTests » WebDashboard » Dashboard » SideBarViewBuilderTest.cs
using System;
using System.Collections;
using NMock;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Core.Reporting.Dashboard.Navigation;
using ThoughtWorks.CruiseControl.Remote;
using ThoughtWorks.CruiseControl.UnitTests.UnitTestUtils;
using ThoughtWorks.CruiseControl.WebDashboard.Dashboard;
using ThoughtWorks.CruiseControl.WebDashboard.IO;
using ThoughtWorks.CruiseControl.WebDashboard.MVC;
using ThoughtWorks.CruiseControl.WebDashboard.MVC.View;
using ThoughtWorks.CruiseControl.WebDashboard.Plugins.BuildReport;
using ThoughtWorks.CruiseControl.WebDashboard.Plugins.ServerReport;
using ThoughtWorks.CruiseControl.WebDashboard.ServerConnection;
using ThoughtWorks.CruiseControl.WebDashboard.Plugins.FarmReport;

namespace ThoughtWorks.CruiseControl.UnitTests.WebDashboard.Dashboard{
  [TestFixture]
  public class SideBarViewBuilderTest
  {
    private DynamicMock cruiseRequestWrapperMock;
    private DynamicMock buildNameRetrieverMock;
    private DynamicMock recentBuildsViewBuilderMock;
    private DynamicMock pluginLinkCalculatorMock;
    private DynamicMock velocityViewGeneratorMock;
    private DynamicMock linkFactoryMock;
    private DynamicMock linkListFactoryMock;
    private DynamicMock farmServiceMock;

    private SideBarViewBuilder sideBarViewBuilder;

    private IResponse velocityResponse;
    private Hashtable velocityContext;
    private IAbsoluteLink[] links;
    private IAbsoluteLink[] serverLinks;
    private IServerSpecifier[] serverSpecifiers;


    [SetUp]
    public void Setup()
    {
      cruiseRequestWrapperMock = new DynamicMock(typeof(ICruiseRequest));
      buildNameRetrieverMock = new DynamicMock(typeof(IBuildNameRetriever));
      recentBuildsViewBuilderMock = new DynamicMock(typeof(IRecentBuildsViewBuilder));
      pluginLinkCalculatorMock = new DynamicMock(typeof(IPluginLinkCalculator));
      velocityViewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator));
      linkFactoryMock = new DynamicMock(typeof(ILinkFactory));
      linkListFactoryMock = new DynamicMock(typeof(ILinkListFactory));
      farmServiceMock = new DynamicMock(typeof(IFarmService));


      sideBarViewBuilder = new SideBarViewBuilder(
        (ICruiseRequest) cruiseRequestWrapperMock.MockInstance,
        (IBuildNameRetriever) buildNameRetrieverMock.MockInstance,
        (IRecentBuildsViewBuilder) recentBuildsViewBuilderMock.MockInstance,
        (IPluginLinkCalculator) pluginLinkCalculatorMock.MockInstance,
        (IVelocityViewGenerator) velocityViewGeneratorMock.MockInstance,
        (ILinkFactory) linkFactoryMock.MockInstance,
        (ILinkListFactory)linkListFactoryMock.MockInstance,
        (IFarmService) farmServiceMock.MockInstance,
                null);

      velocityResponse = new HtmlFragmentResponse("velocity view");
      velocityContext = new Hashtable();
      links = new IAbsoluteLink[] { new GeneralAbsoluteLink("link")};
      serverLinks = new IAbsoluteLink[] { new GeneralAbsoluteLink("link")};
      serverSpecifiers = new IServerSpecifier[] {new DefaultServerSpecifier("test")};
    }
    
    private void VerifyAll()
    {
      cruiseRequestWrapperMock.Verify();
      buildNameRetrieverMock.Verify();
      recentBuildsViewBuilderMock.Verify();
      pluginLinkCalculatorMock.Verify();
      velocityViewGeneratorMock.Verify();
      linkFactoryMock.Verify();
      linkListFactoryMock.Verify();
      farmServiceMock.Verify();
    }

    [Test]
    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);
            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();
    }

    [Test]
    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();
    }

    [Test]
    public void ShouldGenerateProjectViewIfServerAndProjectButNoBuildSpecified()
    {
      // Setup
      IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
      cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "myServer");
      cruiseRequestWrapperMock.ExpectAndReturn("ProjectName", "myProject");
      cruiseRequestWrapperMock.ExpectAndReturn("BuildName", "");
      cruiseRequestWrapperMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);

      pluginLinkCalculatorMock.ExpectAndReturn("GetProjectPluginLinks", links, projectSpecifier);
      string recentBuildsView = "";
      recentBuildsViewBuilderMock.ExpectAndReturn("BuildRecentBuildsTable", recentBuildsView, projectSpecifier, null);

      velocityContext["links"] = links;
      velocityContext["recentBuildsTable"] = recentBuildsView;

      velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"ProjectSideBar.vm", new HashtableConstraint(velocityContext));

      // Execute
            HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest);

      // Verify
      Assert.AreEqual(velocityResponse, returnedResponse);
      VerifyAll();
    }

    [Test]
    public void ShouldGenerateBuildViewIfServerAndProjectAndBuildSpecified()
    {
      // Setup
      IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject");
      IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild");
      cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "myServer");
      cruiseRequestWrapperMock.ExpectAndReturn("ProjectName", "myProject");
      cruiseRequestWrapperMock.ExpectAndReturn("BuildName", "myBuild");
      cruiseRequestWrapperMock.ExpectAndReturn("BuildSpecifier", buildSpecifier);
      cruiseRequestWrapperMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);

      pluginLinkCalculatorMock.ExpectAndReturn("GetBuildPluginLinks", links, buildSpecifier);
      string recentBuildsView = "";
      recentBuildsViewBuilderMock.ExpectAndReturn("BuildRecentBuildsTable", recentBuildsView, buildSpecifier, null);

      IBuildSpecifier nextBuildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "next");
      IBuildSpecifier previousBuildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "previous");
      IAbsoluteLink latestLink = new GeneralAbsoluteLink("test latest");
      IAbsoluteLink nextLink = new GeneralAbsoluteLink("test next");
      IAbsoluteLink previousLink = new GeneralAbsoluteLink("test previous");

      buildNameRetrieverMock.ExpectAndReturn("GetNextBuildSpecifier", nextBuildSpecifier, buildSpecifier, null);
      buildNameRetrieverMock.ExpectAndReturn("GetPreviousBuildSpecifier", previousBuildSpecifier, buildSpecifier, null);

      string action = BuildReportBuildPlugin.ACTION_NAME;

      linkFactoryMock.ExpectAndReturn("CreateProjectLink", latestLink, projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME);
      linkFactoryMock.ExpectAndReturn("CreateBuildLink", nextLink, nextBuildSpecifier, "", action);
      linkFactoryMock.ExpectAndReturn("CreateBuildLink", previousLink, previousBuildSpecifier, "", action);

      velocityContext["links"] = links;
      velocityContext["recentBuildsTable"] = recentBuildsView;
      velocityContext["latestLink"] = latestLink;
      velocityContext["nextLink"] = nextLink;
      velocityContext["previousLink"] = previousLink;

      velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"BuildSideBar.vm", new HashtableConstraint(velocityContext));

      // Execute
      HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest);

      // Verify
      Assert.AreEqual(velocityResponse, returnedResponse);
      VerifyAll();
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.