コード例 #1
0
        public void CanCreateCommitInformationFromFormatedData()
        {
            var commitGuid     = Guid.NewGuid();
            var treeGuid       = Guid.NewGuid();
            var parentGuid1    = Guid.NewGuid().ToString();
            var parentGuid2    = Guid.NewGuid().ToString();
            var authorTime     = DateTime.UtcNow.AddDays(-3);
            var commitTime     = DateTime.UtcNow.AddDays(-2);
            var authorUnixTime = (int)(authorTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
            var commitUnixTime = (int)(commitTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;

            var revisionProvider = Substitute.For <IGitRevisionProvider>();
            var parent1Rev       = new GitRevision(aModule: null, guid: parentGuid1)
            {
                Subject = "Parent1"
            };
            var parent2Rev = new GitRevision(aModule: null, guid: parentGuid2)
            {
                Subject = "Parent2"
            };

            revisionProvider.GetRevision(parentGuid1, shortFormat: true).Returns(parent1Rev);
            revisionProvider.GetRevision(parentGuid2, shortFormat: true).Returns(parent2Rev);

            var rawData = commitGuid + "\n" +
                          treeGuid + "\n" +
                          parentGuid1 + " " + parentGuid2 + "\n" +
                          "John Doe (Acme Inc) <*****@*****.**>\n" +
                          authorUnixTime + "\n" +
                          "Jane Doe (Acme Inc) <*****@*****.**>\n" +
                          commitUnixTime + "\n" +
                          "\n" +
                          "\tI made a really neato change.\n\n" +
                          "Notes (p4notes):\n" +
                          "\tP4@547123";

            var expectedHeader = "Author:\t\t<a href='mailto:[email protected]'>John Doe (Acme Inc) &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Author date:\t3 days ago (" + LocalizationHelpers.GetFullDateString(authorTime) + ")" + Environment.NewLine +
                                 "Committer:\t<a href='mailto:[email protected]'>Jane Doe (Acme Inc) &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Commit date:\t2 days ago (" + LocalizationHelpers.GetFullDateString(commitTime) + ")" + Environment.NewLine +
                                 "Commit hash:\t" + commitGuid + Environment.NewLine +
                                 "Parent(s):\t<a href='gitext://gotocommit/" + parentGuid1 + "'>" + parentGuid1.Substring(0, 10) + "</a> " + parent1Rev.Subject +
                                 Environment.NewLine +
                                 " \t\t<a href='gitext://gotocommit/" + parentGuid2 + "'>" + parentGuid2.Substring(0, 10) + "</a> " + parent2Rev.Subject;

            var expectedBody = "\nI made a really neato change." + Environment.NewLine + Environment.NewLine +
                               "Notes (p4notes):" + Environment.NewLine +
                               "\tP4@547123";

            var commitData        = CommitData.CreateFromFormatedData(rawData, new GitModule(""));
            var commitInformation = CommitInformation.GetCommitInfo(revisionProvider, commitData, true);

            Assert.AreEqual(expectedHeader, commitInformation.Header);
            Assert.AreEqual(expectedBody, commitInformation.Body);
        }
コード例 #2
0
        public void RenderPlain_with_spaces()
        {
            var expectedHeader = "Author:      John Doe (Acme Inc) <*****@*****.**>" + Environment.NewLine +
                                 "Author date: 3 days ago (" + LocalizationHelpers.GetFullDateString(_data.AuthorDate) + ")" + Environment.NewLine +
                                 "Committer:   Jane Doe <*****@*****.**>" + Environment.NewLine +
                                 "Commit date: 2 days ago (" + LocalizationHelpers.GetFullDateString(_data.CommitDate) + ")" + Environment.NewLine +
                                 "Commit hash: " + _data.Guid;

            var result = _rendererSpaces.RenderPlain(_data);

            result.Should().Be(expectedHeader);
        }
コード例 #3
0
        public void Render_with_spaces_no_links()
        {
            var expectedHeader = "Author:      <a href='mailto:[email protected]'>John Doe (Acme Inc) &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Author date: 3 days ago (" + LocalizationHelpers.GetFullDateString(_data.AuthorDate) + ")" + Environment.NewLine +
                                 "Committer:   <a href='mailto:[email protected]'>Jane Doe &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Commit date: 2 days ago (" + LocalizationHelpers.GetFullDateString(_data.CommitDate) + ")" + Environment.NewLine +
                                 "Commit hash: " + _data.Guid + Environment.NewLine +
                                 "Children:    " + _data.ChildrenGuids[0].Substring(0, 10) + " " + _data.ChildrenGuids[1].Substring(0, 10) + " " + _data.ChildrenGuids[2].Substring(0, 10) + Environment.NewLine +
                                 "Parent(s):   " + _data.ParentGuids[0].Substring(0, 10) + " " + _data.ParentGuids[1].Substring(0, 10);

            var result = _rendererSpaces.Render(_data, false);

            result.Should().Be(expectedHeader);
        }
コード例 #4
0
        public void Render_with_spaces_with_links()
        {
            var expectedHeader = "Author:      <a href='mailto:[email protected]'>John Doe (Acme Inc) &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Author date: 3 days ago (" + LocalizationHelpers.GetFullDateString(_data.AuthorDate) + ")" + Environment.NewLine +
                                 "Committer:   <a href='mailto:[email protected]'>Jane Doe &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Commit date: 2 days ago (" + LocalizationHelpers.GetFullDateString(_data.CommitDate) + ")" + Environment.NewLine +
                                 "Commit hash: " + _data.Guid + Environment.NewLine +
                                 "Children:    " +
                                 "<a href='gitext://gotocommit/" + _data.ChildrenGuids[0] + "'>" + GitRevision.ToShortSha(_data.ChildrenGuids[0]) + "</a> " +
                                 "<a href='gitext://gotocommit/" + _data.ChildrenGuids[1] + "'>" + GitRevision.ToShortSha(_data.ChildrenGuids[1]) + "</a> " +
                                 "<a href='gitext://gotocommit/" + _data.ChildrenGuids[2] + "'>" + GitRevision.ToShortSha(_data.ChildrenGuids[2]) + "</a>" + Environment.NewLine +
                                 "Parent(s):   " +
                                 "<a href='gitext://gotocommit/" + _data.ParentGuids[0] + "'>" + GitRevision.ToShortSha(_data.ParentGuids[0]) + "</a> " +
                                 "<a href='gitext://gotocommit/" + _data.ParentGuids[1] + "'>" + GitRevision.ToShortSha(_data.ParentGuids[1]) + "</a>";

            var result = _rendererSpaces.Render(_data, true);

            result.Should().Be(expectedHeader);
        }
コード例 #5
0
        public void CanCreateCommitInformationFromFormatedData()
        {
            LinkFactory linkFactory    = new LinkFactory();
            var         commitGuid     = Guid.NewGuid();
            var         treeGuid       = Guid.NewGuid();
            var         parentGuid1    = Guid.NewGuid().ToString();
            var         parentGuid2    = Guid.NewGuid().ToString();
            var         authorTime     = DateTime.UtcNow.AddDays(-3);
            var         commitTime     = DateTime.UtcNow.AddDays(-2);
            var         authorUnixTime = (int)(authorTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
            var         commitUnixTime = (int)(commitTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;

            var rawData = commitGuid + "\n" +
                          treeGuid + "\n" +
                          parentGuid1 + " " + parentGuid2 + "\n" +
                          "John Doe (Acme Inc) <*****@*****.**>\n" +
                          authorUnixTime + "\n" +
                          "Jane Doe (Acme Inc) <*****@*****.**>\n" +
                          commitUnixTime + "\n" +
                          "\n" +
                          "\tI made a really neato change.\n\n" +
                          "Notes (p4notes):\n" +
                          "\tP4@547123";

            var expectedHeader = "Author:      <a href='mailto:[email protected]'>John Doe (Acme Inc) &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Author date: 3 days ago (" + LocalizationHelpers.GetFullDateString(authorTime) + ")" + Environment.NewLine +
                                 "Committer:   <a href='mailto:[email protected]'>Jane Doe (Acme Inc) &lt;[email protected]&gt;</a>" + Environment.NewLine +
                                 "Commit date: 2 days ago (" + LocalizationHelpers.GetFullDateString(commitTime) + ")" + Environment.NewLine +
                                 "Commit hash: " + commitGuid + Environment.NewLine +
                                 "Parent(s):   <a href='gitext://gotocommit/" + parentGuid1 + "'>" + parentGuid1.Substring(0, 10) + "</a> <a href='gitext://gotocommit/" + parentGuid2 + "'>" + parentGuid2.Substring(0, 10) + "</a>";

            var expectedBody = "\nI made a really neato change." + Environment.NewLine + Environment.NewLine +
                               "Notes (p4notes):" + Environment.NewLine +
                               "\tP4@547123";

            // TEMP, will be refactored in the follow up refactor
            var commitData        = new CommitDataManager(() => new GitModule("")).CreateFromFormatedData(rawData);
            var commitInformation = CommitInformation.GetCommitInfo(commitData, linkFactory, true);

            Assert.AreEqual(expectedHeader, commitInformation.Header);
            Assert.AreEqual(expectedBody, commitInformation.Body);
        }
コード例 #6
0
 /// <summary>
 /// Formats the supplied date as relative local date (e.g. 3 months ago (10/9/17 4:38:40 pm)).
 /// </summary>
 /// <param name="date">Date to format.</param>
 /// <returns>Date in relative local date format.</returns>
 public string FormatDateAsRelativeLocal(DateTimeOffset date)
 {
     return(string.Format("{0} ({1})", LocalizationHelpers.GetRelativeDateString(_getUtcNow(), date.UtcDateTime), LocalizationHelpers.GetFullDateString(date)));
 }