DefaultPluginLinkCalculatorTest.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 » DefaultPluginLinkCalculatorTest.cs
using NMock;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Core.Reporting.Dashboard.Navigation;
using ThoughtWorks.CruiseControl.WebDashboard.Configuration;
using ThoughtWorks.CruiseControl.WebDashboard.Dashboard;

namespace ThoughtWorks.CruiseControl.UnitTests.WebDashboard.Dashboard{
  [TestFixture]
  public class DefaultPluginLinkCalculatorTest
  {
    private string serverName = "my server";
    private string projectName = "my project";
    private string buildName = "my build";
    private DefaultPluginLinkCalculator Plugins;
    private DynamicMock linkFactoryMock;
    private DynamicMock configurationMock;
    private DefaultBuildSpecifier buildSpecifier;
    private IProjectSpecifier projectSpecifier;
    private DefaultServerSpecifier serverSpecifier;
    private DynamicMock pluginMock1;
    private DynamicMock pluginMock2;
    private INamedAction action1;
    private INamedAction action2;
    private INamedAction action3;
    private IAbsoluteLink link1;
    private IAbsoluteLink link2;

    [SetUp]
    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;
    }

    private void VerifyAll()
    {
      linkFactoryMock.Verify();
      configurationMock.Verify();
    }

    [Test]
    public void ShouldReturnBuildPluginLinksRelevantToThisProject()
    {
      DynamicMock buildPluginMock1 = new DynamicMock(typeof (IBuildPlugin));
      DynamicMock buildPluginMock2 = new DynamicMock(typeof (IBuildPlugin));
      DynamicMock buildPluginMock3 = new DynamicMock(typeof (IBuildPlugin));
      buildPluginMock1.SetupResult("LinkDescription", "Description 1");
      buildPluginMock1.SetupResult("NamedActions", new INamedAction[] {action1});
      buildPluginMock1.SetupResult("IsDisplayedForProject", true, typeof(IProjectSpecifier));
      buildPluginMock2.SetupResult("LinkDescription", "Description 2");
      buildPluginMock2.SetupResult("NamedActions", new INamedAction[] {action2});
      buildPluginMock2.SetupResult("IsDisplayedForProject", true, typeof(IProjectSpecifier));
      buildPluginMock3.SetupResult("IsDisplayedForProject", false, typeof(IProjectSpecifier));

      configurationMock.ExpectAndReturn("BuildPlugins", new IBuildPlugin[]
        {
          (IBuildPlugin) buildPluginMock1.MockInstance, (IBuildPlugin) buildPluginMock2.MockInstance, (IBuildPlugin) buildPluginMock3.MockInstance
        });
      linkFactoryMock.ExpectAndReturn("CreateBuildLink", link1, buildSpecifier, "Description 1", "Action Name 1");
      linkFactoryMock.ExpectAndReturn("CreateBuildLink", link2, buildSpecifier, "Description 2", "Action Name 2");

      IAbsoluteLink[] buildLinks = Plugins.GetBuildPluginLinks(buildSpecifier);

      Assert.AreSame(link1, buildLinks[0]);
      Assert.AreSame(link2, buildLinks[1]);
      Assert.AreEqual(2, buildLinks.Length);
      VerifyAll();
    }

    [Test]
    public void ShouldReturnServerPluginLinksByQueryingConfiguration()
    {
      configurationMock.ExpectAndReturn("ServerPlugins", new IPlugin[] {(IPlugin) pluginMock1.MockInstance, (IPlugin) pluginMock2.MockInstance});
      linkFactoryMock.ExpectAndReturn("CreateServerLink", link1, serverSpecifier, "Description 1", "Action Name 1");
      linkFactoryMock.ExpectAndReturn("CreateServerLink", link2, serverSpecifier, "Description 2", "Action Name 2");

      IAbsoluteLink[] buildLinks = Plugins.GetServerPluginLinks(serverSpecifier);

      Assert.AreSame(link1, buildLinks[0]);
      Assert.AreSame(link2, buildLinks[1]);
      Assert.AreEqual(2, buildLinks.Length);
      VerifyAll();
    }

    [Test]
    public void ShouldReturnFarmPluginLinksByQueryingConfiguration()
    {
      configurationMock.ExpectAndReturn("FarmPlugins", new IPlugin[] {(IPlugin) pluginMock1.MockInstance, (IPlugin) pluginMock2.MockInstance});
      linkFactoryMock.ExpectAndReturn("CreateFarmLink", link1, "Description 1", "Action Name 1");
      linkFactoryMock.ExpectAndReturn("CreateFarmLink", link2, "Description 2", "Action Name 2");

      IAbsoluteLink[] buildLinks = Plugins.GetFarmPluginLinks();

      Assert.AreSame(link1, buildLinks[0]);
      Assert.AreSame(link2, buildLinks[1]);
      Assert.AreEqual(2, buildLinks.Length);
      VerifyAll();
    }

    [Test]
    public void ShouldReturnProjectPluginLinksByQueryingConfiguration()
    {
      configurationMock.ExpectAndReturn("ProjectPlugins", new IPlugin[] {(IPlugin) pluginMock1.MockInstance, (IPlugin) pluginMock2.MockInstance});
      linkFactoryMock.ExpectAndReturn("CreateProjectLink", link1, projectSpecifier, "Description 1", "Action Name 1");
      linkFactoryMock.ExpectAndReturn("CreateProjectLink", link2, projectSpecifier, "Description 2", "Action Name 2");

      IAbsoluteLink[] buildLinks = Plugins.GetProjectPluginLinks(projectSpecifier);

      Assert.AreSame(link1, buildLinks[0]);
      Assert.AreSame(link2, buildLinks[1]);
      Assert.AreEqual(2, buildLinks.Length);
      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.