public void SetupModification(Modification[] modifications)
 {
     foreach (Modification mod in modifications)
     {
         mod.Url = String.Format(_url, mod.FolderName.Length == 0 ? mod.FileName : mod.FolderName + "/" + mod.FileName);
     }
 }
        public Modification[] Parse(TextReader history, DateTime from, DateTime to)
        {
            var modifications = new List<Modification>();
            var document = XDocument.Load(history);
            var fromDate = from.ToString("s");
            var toDate = to.ToString("s");
            foreach (XElement change in document.Descendants("change"))
            {
                var date = DateTime.Parse(
                    change.Attribute("date").Value);
                if ((date >= from) &&
                    (date <= to))
                {
                    var modification = new Modification
                    {
                        FileName = change.Attribute("file").Value,
                        ModifiedTime = date,
                        FolderName = change.Attribute("folder").Value,
                        Type = change.Attribute("type").Value
                    };
                    modifications.Add(modification);
                }
            }

            return modifications.ToArray();
        }
		public void ShouldNotAcceptModificationsWithNullFolder()
		{
			Modification modification = new Modification();
			PathFilter filter = new PathFilter();
			filter.Pattern = "*.*";
			Assert.IsFalse(filter.Accept(modification));
		}
		public void ShouldCheckModificationsUntilThereAreNoModsInModificationDelay()
		{
			quietPeriod.ModificationDelaySeconds = 45;		

			// last build was at 12:01:00, current build is at 12:02:00
			
			// with a modification just at 12:01:30...
			Modification[] newMods = new Modification[] { CreateModificationAtTime(12, 01, 30) };
			
			// ...should wait for 15 seconds so that the 45 second delay completes (at 12:02:15)
			mockSourceControl.ExpectAndReturn("GetModifications", newMods, lastBuild, thisBuild);
			mockDateTimeProvider.Expect("Sleep", TimeSpan.FromSeconds(15));
			mockDateTimeProvider.ExpectAndReturn("Now", CreateDateTime(12, 02, 15));

			// After this time it should ask for modifications again.  Introduce a new modification at 12:02:10, meaning that the ealiest a build can start is at 12:02:55
			//  i.e. 40 seconds from the time of the current build (12:02:15)
			newMods = new Modification[] {newMods[0], CreateModificationAtTime(12, 02, 10)};		
			mockSourceControl.ExpectAndReturn("GetModifications", newMods, lastBuild, IntegrationResultMother.CreateSuccessful(CreateDateTime(12, 02, 15)));
			mockDateTimeProvider.Expect("Sleep", TimeSpan.FromSeconds(40));
			mockDateTimeProvider.ExpectAndReturn("Now", CreateDateTime(12, 02, 55));
			mockSourceControl.ExpectAndReturn("GetModifications", newMods, lastBuild, IntegrationResultMother.CreateSuccessful(CreateDateTime(12, 02, 55)));

			Modification[] actualMods = quietPeriod.GetModifications((ISourceControl) mockSourceControl.MockInstance, lastBuild, thisBuild);

			Assert.AreEqual(newMods, actualMods);
		}
		public void ShouldRejectModificationsWithNullComments()
		{
			Modification modification = new Modification();
            CommentFilter filter = new CommentFilter();
			filter.Pattern = ".*";
			Assert.IsFalse(filter.Accept(modification), "Should not have matched but did.");
		}
		public void ShouldFilterSpecifiedAction()
		{
			Modification mod = new Modification();
			mod.Type = "Created";

			filter.Actions = new string[] {"Created"};
			Assert.IsTrue(filter.Accept(mod), "Action not filtered");
		}
		public void ShouldFilterSpecifiedUser()
		{
			Modification mod = new Modification();
			mod.UserName = "******";

			filter.UserNames = new string[] { "bob" };
			Assert.IsTrue(filter.Accept(mod));
		}
 public void ShouldRejectModificationsWithMatchingComments()
 {
     Modification modification = new Modification();
     modification.Comment = "This is a comment.";
     CommentFilter filter = new CommentFilter();
     filter.Pattern = ".* is not a .*";
     Assert.IsFalse(filter.Accept(modification), "Should not have matched but did.");
 }
		public void GetModificationsDoesNotCreateLabelWhenThereAreNoModifications()
		{
			ProcessResult result = new ProcessResult("",string.Empty, 0, false);
			Modification[] emptyArray = new Modification[0];
			_historyParser.SetupResult("Parse", emptyArray, typeof(TextReader), typeof(DateTime), typeof(DateTime));
			_executor.ExpectAndReturn("Execute", result, new IsTypeOf(typeof(ProcessInfo)));
			_executor.ExpectNoCall("Execute", typeof(ProcessInfo));

			_vss.GetModifications(IntegrationResultMother.CreateSuccessful(DateTime.Now), IntegrationResultMother.CreateSuccessful(DateTime.Now));
		}
		public void ParseUsernameAndUKDate()
		{
			Modification mod = new Modification();
			string line = "foo\r\nUser: Admin        Date:  16/9/02   Time:  22:40\r\n";
            CheckInParser myParser = new CheckInParser(line, new VssLocale(new CultureInfo("en-GB")));
            myParser.ParseUsernameAndDate(mod);

			Assert.AreEqual("Admin", mod.UserName);
			Assert.AreEqual(new DateTime(2002, 9, 16, 22, 40, 0), mod.ModifiedTime);
		}
		public void CanAssignFileInfoWithNoPath()
		{
			const string file = "context.js";
			Modification modification = new Modification();

			parser.AssignFileInfo( modification, file );

			Assert.AreEqual( string.Empty, modification.FolderName );
			Assert.AreEqual( file, modification.FileName );
		}
        public AccuRevMotherWindows()
        {
            historyOutputReader = new StringReader(historyOutputDataWindows);

            /// The date ranges.
            oldestHistoryModification = DateTime.Parse("2006/11/22 11:10:44");
            newestHistoryModification = DateTime.Parse("2006/11/22 11:11:00");

            historyOutputModifications = new Modification[5];

            historyOutputModifications[0] = new Modification();
            historyOutputModifications[0].ChangeNumber = "12245";
            historyOutputModifications[0].Comment = "New Project for accessing SICS/nt web services";
            historyOutputModifications[0].FileName = "AssemblyInfo.cs";
            historyOutputModifications[0].FolderName = @"Dev\Server\Interface\Properties\";
            historyOutputModifications[0].ModifiedTime = new DateTime(2006,11,22,11,11,00);
            historyOutputModifications[0].Type = "add";
            historyOutputModifications[0].UserName = "******";

            historyOutputModifications[1] = new Modification();
            historyOutputModifications[1].ChangeNumber = "12244";
            historyOutputModifications[1].Comment = "New Project for accessing web services";
            historyOutputModifications[1].FileName = "Interface";
            historyOutputModifications[1].FolderName = @"Dev\Server\";
            historyOutputModifications[1].ModifiedTime = new DateTime(2006,11,22,11,10,44);
            historyOutputModifications[1].Type = "add";
            historyOutputModifications[1].UserName = "******";

            historyOutputModifications[2] = new Modification();
            historyOutputModifications[2].ChangeNumber = "12244";
            historyOutputModifications[2].Comment = "New Project for accessing web services";
            historyOutputModifications[2].FileName = "App.config";
            historyOutputModifications[2].FolderName = @"Dev\Server\Interface\";
            historyOutputModifications[2].ModifiedTime = new DateTime(2006, 11, 22, 11, 10, 44);
            historyOutputModifications[2].Type = "add";
            historyOutputModifications[2].UserName = "******";

            historyOutputModifications[3] = new Modification();
            historyOutputModifications[3].ChangeNumber = "12244";
            historyOutputModifications[3].Comment = "New Project for accessing web services";
            historyOutputModifications[3].FileName = "CommonTypes.cs";
            historyOutputModifications[3].FolderName = @"Dev\Server\Interface\";
            historyOutputModifications[3].ModifiedTime = new DateTime(2006, 11, 22, 11, 10, 44);
            historyOutputModifications[3].Type = "add";
            historyOutputModifications[3].UserName = "******";

            historyOutputModifications[4] = new Modification();
            historyOutputModifications[4].ChangeNumber = "12244";
            historyOutputModifications[4].Comment = "New Project for accessing web services";
            historyOutputModifications[4].FileName = "Connection.cs";
            historyOutputModifications[4].FolderName = @"Dev\Server\Interface\";
            historyOutputModifications[4].ModifiedTime = new DateTime(2006, 11, 22, 11, 10, 44);
            historyOutputModifications[4].Type = "add";
            historyOutputModifications[4].UserName = "******";
        }
		public void ShouldBuildValidUrls()
		{
			HgWebUrlBuilder hgweb = new HgWebUrlBuilder();
			hgweb.Url = "http://selenic.com/hg/index.cgi/";
			Modification[] modifications = new Modification[] {new Modification()};
			modifications[0].Version = "4a064e1977f8";
			hgweb.SetupModification(modifications);

			Assert.That(modifications[0].Url, Is.Not.Null);
			Assert.That(modifications[0].Url, Is.EqualTo("http://selenic.com/hg/index.cgi/rev/4a064e1977f8"));
		}
		protected Modification[] CreateModifications()
		{
			Modification[] testModifications = new Modification[]
				{
					new Modification(), new Modification(), new Modification()
				};
			testModifications[0].ChangeNumber = "100";
			testModifications[1].ChangeNumber = "2000";
			testModifications[2].ChangeNumber = "30000";
			return (testModifications);
		}
		private void AssertModification(Modification mod, int changeNumber, string revision, string file, string folder, DateTime modifiedTime, string type, string email, string username, string comment)
		{
			Assert.AreEqual(changeNumber.ToString(), mod.ChangeNumber);
			Assert.AreEqual(file, mod.FileName);
			Assert.AreEqual(folder, mod.FolderName);
			Assert.AreEqual(modifiedTime, mod.ModifiedTime);
			Assert.AreEqual(type, mod.Type);
			Assert.AreEqual(email, mod.EmailAddress);
			Assert.AreEqual(username, mod.UserName);
			Assert.AreEqual(comment, mod.Comment);
			Assert.AreEqual(revision, mod.Version);
		}
        public void ModificationsAreComparedByModifiedDatetime()
        {
            Modification alpha = new Modification();
            alpha.ModifiedTime = new DateTime(1975, 3, 3);

            Modification beta = new Modification();
            alpha.ModifiedTime = new DateTime(1961, 3, 3);

            Assert.IsTrue(alpha.CompareTo(beta) > 0, string.Format("expected alpha greater than beta {0}", alpha.CompareTo(beta)));
            Assert.IsTrue(alpha.CompareTo(alpha) == 0, string.Format("expected alpha-beta equality {0}", alpha.CompareTo(beta)));
            Assert.IsTrue(beta.CompareTo(alpha) < 0, string.Format("expected alpha less than beta {0}", alpha.CompareTo(beta)));
        }
		public void ParseUsernameAndUSDate()
		{
			Modification mod = new Modification();
			
			string line = "foo\r\nUser: Admin        Date:  9/16/02   Time:  2:40p\r\n";
			CheckInParser parser = new CheckInParser(line, new VssLocale(new CultureInfo("en-US")));
			parser.ParseUsernameAndDate(mod);
			string expectedUsername = "******";
			DateTime expectedDate = new DateTime(2002, 09, 16, 14, 40, 0);
			Assert.AreEqual(expectedUsername, mod.UserName);
			Assert.AreEqual(expectedDate, mod.ModifiedTime);
		}
        public void AppendModifications()
        {
            WorkflowResult result = new WorkflowResult();
            Modification mod1 = new Modification();
            Modification mod2 = new Modification();
            result.Modifications = new Modification[] { mod1 };
            result.Modifications = new Modification[] { mod2 };

            Assert.AreEqual(2, result.Modifications.Length);
            Assert.AreEqual(mod1, result.Modifications[0]);
            Assert.AreEqual(mod2, result.Modifications[1]);
        }
		public void CanAssignFileInfo()
		{
			const string path = @"D:\CCase\ppunjani_view\RefArch\tutorial\wwhdata\common";
			const string file = "context.js";
			const string fullPath = path + "\\" + file;
			Modification modification = new Modification();

			parser.AssignFileInfo( modification, fullPath );

			Assert.AreEqual( path, modification.FolderName );
			Assert.AreEqual( file, modification.FileName );
		}
        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);
        }
        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);
        }
        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";

            DefaultIssueTrackerUrlBuilder defaultIssue = CreateBuilder();
            defaultIssue.SetupModification(mods);

            string url = String.Format(UrlFromConfigFile, 5000);
            Assert.AreEqual(url, mods[0].IssueUrl);
        }
        public void ParseMemberInfo()
        {
            Modification modification = new Modification();
            MksHistoryParser parser = new MksHistoryParser();
            parser.ParseMemberInfoAndAddToModification(modification, new StringReader(MEMBER_INFO));

            DateTime modifiedTimeWithLocalTimeZone = DateTime.Parse("2009-10-16T18:07:08");
            DateTime modifiedTimeWithCorrectTimeZoneInformation = modification.ModifiedTime;
            TimeSpan actualOffsetAtModifiedTime = modifiedTimeWithCorrectTimeZoneInformation.Subtract(modifiedTimeWithLocalTimeZone);

            TimeSpan expectedOffsetAtModifiedTime = TimeZone.CurrentTimeZone.GetUtcOffset(modifiedTimeWithLocalTimeZone);

            Assert.AreEqual("Test", modification.UserName);
            Assert.AreEqual(expectedOffsetAtModifiedTime, actualOffsetAtModifiedTime, "Date was not parsed with correct time zone offset.");
            Assert.AreEqual("Test Comment", modification.Comment);
        }
 /// <summary>
 /// Retrieves the change number of the last modification.
 /// </summary>
 /// <param name="modifications">The modifications to check.</param>
 /// <returns>The last change number if there are any changes, null otherwise.</returns>
 /// <remarks>
 /// Since ChangeNumbers are no longer numbers, this will return null if there are no 
 /// modifications.
 /// </remarks>
 public static string GetLastChangeNumber(Modification[] modifications)
 {
     var lastModification = new Modification
     {
         ModifiedTime = DateTime.MinValue,
         ChangeNumber = null
     };
     foreach (Modification modification in modifications)
     {
         if (modification.ModifiedTime > lastModification.ModifiedTime)
         {
             lastModification = modification;
         }
     }
     return lastModification.ChangeNumber;
 }
		public void ParseCreatedModification()
		{
			string entry = EntryWithSingleLineComment();
			
			Modification expected = new Modification();
			expected.Comment = "added subfolder";
			expected.UserName = "******";
			expected.ModifiedTime = new DateTime(2002, 9, 16, 14, 41, 0);
			expected.Type = "Created";
			expected.FileName = "[none]";
			expected.FolderName = "plant";

			Modification[] actual = parser.ParseModifications(makeArray(entry));
			Assert.IsNotNull(actual, "expected a mod");
			Assert.AreEqual(0, actual.Length, "created should not have produced a modification");
		}
        public void ShouldNotFilterSpecifiedModWithOneFilterThatAccepts()
        {
            Modification mod = new Modification();
            mod.Type = "Delete";
            mod.UserName = "******";

            ActionFilter aFilter = new ActionFilter();
            UserFilter uFilter = new UserFilter();


            aFilter.Actions = new string[] { "Created" };
            uFilter.UserNames = new string[] { "bob" };

            filter.Filters = new IModificationFilter[] { aFilter, uFilter };

            Assert.IsFalse(filter.Accept(mod), "Modifcation was filtered");
        }
		public void ParsingSingleLogMessageProducesOneModification()
		{
			Modification[] modifications = svn.Parse(new StringReader(oneEntryLogXml), oldestEntry, newestEntry);

			Assert.AreEqual(1, modifications.Length);

			Modification expected = new Modification();
			expected.Type = "Added";
			expected.FileName = "addedfile.txt";
			expected.FolderName = "/foo";
			expected.ModifiedTime = CreateDate("2003-12-12T16:48:51Z");
			expected.ChangeNumber = "4";
			expected.UserName =string.Empty;
			expected.Comment = "i added a file";

			Assert.AreEqual(expected, modifications[0]);
		}
        public void AnalyzeModifications()
        {
            Modification[] expected = new Modification[1];
            expected[0] = new Modification();
            expected[0].Comment = @"Added new labels.";
            expected[0].EmailAddress = null;
            expected[0].Version = "1.4";
            expected[0].FileName = @"ChessViewer.java-arc";
            expected[0].FolderName = @"D:\root\PVCS\vm\common\SampleDB\archives\chess\client";
            expected[0].ModifiedTime = DateTime.Parse("2/1/00 4:52:46 PM", dfi);
            expected[0].Type = "Checked in";
            expected[0].UserName = "******";

            Modification[] actual = PvcsHistoryParser.AnalyzeModifications(GetExpectedModificationsForAnalyze());

            CustomAssertion.AssertEqualArrays(actual, expected);
        }
        public void ShouldFilterSpecifiedModification()
        {
            Modification mod = new Modification();
            mod.Type = "Created";
            mod.UserName = "******";

            ActionFilter aFilter = new ActionFilter();
            UserFilter uFilter = new UserFilter();


            aFilter.Actions = new string[] { "Created" };
            uFilter.UserNames = new string[] { "bob" };

            filter.Filters = new IModificationFilter[] { aFilter, uFilter };

            Assert.IsTrue(filter.Accept(mod), "Modifcation not filtered");
        }
        private Modification[] GetExpectedModificationsForAnalyze()
        {
            Modification[] mod = new Modification[4];
            mod[0] = new Modification();
            mod[0].Comment = @"Added new labels.";
            mod[0].EmailAddress = null;
            mod[0].Version = "1.2";
            mod[0].FileName = @"ChessViewer.java-arc";
            mod[0].FolderName = @"D:\root\PVCS\vm\common\SampleDB\archives\chess\client";
            mod[0].ModifiedTime = DateTime.Parse("2/1/00 4:52:46 PM", dfi);
            mod[0].Type = "Checked in";
            mod[0].UserName = "******";

            mod[1] = new Modification();
            mod[1].Comment = @"Added new labels.";
            mod[1].EmailAddress = null;
            mod[1].Version = "1.1";
            mod[1].FileName = @"ChessViewer.java-arc";
            mod[1].FolderName = @"D:\root\PVCS\vm\common\SampleDB\archives\chess\client";
            mod[1].ModifiedTime = DateTime.Parse("2/1/00 4:52:46 PM", dfi);
            mod[1].Type = "Checked in";
            mod[1].UserName = "******";

            mod[2] = new Modification();
            mod[2].Comment = @"Added new labels.";
            mod[2].EmailAddress = null;
            mod[2].Version = "1.4";
            mod[2].FileName = @"ChessViewer.java-arc";
            mod[2].FolderName = @"D:\root\PVCS\vm\common\SampleDB\archives\chess\client";
            mod[2].ModifiedTime = DateTime.Parse("2/1/00 4:52:46 PM", dfi);
            mod[2].Type = "Checked in";
            mod[2].UserName = "******";

            mod[3] = new Modification();
            mod[3].Comment = @"Added new labels.";
            mod[3].EmailAddress = null;
            mod[3].Version = "1.3";
            mod[3].FileName = @"ChessViewer.java-arc";
            mod[3].FolderName = @"D:\root\PVCS\vm\common\SampleDB\archives\chess\client";
            mod[3].ModifiedTime = DateTime.Parse("2/1/00 4:52:46 PM", dfi);
            mod[3].Type = "Checked in";
            mod[3].UserName = "******";

            return mod;
        }