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

namespace ThoughtWorks.CruiseControl.UnitTests.Core.Sourcecontrol{
    [TestFixture]
    public class RegExIssueTrackerUrlBuilderTest
    {
        const string ExpectedUrl = "http://jira.public.thoughtworks.org/browse/CCNET-5000";
        const string issueTrackerUrl = "http://jira.public.thoughtworks.org";


        //Assert position at the beginning of the string ^
        //Match any single character that is not a line break character .*
        //   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) *
        //Match the regular expression below and capture its match into backreference number 1 (CCNET-\d*)
        //   Match the characters CCNET- literally CCNET-
        //   Match a single digit 0..9 \d*
        //      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) *
        //Match any single character that is not a line break character .*
        //   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) *
        //Assert position at the end of the string (or before the line break at the end of the string, if any) $
        private string searchString = @"^.*(CCNET-\d*).*$";


        //replace with /browse/backreference1  $1
        private string replacementString = string.Format("{0}/browse/$1", issueTrackerUrl);


        private string CreateSourceControlXml()
        {
            return string.Format("<issueUrlBuilder type=\"regexIssueTracker\"><find>{0}</find><replace>{1}</replace></issueUrlBuilder>", searchString, replacementString);
        }


        private RegExIssueTrackerUrlBuilder CreateBuilder()
        {
            RegExIssueTrackerUrlBuilder regexIssue = new RegExIssueTrackerUrlBuilder();
            NetReflector.Read(CreateSourceControlXml(), regexIssue);
            return regexIssue;
        }


        [Test]
        public void ValuePopulation()
        {
            RegExIssueTrackerUrlBuilder regexIssue = CreateBuilder();

            Assert.AreEqual(searchString, regexIssue.Find);
            Assert.AreEqual(replacementString, regexIssue.Replace);
        }




        [Test]
        public void CommentWithProjectPrefixAndIssueNumberAndText()
        {
            Modification[] mods = new Modification[1];
            mods[0] = new Modification();
            mods[0].FolderName = "/trunk";
            mods[0].FileName = "nant.bat";
            mods[0].ChangeNumber = "3";
            mods[0].Comment = "CCNET-5000 blablabla";

            RegExIssueTrackerUrlBuilder regexIssue = CreateBuilder();
            regexIssue.SetupModification(mods);

            Assert.AreEqual(ExpectedUrl, mods[0].IssueUrl);
        }


        [Test]
        public void CommentWithProjectPrefixAndIssueNumber()
        {
            Modification[] mods = new Modification[1];
            mods[0] = new Modification();
            mods[0].FolderName = "/trunk";
            mods[0].FileName = "nant.bat";
            mods[0].ChangeNumber = "3";
            mods[0].Comment = "CCNET-5000";

            RegExIssueTrackerUrlBuilder regexIssue = CreateBuilder();
            regexIssue.SetupModification(mods);

            Assert.AreEqual(ExpectedUrl, mods[0].IssueUrl);
        }



        [Test]
        public void CommentWithPrefixAndProjectPrefixAndIssueNumber()
        {
            Modification[] mods = new Modification[1];
            mods[0] = new Modification();
            mods[0].FolderName = "/trunk";
            mods[0].FileName = "nant.bat";
            mods[0].ChangeNumber = "3";
            mods[0].Comment = "some random text CCNET-5000 and the issue description";

            RegExIssueTrackerUrlBuilder regexIssue = CreateBuilder();
            regexIssue.SetupModification(mods);

            Assert.AreEqual(ExpectedUrl, mods[0].IssueUrl);
        }


        [Test]
        public void CommentWithIssueNumberAndText()
        {
            Modification[] mods = new Modification[1];
            mods[0] = new Modification();
            mods[0].FolderName = "/trunk";
            mods[0].FileName = "nant.bat";
            mods[0].ChangeNumber = "3";
            mods[0].Comment = "5000 blablabla";

            RegExIssueTrackerUrlBuilder regexIssue = CreateBuilder();
            regexIssue.SetupModification(mods);

            Assert.IsNull(mods[0].IssueUrl);
        }

        [Test]
        public void CommentWithIssueNumberOnly()
        {
            Modification[] mods = new Modification[1];
            mods[0] = new Modification();
            mods[0].FolderName = "/trunk";
            mods[0].FileName = "nant.bat";
            mods[0].ChangeNumber = "3";
            mods[0].Comment = "5000";

            RegExIssueTrackerUrlBuilder regexIssue = CreateBuilder();
            regexIssue.SetupModification(mods);

            Assert.IsNull(mods[0].IssueUrl);
        }


        [Test]
        public void CommentWithTextOnly()
        {
            Modification[] mods = new Modification[1];
            mods[0] = new Modification();
            mods[0].FolderName = "/trunk";
            mods[0].FileName = "nant.bat";
            mods[0].ChangeNumber = "3";
            mods[0].Comment = "bla blabla bla bla";

            RegExIssueTrackerUrlBuilder regexIssue = CreateBuilder();
            regexIssue.SetupModification(mods);

            Assert.IsNull(mods[0].IssueUrl);
        }


        [Test]
        public void NoCommentAtAll()
        {
            Modification[] mods = new Modification[1];
            mods[0] = new Modification();
            mods[0].FolderName = "/trunk";
            mods[0].FileName = "nant.bat";
            mods[0].ChangeNumber = "3";
            mods[0].Comment =string.Empty;

            RegExIssueTrackerUrlBuilder regexIssue = CreateBuilder();
            regexIssue.SetupModification(mods);

            Assert.IsNull(mods[0].IssueUrl);
        }



        [Test,Ignore("CCNET 1589 can not get the test to work")]
        public void MultilineCommentFirstLineContainsBugIdNextContainLogMessage()
        {
            System.Text.StringBuilder commentBuilder = new System.Text.StringBuilder();

            commentBuilder.AppendLine("FS#1234");
            commentBuilder.AppendLine("fixed typo");

            Modification[] mods = new Modification[1];
            mods[0] = new Modification();
            mods[0].FolderName = "/trunk";
            mods[0].FileName = "nant.bat";
            mods[0].ChangeNumber = "3";
            mods[0].Comment = commentBuilder.ToString();


            RegExIssueTrackerUrlBuilder regexIssue = new RegExIssueTrackerUrlBuilder();
            regexIssue.Find = @"FS#(\d+)";
            regexIssue.Replace = @"http://flyspray.internal/index.php?do=details&task_id=$1";

            regexIssue.SetupModification(mods);

            Assert.AreEqual("http://flyspray.internal/index.php?do=details&task_id=1234", mods[0].IssueUrl);
        }



    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.