PathFilterTest.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 » PathFilterTest.cs
using Exortech.NetReflector;
using NUnit.Framework;
using ThoughtWorks.CruiseControl.Core;
using ThoughtWorks.CruiseControl.Core.Sourcecontrol;
using System;

namespace ThoughtWorks.CruiseControl.UnitTests.Core.Sourcecontrol{
    [TestFixture]
  public class PathFilterTest
  {
    [Test]
    public void ExactFileNameMatch()
    {
      ExactFileNameTestSet.RunTests();
    }

    [Test]
    public void AnyFileNameMatch()
    {
      AnyFileNameTestSet.RunTests();
    }

    [Test]
    public void ExactFolderAnyNameMatch()
    {
      ExactFolderAnyNameTestSet.RunTests();
    }

    [Test]
    public void AnyFolderExactNameMatch()
    {
      AnyFolderExactNameTestSet.RunTests();
    }

    [Test]
    public void ExactSubfolderAnyNameMatch()
    {
      ExactSubfolderAnyNameTestSet.RunTests();
    }

    [Test]
    public void AcceptAllMatch()
    {
      AcceptAllTestSet.RunTests();
    }

    [Test]
    public void PartialNameMatch() 
    {
      PartialNameTestSet.RunTests();
    }

    [Test]
    public void AnyFolderExactExtensionMatch()
    {
      AnyFolderExactExtensionTestSet.RunTests();
    }

    [Test]
    public void PartialFolderAnyNameMatch() 
    {
      PartialFolderAnyNameTestSet.RunTests();
    }

    [Test]
    public void AnyFolderPartialExtensionMatch()
    {
      AnyFolderPartialExtentsionTestSet.RunTests();
    }

    [Test]
    public void PartialPathAnyNameMatch() 
    {
      PartialPathAnyNameTestSet.RunTests();
    }

    [Test]
    public void ShouldNotAcceptModificationsWithNullFolder()
    {
      Modification modification = new Modification();
      PathFilter filter = new PathFilter();
      filter.Pattern = "*.*";
      Assert.IsFalse(filter.Accept(modification));
    }

    [Test]
    public void ShouldNotAcceptModificationsWithNullFilename()
    {
      Modification modification = new Modification();
      modification.FolderName = "c:\\";
      PathFilter filter = new PathFilter();
      filter.Pattern = "c:\\*.*";
      Assert.IsFalse(filter.Accept(modification));
    }
      
      [Test]
      public void DeeplyNestedFilters()
      {
            Modification[] modlist = new Modification[]
                {
                    ModificationMother.CreateModification("x.cs", "/working/sources"),
                    ModificationMother.CreateModification("Entries", "/working/sources/CVS"),
                    ModificationMother.CreateModification("x.build", "/working/build"),
                    ModificationMother.CreateModification("x.dll", "/working/build/target/sources")                 
                };
          PathFilter filter = new PathFilter();
          filter.Pattern = "**/sources/**/*.*";
          filter.Accept(modlist[0]);
        }

        [Test]
        public void TwicePartialPathAnyNameMatch()
        {
            TwicePartialPathAnyNameTestSet.RunTests();
        }

        [Test]
        public void CaseSensitivityTest()
        {
            Modification m = ModificationMother.CreateModification("x.xml", "/working/sources");
            PathFilter filter = new PathFilter();            
            filter.Pattern = "**/*.xml";
            Assert.IsTrue(filter.Accept(m));
            m.FileName = "test.Xml";
            Assert.IsFalse(filter.Accept(m));
            filter.CaseSensitive = false;
            Assert.IsTrue(filter.Accept(m));
        }
    private static Modification[] Modifications = 
      {
        ModificationMother.CreateModification("theName.dat",string.Empty),
        ModificationMother.CreateModification("TheName.dat",string.Empty),
        ModificationMother.CreateModification("theName.dat", "/theFolder"),
        ModificationMother.CreateModification("theFile.bin",string.Empty),
        ModificationMother.CreateModification("theFile.bin", "/theFolder"),
        ModificationMother.CreateModification("theName.dat", "/TheFolder"),
        ModificationMother.CreateModification("theName.dat", "/theFolder/theSubFolder"),
        ModificationMother.CreateModification("theName.dat", "/theFolder/theSubFolder/theSubSubFolder"),
        ModificationMother.CreateModification("theName.dat", "/theFolder/theSubFolder/theSubFolder"),
        ModificationMother.CreateModification("theName.dat", "/theFolder/theSubFolder/ThesubFolder"),
        ModificationMother.CreateModification("theName",string.Empty),
        ModificationMother.CreateModification("theName", "/theFolder/theSubFolder"),
        ModificationMother.CreateModification("theName.dav", "\\theFolder\\theSubFolder"),
        ModificationMother.CreateModification("theName.dav", "\\theFolder")
      };

    public static readonly string ExactFileNameFilterXml =
      @"<pathFilter>
                  <pattern>theName.dat</pattern>
              </pathFilter>";

    public static readonly PathFilterTestHelper ExactFileNameTestSet =
      new PathFilterTestHelper(
      ExactFileNameFilterXml, 
      Modifications, 
      new bool[] {true, false, false, false, false, 
               false, false, false, false, false, 
               false, false, false, false});

    public static readonly string AnyFileNameFilterXml =
      @"<pathFilter>
            <pattern>*.*</pattern>
              </pathFilter>";

    public static readonly PathFilterTestHelper AnyFileNameTestSet =
      new PathFilterTestHelper(
      AnyFileNameFilterXml,
      Modifications,
      new bool[] {true, true, false, true, false, 
               false, false, false, false, false, 
               true, false, false, false});

    public static string ExactFolderAnyNameFilterXml =
      @"<pathFilter>
                  <pattern>/theFolder/*.*</pattern>
              </pathFilter>";

    public static readonly PathFilterTestHelper ExactFolderAnyNameTestSet =
      new PathFilterTestHelper(
      ExactFolderAnyNameFilterXml,
      Modifications,
      new bool[] {false, false, true, false, true, 
               false, false, false, false, false, 
               false, false, false, true});

    public static string AnyFolderExactNameFilterXml =
      @"<pathFilter>
                  <pattern>**/theName.dat</pattern>
              </pathFilter>";

    public static readonly PathFilterTestHelper AnyFolderExactNameTestSet =
      new PathFilterTestHelper(
      AnyFolderExactNameFilterXml,
      Modifications,
      new bool[] {true, false, true, false, false, 
               true, true, true, true, true, 
               false, false, false, false});

    public static string ExactSubfolderAnyNameFilterXml = 
      @"<pathFilter>
                  <pattern>**/theSubFolder/*.*</pattern>
              </pathFilter>";

    public static readonly PathFilterTestHelper ExactSubfolderAnyNameTestSet =
      new PathFilterTestHelper(
      ExactSubfolderAnyNameFilterXml,
      Modifications,
      new bool[] {false, false, false, false, false, 
               false, true, false, true, false, 
               false, true, true, false});

    public static string AcceptAllFilterXml =
      @"<pathFilter>
                  <pattern>**/*.*</pattern>
              </pathFilter>"; 

    public static readonly PathFilterTestHelper AcceptAllTestSet =
      new PathFilterTestHelper(
      AcceptAllFilterXml,
      Modifications,
      new bool[] {true, true, true, true, true, 
               true, true, true, true, true, 
               true, true, true, true});

    public static string PartialNameFilterXml =
      @"<pathFilter>
                  <pattern>**/the*.dat</pattern>
              </pathFilter>";

    public static readonly PathFilterTestHelper PartialNameTestSet =
      new PathFilterTestHelper(
      PartialNameFilterXml,
      Modifications,
      new bool[] {true, false, true, false, false, 
               true, true, true, true, true, 
               false, false, false, false});

    public static string AnyFolderExactExtensionFilterXml =
      @"<pathFilter>
                  <pattern>**/*.bin</pattern>
              </pathFilter>";

    public static readonly PathFilterTestHelper AnyFolderExactExtensionTestSet =
      new PathFilterTestHelper(
      AnyFolderExactExtensionFilterXml,
      Modifications,
      new bool[] {false, false, false, true, true, 
               false, false, false, false, false, 
               false, false, false, false});

    public static string PartialFolderAnyNameFilterXml =
      @"<pathFilter>
                  <pattern>**/the*Folder/*.*</pattern>
              </pathFilter>";

    public static readonly PathFilterTestHelper PartialFolderAnyNameTestSet =
      new PathFilterTestHelper(
      PartialFolderAnyNameFilterXml,
      Modifications,
      new bool[] {false, false, true, false, true, 
               false, true, true, true, false, 
               false, true, true, true});

    public static string AnyFolderPartialExtensionFilterXml =
      @"<pathFilter>
                  <pattern>**/*.da*</pattern>
              </pathFilter>";

    public static PathFilterTestHelper AnyFolderPartialExtentsionTestSet =
      new PathFilterTestHelper(
      AnyFolderPartialExtensionFilterXml,
      Modifications,
      new bool[] {true, true, true, false, false,
               true, true, true, true, true,
               false, false, true, true});

    public static string PartialPathAnyNameFilterXml =
      @"<pathFilter>
                  <pattern>/theFolder/**/*.*</pattern>
              </pathFilter>";

    public static PathFilterTestHelper PartialPathAnyNameTestSet =
      new PathFilterTestHelper(
      PartialPathAnyNameFilterXml,
      Modifications,
      new bool[] {false, false, true, false, true,
               false, true, true, true, true,
               false, true, true, true});

        public static string TwicePartialPathAnyNameFilterXml =
    @"<pathFilter>
        <pattern>**/theSubFolder/**/*.*</pattern>
      </pathFilter>";

        public static PathFilterTestHelper TwicePartialPathAnyNameTestSet =
            new PathFilterTestHelper(
              TwicePartialPathAnyNameFilterXml,
              Modifications,
              new bool[] {false, false, false, false, false,
                            false, true , true , true , true ,
                            false, true , true , false});
  }

  public class PathFilterTestHelper 
  {
    private PathFilter filter;
    private Modification[] modifications;
    private bool[] expectedResults;

    public PathFilterTestHelper(string xmlFragment,
      Modification[] modifications,
      bool[] expectedResults) 
    {
      filter = new PathFilter();
      NetReflector.Read(xmlFragment, filter);

      this.modifications = modifications;
      this.expectedResults = expectedResults;
    }

    public void RunTests() 
    {
      int i = 0;

      foreach (Modification m in modifications) 
      {
        Assert.IsTrue(filter.Accept(m) == expectedResults[i], 
          DescribeExpectedResult(m, expectedResults[i]));
        i++;
      }
    }

    private string DescribeExpectedResult(
      Modification m,
      bool expectedResult) 
    {
      return string.Format("{0}/{1} should be {2}.",
        m.FolderName,
        m.FileName,
        expectedResult ? "accepted" : "rejected");
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.