MultiSourceControlTest.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » UnitTests » Core » Sourcecontrol » 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 » Core » Sourcecontrol » MultiSourceControlTest.cs
using System;
using System.Collections;
using Exortech.NetReflector;
using NMock;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Core;
using ThoughtWorks.CruiseControl.Core.Sourcecontrol;

namespace ThoughtWorks.CruiseControl.UnitTests.Core.Sourcecontrol{
  [TestFixture]
  public class MultiSourceControlTest : CustomAssertion
  {
    public static string SourceControlXml = @"<sourcecontrol type=""multi"">
  <sourceControls>
    <mocksourcecontrol>
      <anOptionalProperty>foo</anOptionalProperty>
    </mocksourcecontrol>
    <mocksourcecontrol>
      <anOptionalProperty>bar</anOptionalProperty>
    </mocksourcecontrol>
  </sourceControls>
</sourcecontrol>
";

    [Test]
    public void ValuePopulation()
    {
      //// SETUP
      MultiSourceControl multiSourceControl = new MultiSourceControl();

      //// EXECUTE
      NetReflector.Read(SourceControlXml, multiSourceControl);

      //// VERIFY
      Assert.IsTrue(multiSourceControl.SourceControls.Length == 2);

      string optionalProp0 = ((SourceControlMock) multiSourceControl.SourceControls[0]).AnOptionalProperty;
      string optionalProp1 = ((SourceControlMock) multiSourceControl.SourceControls[1]).AnOptionalProperty;

      bool fooFound = optionalProp0 == "foo" || optionalProp1 == "foo";
      bool barFound = optionalProp0 == "bar" || optionalProp1 == "bar";

      Assert.IsTrue(fooFound && barFound);
    }

    [Test]
    public void PassesThroughLabelSourceControl()
    {
      //// SETUP
      IntegrationResult result = new IntegrationResult();

      DynamicMock mockSC1 = new DynamicMock(typeof (ISourceControl));
      mockSC1.Expect("LabelSourceControl", result);

      DynamicMock mockSC2 = new DynamicMock(typeof (ISourceControl));
      mockSC2.Expect("LabelSourceControl", result);

      ISourceControl[] sourceControls = new ISourceControl[] {(ISourceControl) mockSC1.MockInstance, (ISourceControl) mockSC2.MockInstance};

      MultiSourceControl multiSourceControl = new MultiSourceControl();
      multiSourceControl.SourceControls = sourceControls;

      //// EXECUTE
      multiSourceControl.LabelSourceControl(result);

      //// VERIFY
      mockSC1.Verify();
      mockSC2.Verify();
    }

    [Test]
    public void PassesThroughGetSourceControlAndCombinesResults()
    {
      //// SETUP
      IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
      IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));

      Modification mod1 = new Modification();
      mod1.Comment = "Testing Multi";
      Modification mod2 = new Modification();
      mod2.Comment = "More Multi";
      Modification mod3 = new Modification();
      mod3.Comment = "Yet More Multi";

      ArrayList mocks = new ArrayList();
      mocks.Add(CreateModificationsSourceControlMock(new Modification[] {mod1, mod2}, from, to));
      mocks.Add(CreateModificationsSourceControlMock(new Modification[] {mod3}, from, to));
      mocks.Add(CreateModificationsSourceControlMock(new Modification[0], from, to));
      mocks.Add(CreateModificationsSourceControlMock(null, from, to));

      ArrayList scList = new ArrayList();
      foreach (DynamicMock mock in mocks)
      {
        scList.Add(mock.MockInstance);
      }

      MultiSourceControl multiSourceControl = new MultiSourceControl();
      multiSourceControl.SourceControls = (ISourceControl[]) scList.ToArray(typeof (ISourceControl));

      //// EXECUTE
      ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));

      //// VERIFY
      foreach (DynamicMock mock in mocks)
      {
        mock.Verify();
      }

      Assert.IsTrue(returnedMods.Contains(mod1));
      Assert.IsTrue(returnedMods.Contains(mod2));
      Assert.IsTrue(returnedMods.Contains(mod3));
    }

    [Test]
    public void ShouldInstructAggregatedSourceControlsToGetSource()
    {
      IntegrationResult result = new IntegrationResult();
      IMock mockSC1 = new DynamicMock(typeof (ISourceControl));
      IMock mockSC2 = new DynamicMock(typeof (ISourceControl));
      mockSC1.Expect("GetSource", result);
      mockSC2.Expect("GetSource", result);

      MultiSourceControl multiSourceControl = new MultiSourceControl();
      multiSourceControl.SourceControls = new ISourceControl[] {(ISourceControl) mockSC1.MockInstance, (ISourceControl) mockSC2.MockInstance};
      multiSourceControl.GetSource(result);

      mockSC1.Verify();
      mockSC2.Verify();
    }

    private DynamicMock CreateModificationsSourceControlMock(Modification[] mods, IntegrationResult dt1, IntegrationResult dt2)
    {
      DynamicMock mock = new DynamicMock(typeof (ISourceControl));
      mock.ExpectAndReturn("GetModifications", mods, dt1, dt2);
      return mock;
    }

    
    [Test]
    public void IfRequireChangesFromAllTrueAndAllSourceControlHasModificationsThenReturnMods()
    {
      //// SETUP
      IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
      IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));

      Modification mod1 = new Modification();
      mod1.Comment = "Testing Multi";
      Modification mod2 = new Modification();
      mod2.Comment = "Testing Multi";

      ArrayList mocks = new ArrayList();
      mocks.Add(CreateModificationsSourceControlMock(new Modification[] {mod1}, from, to));
      mocks.Add(CreateModificationsSourceControlMock(new Modification[] {mod2}, from, to));

      ArrayList scList = new ArrayList();
      foreach (DynamicMock mock in mocks)
      {
        scList.Add(mock.MockInstance);
      }

      MultiSourceControl multiSourceControl = new MultiSourceControl();
      multiSourceControl.SourceControls = (ISourceControl[]) scList.ToArray(typeof (ISourceControl));
      multiSourceControl.RequireChangesFromAll = true;

      //// EXECUTE
      ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));
      Assert.AreEqual(1, returnedMods.Count);

      //// VERIFY
      foreach (DynamicMock mock in mocks)
      {
        mock.Verify();
      }
    }
    
    [Test]
    public void IfRequireChangesFromAllTrueAndSecondSourceControlHasEmptyChangesThenReturnEmpty()
    {
      //// SETUP
      IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
      IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));

      Modification mod1 = new Modification();
      mod1.Comment = "Testing Multi";

      ArrayList mocks = new ArrayList();
      mocks.Add(CreateModificationsSourceControlMock(new Modification[] {mod1}, from, to));
      mocks.Add(CreateModificationsSourceControlMock(new Modification[0], from, to));

      ArrayList scList = new ArrayList();
      foreach (DynamicMock mock in mocks)
      {
        scList.Add(mock.MockInstance);
      }

      MultiSourceControl multiSourceControl = new MultiSourceControl();
      multiSourceControl.SourceControls = (ISourceControl[]) scList.ToArray(typeof (ISourceControl));
      multiSourceControl.RequireChangesFromAll = true;

      //// EXECUTE
      ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));

      //// VERIFY
      foreach (DynamicMock mock in mocks)
      {
        mock.Verify();
      }

      Assert.AreEqual(0, returnedMods.Count);
    }

    [Test]
    public void IfRequireChangesFromAllTrueAndFirstSourceControlHasEmptyChangesThenReturnEmpty()
    {
      //// SETUP
      IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
      IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));

      Modification mod1 = new Modification();
      mod1.Comment = "Testing Multi";

      ArrayList mocks = new ArrayList();
      mocks.Add(CreateModificationsSourceControlMock(new Modification[0], from, to));
      DynamicMock nonCalledMock = new DynamicMock(typeof (ISourceControl));
      nonCalledMock.ExpectNoCall("GetModifications", typeof(IIntegrationResult), typeof(IIntegrationResult));
      mocks.Add(nonCalledMock);

      ArrayList scList = new ArrayList();
      foreach (DynamicMock mock in mocks)
      {
        scList.Add(mock.MockInstance);
      }

      MultiSourceControl multiSourceControl = new MultiSourceControl();
      multiSourceControl.SourceControls = (ISourceControl[]) scList.ToArray(typeof (ISourceControl));
      multiSourceControl.RequireChangesFromAll = true;

      //// EXECUTE
      ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));

      //// VERIFY
      foreach (DynamicMock mock in mocks)
      {
        mock.Verify();
      }

      Assert.AreEqual(0, returnedMods.Count);
    }

    [Test]
    public void IfRequireChangesFromAllTrueAndNoSourceControlHasEmptyChangesThenReturnChanges()
    {
      //// SETUP
      IntegrationResult from = IntegrationResultMother.CreateSuccessful(DateTime.Now);
      IntegrationResult to = IntegrationResultMother.CreateSuccessful(DateTime.Now.AddDays(10));

      Modification mod1 = new Modification();
      mod1.Comment = "Testing Multi";
      Modification mod2 = new Modification();
      mod2.Comment = "More Multi";
      Modification mod3 = new Modification();
      mod3.Comment = "Yet More Multi";

      ArrayList mocks = new ArrayList();
      mocks.Add(CreateModificationsSourceControlMock(new Modification[] {mod1, mod2}, from, to));
      mocks.Add(CreateModificationsSourceControlMock(new Modification[] {mod3}, from, to));

      ArrayList scList = new ArrayList();
      foreach (DynamicMock mock in mocks)
      {
        scList.Add(mock.MockInstance);
      }

      MultiSourceControl multiSourceControl = new MultiSourceControl();
      multiSourceControl.RequireChangesFromAll = true;
      multiSourceControl.SourceControls = (ISourceControl[]) scList.ToArray(typeof (ISourceControl));

      //// EXECUTE
      ArrayList returnedMods = new ArrayList(multiSourceControl.GetModifications(from, to));

      //// VERIFY
      foreach (DynamicMock mock in mocks)
      {
        mock.Verify();
      }

      Assert.IsTrue(returnedMods.Contains(mod1));
      Assert.IsTrue(returnedMods.Contains(mod2));
      Assert.IsTrue(returnedMods.Contains(mod3));
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.