From e283f764ac92794960de0458af557033b859cd28 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 11 Dec 2017 18:48:04 -0500 Subject: [PATCH 1/3] Changes to support a default for GitLogEntry --- src/GitHub.Api/Git/GitLogEntry.cs | 152 ++++++++-- .../LogEntryOutputProcessor.cs | 25 +- .../Process/ProcessManagerIntegrationTests.cs | 64 ++--- .../UnitTests/IO/GitLogEntryListTests.cs | 260 +++++++----------- src/tests/UnitTests/IO/GitLogEntryTests.cs | 242 ++++++---------- .../IO/LogEntryOutputProcessorTests.cs | 23 +- 6 files changed, 346 insertions(+), 420 deletions(-) diff --git a/src/GitHub.Api/Git/GitLogEntry.cs b/src/GitHub.Api/Git/GitLogEntry.cs index 5861f4334..7954787d8 100644 --- a/src/GitHub.Api/Git/GitLogEntry.cs +++ b/src/GitHub.Api/Git/GitLogEntry.cs @@ -11,22 +11,91 @@ public struct GitLogEntry private const string Today = "Today"; private const string Yesterday = "Yesterday"; - public string CommitID; - public string MergeA; - public string MergeB; - public string AuthorName; - public string AuthorEmail; - public string CommitEmail; - public string CommitName; - public string Summary; - public string Description; - public string TimeString; - public string CommitTimeString; - public List Changes; - - public string ShortID + public static GitLogEntry Default = new GitLogEntry(String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, new List(), String.Empty, String.Empty); + + public string commitID; + public string mergeA; + public string mergeB; + public string authorName; + public string authorEmail; + public string commitEmail; + public string commitName; + public string summary; + public string description; + public string timeString; + public string commitTimeString; + public List changes; + + public GitLogEntry(string commitID, + string authorName, string authorEmail, + string commitName, string commitEmail, + string summary, + string description, + DateTimeOffset time, DateTimeOffset commitTime, + List changes, + string mergeA = null, string mergeB = null) : this() { - get { return CommitID.Length < 7 ? CommitID : CommitID.Substring(0, 7); } + Guard.ArgumentNotNull(commitID, "commitID"); + Guard.ArgumentNotNull(authorName, "authorName"); + Guard.ArgumentNotNull(authorEmail, "authorEmail"); + Guard.ArgumentNotNull(commitEmail, "commitEmail"); + Guard.ArgumentNotNull(commitName, "commitName"); + Guard.ArgumentNotNull(summary, "summary"); + Guard.ArgumentNotNull(description, "description"); + Guard.ArgumentNotNull(changes, "changes"); + + this.commitID = commitID; + this.authorName = authorName; + this.authorEmail = authorEmail; + this.commitEmail = commitEmail; + this.commitName = commitName; + this.summary = summary; + this.description = description; + + Time = time; + CommitTime = commitTime; + + this.changes = changes; + + this.mergeA = mergeA ?? string.Empty; + this.mergeB = mergeB ?? string.Empty; + } + + public GitLogEntry(string commitID, + string authorName, string authorEmail, + string commitName, string commitEmail, + string summary, + string description, + string timeString, string commitTimeString, + List changes, + string mergeA = null, string mergeB = null) : this() + { + Guard.ArgumentNotNull(commitID, "commitID"); + Guard.ArgumentNotNull(authorName, "authorName"); + Guard.ArgumentNotNull(authorEmail, "authorEmail"); + Guard.ArgumentNotNull(commitEmail, "commitEmail"); + Guard.ArgumentNotNull(commitName, "commitName"); + Guard.ArgumentNotNull(summary, "summary"); + Guard.ArgumentNotNull(description, "description"); + Guard.ArgumentNotNull(timeString, "timeString"); + Guard.ArgumentNotNull(commitTimeString, "commitTimeString"); + Guard.ArgumentNotNull(changes, "changes"); + + this.commitID = commitID; + this.authorName = authorName; + this.authorEmail = authorEmail; + this.commitEmail = commitEmail; + this.commitName = commitName; + this.summary = summary; + this.description = description; + + this.timeString = timeString; + this.commitTimeString = commitTimeString; + + this.changes = changes; + + this.mergeA = mergeA ?? string.Empty; + this.mergeB = mergeB ?? string.Empty; } public string PrettyTimeString @@ -49,37 +118,62 @@ public DateTimeOffset Time { if (!timeValue.HasValue) { - timeValue = DateTimeOffset.Parse(TimeString); + timeValue = DateTimeOffset.ParseExact(TimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None); } - + return timeValue.Value; } + private set + { + timeString = value.ToString(Constants.Iso8601Format); + timeValue = value; + } } [NonSerialized] private DateTimeOffset? commitTimeValue; - public DateTimeOffset? CommitTime + public DateTimeOffset CommitTime { get { - if (!timeValue.HasValue && !string.IsNullOrEmpty(CommitTimeString)) + if (!commitTimeValue.HasValue) { - commitTimeValue = DateTimeOffset.Parse(CommitTimeString); + commitTimeValue = DateTimeOffset.ParseExact(CommitTimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None); } - return commitTimeValue; + return commitTimeValue.Value; + } + private set + { + commitTimeString = value.ToString(Constants.Iso8601Format); + commitTimeValue = value; } } - public void Clear() - { - CommitID = MergeA = MergeB = AuthorName = AuthorEmail = Summary = Description = ""; + public string ShortID => CommitID.Length < 7 ? CommitID : CommitID.Substring(0, 7); - timeValue = DateTimeOffset.MinValue; - TimeString = timeValue.Value.ToString(DateTimeFormatInfo.CurrentInfo); + public string CommitID => commitID; - commitTimeValue = null; - CommitTimeString = null; - } + public string MergeA => mergeA; + + public string MergeB => mergeB; + + public string AuthorName => authorName; + + public string AuthorEmail => authorEmail; + + public string CommitEmail => commitEmail; + + public string CommitName => commitName; + + public string Summary => summary; + + public string Description => description; + + public string TimeString => timeString; + + public string CommitTimeString => commitTimeString; + + public List Changes => changes; public override string ToString() { diff --git a/src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs b/src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs index b165b82a5..4e916a62c 100644 --- a/src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs +++ b/src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs @@ -317,21 +317,16 @@ private void ReturnGitLogEntry() if (time.HasValue) { - RaiseOnEntry(new GitLogEntry() - { - AuthorName = authorName, - CommitName = committerName, - MergeA = mergeA, - MergeB = mergeB, - Changes = changes, - AuthorEmail = authorEmail, - CommitEmail = committerEmail, - Summary = summary, - Description = description, - CommitID = commitId, - TimeString = time.Value.ToString(Constants.Iso8601Format), - CommitTimeString = committerTime.Value.ToString(Constants.Iso8601Format) - }); + var gitLogEntry = new GitLogEntry(commitId, + authorName, authorEmail, + committerName, committerEmail, + summary, + description, + time.Value, committerTime.Value, + changes, + mergeA, mergeB); + + RaiseOnEntry(gitLogEntry); } Reset(); diff --git a/src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs b/src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs index 458e997e6..0d1f80913 100644 --- a/src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs +++ b/src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs @@ -42,42 +42,29 @@ public async Task LogEntriesTest() logEntries.AssertEqual(new[] { - new GitLogEntry - { - AuthorEmail = "author@example.com", - CommitEmail = "author@example.com", - AuthorName = "Author Person", - CommitName = "Author Person", - Changes = new List + new GitLogEntry("018997938335742f8be694240a7c2b352ec0835f", + "Author Person", "author@example.com", "Author Person", + "author@example.com", + "Moving project files where they should be kept", + "Moving project files where they should be kept", firstCommitTime, + firstCommitTime, new List { new GitStatusEntry("Assets/TestDocument.txt".ToNPath(), TestRepoMasterCleanUnsynchronized + "/Assets/TestDocument.txt".ToNPath(), "Assets/TestDocument.txt".ToNPath(), GitFileStatus.Renamed, "TestDocument.txt") - }, - CommitID = "018997938335742f8be694240a7c2b352ec0835f", - Description = "Moving project files where they should be kept", - Summary = "Moving project files where they should be kept", - TimeString = firstCommitTime.ToString(Constants.Iso8601Format), - CommitTimeString = firstCommitTime.ToString(Constants.Iso8601Format), - }, - new GitLogEntry - { - AuthorEmail = "author@example.com", - CommitEmail = "author@example.com", - AuthorName = "Author Person", - CommitName = "Author Person", - Changes = new List + }), + + new GitLogEntry("03939ffb3eb8486dba0259b43db00842bbe6eca1", + "Author Person", "author@example.com", "Author Person", + "author@example.com", + "Initial Commit", + "Initial Commit", secondCommitTime, + secondCommitTime, new List { new GitStatusEntry("TestDocument.txt".ToNPath(), TestRepoMasterCleanUnsynchronized + "/TestDocument.txt".ToNPath(), "TestDocument.txt".ToNPath(), GitFileStatus.Added), - }, - CommitID = "03939ffb3eb8486dba0259b43db00842bbe6eca1", - Description = "Initial Commit", - Summary = "Initial Commit", - TimeString = secondCommitTime.ToString(Constants.Iso8601Format), - CommitTimeString = secondCommitTime.ToString(Constants.Iso8601Format), - }, + }), }); } @@ -95,24 +82,17 @@ public async Task RussianLogEntriesTest() logEntries.AssertEqual(new[] { - new GitLogEntry - { - AuthorEmail = "author@example.com", - CommitEmail = "author@example.com", - AuthorName = "Author Person", - CommitName = "Author Person", - Changes = new List + new GitLogEntry("06d6451d351626894a30e9134f551db12c74254b", + "Author Person", "author@example.com", "Author Person", + "author@example.com", + "Я люблю github", + "Я люблю github", commitTime, + commitTime, new List { new GitStatusEntry(@"Assets\A new file.txt".ToNPath(), TestRepoMasterCleanUnsynchronizedRussianLanguage + "/Assets/A new file.txt".ToNPath(), "Assets/A new file.txt".ToNPath(), GitFileStatus.Added), - }, - CommitID = "06d6451d351626894a30e9134f551db12c74254b", - Description = "Я люблю github", - Summary = "Я люблю github", - TimeString = commitTime.ToString(Constants.Iso8601Format), - CommitTimeString = commitTime.ToString(Constants.Iso8601Format), - } + }), }); } diff --git a/src/tests/UnitTests/IO/GitLogEntryListTests.cs b/src/tests/UnitTests/IO/GitLogEntryListTests.cs index ac4ee8a7f..daeeffaeb 100644 --- a/src/tests/UnitTests/IO/GitLogEntryListTests.cs +++ b/src/tests/UnitTests/IO/GitLogEntryListTests.cs @@ -32,22 +32,19 @@ public void NullListShouldNotEqualEmptyList() public void NullListShouldNotEqualListOf1() { var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); + var entries = new[] { - new GitLogEntry - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - } + new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(), + "MergeA", "MergeB") }; + GitLogEntry[] otherEntries = null; entries.AssertNotEqual(otherEntries); @@ -57,22 +54,19 @@ public void NullListShouldNotEqualListOf1() public void EmptyListShouldNotEqualListOf1() { var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); + var entries = new[] { - new GitLogEntry - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - } + new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(), + "MergeA", "MergeB") }; + GitLogEntry[] otherEntries = new GitLogEntry[0]; entries.AssertNotEqual(otherEntries); @@ -82,46 +76,37 @@ public void EmptyListShouldNotEqualListOf1() public void ListOf1ShouldEqualListOf1() { var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); + var entries = new[] { - new GitLogEntry - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(new[] { new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - } + "MergeA", "MergeB") }; var otherEntries = new[] { - new GitLogEntry - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(new[] { new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), - }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - } + }), + "MergeA", "MergeB") }; entries.AssertEqual(otherEntries); @@ -135,70 +120,49 @@ public void ListOf2ShouldEqualListOf2() var entries = new[] { - new GitLogEntry - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", "Description", + commitTime, commitTime, + new List(new[] { new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }, - new GitLogEntry - { - AuthorName = "OtherAuthorName", - AuthorEmail = "OtherAuthorEmail", - MergeA = "OtherMergeA", - MergeB = "OtherMergeB", - Changes = new List(), - CommitID = "OtherCommitID", - Summary = "OtherSummary", - Description = "OtherDescription", - TimeString = otherCommitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = otherCommitTime.ToString(DateTimeFormatInfo.CurrentInfo), - } + "MergeA", "MergeB"), + new GitLogEntry("`CommitID", + "`AuthorName", "`AuthorEmail", + "`AuthorName", "`AuthorEmail", + "`Summary", + "`Description", + commitTime, commitTime, + new List(), + "`MergeA", "`MergeB"), }; var otherEntries = new[] { - new GitLogEntry - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + new GitLogEntry("`CommitID", + "`AuthorName", "`AuthorEmail", + "`AuthorName", "`AuthorEmail", + "`Summary", + "`Description", + commitTime, commitTime, + new List(new[] { new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }, - new GitLogEntry - { - AuthorName = "OtherAuthorName", - AuthorEmail = "OtherAuthorEmail", - MergeA = "OtherMergeA", - MergeB = "OtherMergeB", - Changes = new List(), - CommitID = "OtherCommitID", - Summary = "OtherSummary", - Description = "OtherDescription", - TimeString = otherCommitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = otherCommitTime.ToString(DateTimeFormatInfo.CurrentInfo), - } + "`MergeA", "`MergeB"), + new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(), + "MergeA", "MergeB") }; entries.AssertEqual(otherEntries); @@ -212,70 +176,50 @@ public void ListOf2ShouldNotEqualListOf2InDifferentOrder() var entries = new[] { - new GitLogEntry - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(new[] { new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }, - new GitLogEntry - { - AuthorName = "OtherAuthorName", - AuthorEmail = "OtherAuthorEmail", - MergeA = "OtherMergeA", - MergeB = "OtherMergeB", - Changes = new List(), - CommitID = "OtherCommitID", - Summary = "OtherSummary", - Description = "OtherDescription", - TimeString = otherCommitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = otherCommitTime.ToString(DateTimeFormatInfo.CurrentInfo), - } + "MergeA", "MergeB"), + new GitLogEntry("`CommitID", + "`AuthorName", "`AuthorEmail", + "`AuthorName", "`AuthorEmail", + "`Summary", + "`Description", + commitTime, commitTime, + new List(), + "`MergeA", "`MergeB"), }; var otherEntries = new[] { - new GitLogEntry - { - AuthorName = "OtherAuthorName", - AuthorEmail = "OtherAuthorEmail", - MergeA = "OtherMergeA", - MergeB = "OtherMergeB", - Changes = new List(), - CommitID = "OtherCommitID", - Summary = "OtherSummary", - Description = "OtherDescription", - TimeString = otherCommitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = otherCommitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }, - new GitLogEntry - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + new GitLogEntry("`CommitID", + "`AuthorName", "`AuthorEmail", + "`AuthorName", "`AuthorEmail", + "`Summary", + "`Description", + otherCommitTime, otherCommitTime, + new List(), + "`MergeA", "`MergeB"), + new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + otherCommitTime, otherCommitTime, + new List(new[] { new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), - }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - } + }), + "MergeA", "MergeB") }; entries.AssertNotEqual(otherEntries); diff --git a/src/tests/UnitTests/IO/GitLogEntryTests.cs b/src/tests/UnitTests/IO/GitLogEntryTests.cs index 89e3ddccc..7d5d43b33 100644 --- a/src/tests/UnitTests/IO/GitLogEntryTests.cs +++ b/src/tests/UnitTests/IO/GitLogEntryTests.cs @@ -14,90 +14,40 @@ public class GitLogEntryTests public void ShouldEqualSelf() { var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); - var gitLogEntry = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; + var gitLogEntry = new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(), + "MergeA", "MergeB"); gitLogEntry.AssertEqual(gitLogEntry); } - [Test] - public void ShouldEqualAnotherWhenChangesIsNull() - { - var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); - - var gitLogEntry1 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = null, - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; - - var gitLogEntry2 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = null, - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; - - gitLogEntry1.AssertEqual(gitLogEntry2); - } - [Test] public void ShouldNotEqualAnotherWhenFieldsAreDifferent() { var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); - var gitLogEntry1 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = null, - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; - - var gitLogEntry2 = new GitLogEntry() - { - AuthorName = "ASDFASDF", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = null, - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; + + var gitLogEntry1 = new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(), + "MergeA", "MergeB"); + + var gitLogEntry2 = new GitLogEntry("`CommitID", + "`AuthorName", "`AuthorEmail", + "`AuthorName", "`AuthorEmail", + "`Summary", + "`Description", + commitTime, commitTime, + new List(), + "`MergeA", "`MergeB"); gitLogEntry1.AssertNotEqual(gitLogEntry2); } @@ -106,34 +56,24 @@ public void ShouldNotEqualAnotherWhenFieldsAreDifferent() public void ShouldEqualAnotherWhenChangesIsEmpty() { var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); - var gitLogEntry1 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; - - var gitLogEntry2 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; - + var gitLogEntry1 = new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(), + "MergeA", "MergeB"); + + var gitLogEntry2 = new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(), + "MergeA", "MergeB"); + gitLogEntry1.AssertEqual(gitLogEntry2); } @@ -142,41 +82,29 @@ public void ShouldEqualAnotherWhenChangesIsNotEmpty() { var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); - var gitLogEntry1 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + var gitLogEntry1 = new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", "Description", + commitTime, commitTime, + new List(new[] { - new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, - "SomeOriginalPath"), + new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; - - var gitLogEntry2 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + "MergeA", "MergeB"); + + var gitLogEntry2 = new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(new[] { new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath") }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; + "MergeA", "MergeB"); gitLogEntry1.AssertEqual(gitLogEntry2); } @@ -186,41 +114,31 @@ public void ShouldNotEqualAnotherWhenChangesAreDifferent() { var commitTime = new DateTimeOffset(1921, 12, 23, 1, 3, 6, 23, TimeSpan.Zero); - var gitLogEntry1 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + var gitLogEntry1 = new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(new[] { new GitStatusEntry("ASDFASDF", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), - }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; - - var gitLogEntry2 = new GitLogEntry() - { - AuthorName = "AuthorName", - AuthorEmail = "AuthorEmail", - MergeA = "MergeA", - MergeB = "MergeB", - Changes = new List(new[] + }), + "MergeA", "MergeB"); + + var gitLogEntry2 = new GitLogEntry("CommitID", + "AuthorName", "AuthorEmail", + "AuthorName", "AuthorEmail", + "Summary", + "Description", + commitTime, commitTime, + new List(new[] { new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath") - }), - CommitID = "CommitID", - Summary = "Summary", - Description = "Description", - TimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - CommitTimeString = commitTime.ToString(DateTimeFormatInfo.CurrentInfo), - }; + }), + "MergeA", "MergeB"); gitLogEntry1.AssertNotEqual(gitLogEntry2); } diff --git a/src/tests/UnitTests/IO/LogEntryOutputProcessorTests.cs b/src/tests/UnitTests/IO/LogEntryOutputProcessorTests.cs index 04e5f5896..5c0bc3a5c 100644 --- a/src/tests/UnitTests/IO/LogEntryOutputProcessorTests.cs +++ b/src/tests/UnitTests/IO/LogEntryOutputProcessorTests.cs @@ -41,26 +41,21 @@ public void ShouldParseSingleCommit() }; var commitTime = new DateTimeOffset(2017, 1, 6, 15, 36, 57, TimeSpan.FromHours(1)); + var expected = new[] { - new GitLogEntry - { - CommitID = "1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf", - AuthorEmail = "author@example.com", - AuthorName = "Author Person", - CommitEmail = "author@example.com", - CommitName = "Author Person", - Changes = new List + new GitLogEntry("1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf", + "Author Person", "author@example.com", + "Author Person", "author@example.com", + "Rename RepositoryModelBase to RepositoryModel", + "Rename RepositoryModelBase to RepositoryModel", + commitTime, commitTime, + new List { new GitStatusEntry("src/GitHub.App/Models/RemoteRepositoryModel.cs", TestRootPath + @"\src/GitHub.App/Models/RemoteRepositoryModel.cs", null, GitFileStatus.Modified), - }, - Summary = "Rename RepositoryModelBase to RepositoryModel", - Description = "Rename RepositoryModelBase to RepositoryModel", - TimeString = commitTime.ToString(Constants.Iso8601Format), - CommitTimeString = commitTime.ToString(Constants.Iso8601Format), - }, + }) }; AssertProcessOutput(output, expected); From 39a877c18cbdf29b66ad549e14ee78e61d973d02 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 12 Dec 2017 07:35:17 -0500 Subject: [PATCH 2/3] Tweaking the constructor --- src/GitHub.Api/Git/GitLogEntry.cs | 59 ++++++++++--------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/src/GitHub.Api/Git/GitLogEntry.cs b/src/GitHub.Api/Git/GitLogEntry.cs index 7954787d8..10b2fed11 100644 --- a/src/GitHub.Api/Git/GitLogEntry.cs +++ b/src/GitHub.Api/Git/GitLogEntry.cs @@ -11,7 +11,7 @@ public struct GitLogEntry private const string Today = "Today"; private const string Yesterday = "Yesterday"; - public static GitLogEntry Default = new GitLogEntry(String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, new List(), String.Empty, String.Empty); + public static GitLogEntry Default = new GitLogEntry(String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, DateTimeOffset.MinValue, DateTimeOffset.MinValue, new List(), String.Empty, String.Empty); public string commitID; public string mergeA; @@ -61,43 +61,6 @@ public GitLogEntry(string commitID, this.mergeB = mergeB ?? string.Empty; } - public GitLogEntry(string commitID, - string authorName, string authorEmail, - string commitName, string commitEmail, - string summary, - string description, - string timeString, string commitTimeString, - List changes, - string mergeA = null, string mergeB = null) : this() - { - Guard.ArgumentNotNull(commitID, "commitID"); - Guard.ArgumentNotNull(authorName, "authorName"); - Guard.ArgumentNotNull(authorEmail, "authorEmail"); - Guard.ArgumentNotNull(commitEmail, "commitEmail"); - Guard.ArgumentNotNull(commitName, "commitName"); - Guard.ArgumentNotNull(summary, "summary"); - Guard.ArgumentNotNull(description, "description"); - Guard.ArgumentNotNull(timeString, "timeString"); - Guard.ArgumentNotNull(commitTimeString, "commitTimeString"); - Guard.ArgumentNotNull(changes, "changes"); - - this.commitID = commitID; - this.authorName = authorName; - this.authorEmail = authorEmail; - this.commitEmail = commitEmail; - this.commitName = commitName; - this.summary = summary; - this.description = description; - - this.timeString = timeString; - this.commitTimeString = commitTimeString; - - this.changes = changes; - - this.mergeA = mergeA ?? string.Empty; - this.mergeB = mergeB ?? string.Empty; - } - public string PrettyTimeString { get @@ -118,7 +81,15 @@ public DateTimeOffset Time { if (!timeValue.HasValue) { - timeValue = DateTimeOffset.ParseExact(TimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None); + DateTimeOffset result; + if (DateTimeOffset.TryParseExact(TimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture,DateTimeStyles.None, out result)) + { + timeValue = result; + } + else + { + Time = DateTimeOffset.MinValue; + } } return timeValue.Value; @@ -137,7 +108,15 @@ public DateTimeOffset CommitTime { if (!commitTimeValue.HasValue) { - commitTimeValue = DateTimeOffset.ParseExact(CommitTimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None); + DateTimeOffset result; + if (DateTimeOffset.TryParseExact(CommitTimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out result)) + { + commitTimeValue = result; + } + else + { + CommitTime = DateTimeOffset.MinValue; + } } return commitTimeValue.Value; From 742e048edb42aaae7b4ca13447ca734196789b2d Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 12 Dec 2017 07:37:14 -0500 Subject: [PATCH 3/3] Fixing tests --- .../UnitTests/IO/GitLogEntryListTests.cs | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/tests/UnitTests/IO/GitLogEntryListTests.cs b/src/tests/UnitTests/IO/GitLogEntryListTests.cs index daeeffaeb..769559435 100644 --- a/src/tests/UnitTests/IO/GitLogEntryListTests.cs +++ b/src/tests/UnitTests/IO/GitLogEntryListTests.cs @@ -85,11 +85,10 @@ public void ListOf1ShouldEqualListOf1() "Summary", "Description", commitTime, commitTime, - new List(new[] + new List { - new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, - "SomeOriginalPath"), - }), + new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), + }, "MergeA", "MergeB") }; @@ -125,11 +124,10 @@ public void ListOf2ShouldEqualListOf2() "AuthorName", "AuthorEmail", "Summary", "Description", commitTime, commitTime, - new List(new[] + new List { - new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, - "SomeOriginalPath"), - }), + new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"), + }, "MergeA", "MergeB"), new GitLogEntry("`CommitID", "`AuthorName", "`AuthorEmail", @@ -143,28 +141,27 @@ public void ListOf2ShouldEqualListOf2() var otherEntries = new[] { - new GitLogEntry("`CommitID", - "`AuthorName", "`AuthorEmail", - "`AuthorName", "`AuthorEmail", - "`Summary", - "`Description", - commitTime, commitTime, - new List(new[] - { - new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, - "SomeOriginalPath"), - }), - "`MergeA", "`MergeB"), new GitLogEntry("CommitID", "AuthorName", "AuthorEmail", "AuthorName", "AuthorEmail", "Summary", "Description", commitTime, commitTime, - new List(), - "MergeA", "MergeB") + new List { + new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath") + }, + "MergeA", "MergeB"), + new GitLogEntry("`CommitID", + "`AuthorName", "`AuthorEmail", + "`AuthorName", "`AuthorEmail", + "`Summary", + "`Description", + commitTime, commitTime, + new List(), + "`MergeA", "`MergeB") }; + entries.AssertEqual(otherEntries); }