コード例 #1
0
        public void VerifyOverriddenChangesAreUsed()
        {
            var yesterday   = DateTimeOffset.Now.AddDays(-1);
            var twoDaysAgo  = DateTimeOffset.Now.AddDays(-2);
            var badChange   = new DefaultChange(" ", "Added", "WithoutVersion", yesterday);
            var fixedChange = new DefaultChange("0.2.0", badChange.Tag, badChange.Summary, badChange.Date);
            var fineChange  = new DefaultChange("0.1.0", "Removed", "Another Summary", twoDaysAgo);
            var overrides   = new Dictionary <string, IChange>
            {
                { ToSha1String(badChange), fixedChange }
            };
            var changes = new List <IChange>
            {
                badChange,
                fineChange
            };
            var expectedChanges = new List <IChange>
            {
                fixedChange,
                fineChange
            };
            var repoMock   = new Mock <IRepository>();
            var commitLog  = Mock.Of <IQueryableCommitLog>(cl => cl.GetEnumerator() == MockCommitEnumerator(changes));
            var parserMock = new Mock <ICommitParser <IChange> >();

            parserMock.Setup(p => p.Parse(fixedChange)).Returns(fixedChange);
            parserMock.Setup(p => p.Parse(It.IsAny <Commit>())).Returns(fineChange);
            repoMock.Setup(r => r.Commits).Returns(commitLog);

            var reader        = new GitReader <IChange>(repoMock.Object, parserMock.Object, overrides);
            var actualChanges = reader.Values();

            Assert.That(actualChanges, Is.EquivalentTo(expectedChanges));
            repoMock.VerifyAll();
        }
コード例 #2
0
        public void VerifyParsesWithReference()
        {
            var expectedChange = new DefaultChange("Unreleased", "Added", "Some Summary", DateTimeOffset.Now, "REF-1234");
            var parser         = new DefaultCommitParser(_defaultPatterns);

            var actual = parser.Parse(MockCommit(expectedChange));

            Assert.That(actual, Is.EqualTo(expectedChange));
        }
コード例 #3
0
        public void VerifyUnreleasedCommitsHaveUnreleasedVersion()
        {
            var expectedChange = new DefaultChange(new ChangeVersion("Unreleased"), "Added", "Some Summary", DateTimeOffset.Now);
            var parser         = new DefaultCommitParser(_defaultParsingConfig);

            var actual = parser.Parse(MockCommit(expectedChange));

            Assert.That(actual, Is.EqualTo(expectedChange));
        }
コード例 #4
0
        public void VerifyParserParsesLineWithoutReferenceSuccessfully()
        {
            var expectedChange = new DefaultChange(new ChangeVersion("0.1.0"), "Some Change Type", "Some Summary", DateTimeOffset.Now.Date);
            var line           = $"{expectedChange.Version}|{expectedChange.ChangeType}|{expectedChange.Summary}|{expectedChange.Date:yyyy-MM-dd}";
            var writer         = new StringWriter();
            var parser         = new DefaultFileSourceRowParser(writer);
            var actual         = parser.Parse(line);

            Assert.That(actual, Is.EqualTo(expectedChange));
        }
コード例 #5
0
        public void VerifyParserHandlesDateFormatIssues()
        {
            var expectedChange = new DefaultChange(new ChangeVersion("0.1.0"), "Some Change Type", "Some Summary", DateTimeOffset.Now.Date);
            var line           = $"{expectedChange.Version}|{expectedChange.ChangeType}|{expectedChange.Summary}|{expectedChange.Date}";
            var writer         = new StringWriter();
            var parser         = new DefaultFileSourceRowParser(writer);
            var actual         = parser.Parse(line);

            Assert.That(actual, Is.Null);
            Assert.That(writer.ToString().Trim(), Is.EqualTo($"Error parsing line '{line}'. Date should match the format 'yyyy-MM-dd'"));
        }
コード例 #6
0
        public void VerifyParserHandlesTooManyDelimiterIssues()
        {
            var expectedChange = new DefaultChange(new ChangeVersion("0.1.0"), "Some Change Type", "Some Summary", DateTimeOffset.Now.Date);
            var line           = $"{expectedChange.Version}|||{expectedChange.ChangeType}|{expectedChange.Summary}|{expectedChange.Date:yyyy-MM-dd}";
            var writer         = new StringWriter();
            var parser         = new DefaultFileSourceRowParser(writer);
            var actual         = parser.Parse(line);

            Assert.That(actual, Is.Null);
            Assert.That(writer.ToString().Trim(), Is.EqualTo($"Error parsing line '{line}'. Wrong number of values. Expected 4 or 5 but was 6"));
        }
コード例 #7
0
        public void VerifyParsesWithGitTagsNoTagMatch()
        {
            var gitTags = new Dictionary <string, string>();

            gitTags.Add("THISCOULDBEASHA_OTHER", "0.0.0");
            var expectedChange = new DefaultChange(new ChangeVersion("Unreleased"), "Added", "Some Summary", DateTimeOffset.Now);
            var parser         = new DefaultCommitParser(_defaultParsingConfig, gitTags);

            var actual = parser.Parse(MockCommit(expectedChange));

            Assert.That(actual, Is.EqualTo(expectedChange));
        }
コード例 #8
0
        public void VerifyReleasedCommitsWithUnreleasedInVersionHaveCorrectVersion()
        {
            var releasedChange   = new DefaultChange(new ChangeVersion("2.0.0"), "Added", "Some Released Summary", DateTimeOffset.Now);
            var unreleasedChange = new DefaultChange(new ChangeVersion("Unreleased"), "Added", "Some Unreleased Summary", DateTimeOffset.Now);
            var parser           = new DefaultCommitParser(_defaultParsingConfig);

            parser.Parse(MockCommit(releasedChange));
            var actual = parser.Parse(MockCommit(unreleasedChange));

            Assert.That(actual.Version, Is.EqualTo(releasedChange.Version));
            Assert.That(actual.ChangeType, Is.EqualTo(unreleasedChange.ChangeType));
            Assert.That(actual.Summary, Is.EqualTo(unreleasedChange.Summary));
            Assert.That(actual.Date, Is.EqualTo(unreleasedChange.Date));
            Assert.That(actual.Reference, Is.EqualTo(unreleasedChange.Reference));
        }
コード例 #9
0
        public void VerifyCommitsWithUnreleasedInVersionHaveCorrectVersionWhenPreceededByExplicitChange()
        {
            var explicitChange   = new DefaultChange("2.0.0", "Added", "Some Released Summary", DateTimeOffset.Now);
            var unreleasedChange = new DefaultChange("Unreleased", "Added", "Some Unreleased Summary", DateTimeOffset.Now);
            var parser           = new DefaultCommitParser(_defaultPatterns);

            parser.Parse(explicitChange);
            var actual = parser.Parse(MockCommit(unreleasedChange));

            Assert.That(actual.Version, Is.EqualTo(explicitChange.Version));
            Assert.That(actual.Tag, Is.EqualTo(unreleasedChange.Tag));
            Assert.That(actual.Summary, Is.EqualTo(unreleasedChange.Summary));
            Assert.That(actual.Date, Is.EqualTo(unreleasedChange.Date));
            Assert.That(actual.Reference, Is.EqualTo(unreleasedChange.Reference));
        }
コード例 #10
0
        public void VerifyEnumeratorStopsAtMinVersion()
        {
            var now               = DateTimeOffset.Now;
            var minVersion        = "1.5.0";
            var changeVersion2    = new DefaultChange("2.0.0", "Added", "Some 2.0.0 Summary", now);
            var changeVersion1Pt5 = new DefaultChange(minVersion, "Added", "Some 1.5.0 Summary", now.AddDays(-1));
            var changeVersion1    = new DefaultChange("1.0.0", "Added", "Some 1.0.0 Summary", now.AddDays(-2));
            var changes           = new List <IChange> {
                changeVersion2, changeVersion1Pt5, changeVersion1
            };
            var expectedChanges = new List <IChange> {
                changeVersion2, changeVersion1Pt5
            };

            var filteredChanges = new FilteredChanges <IChange>(changes, minVersion, new HashSet <string>());

            Assert.That(filteredChanges, Is.EquivalentTo(expectedChanges));
        }
コード例 #11
0
        public void VerifyEnumeratorSkipsExcludedTags()
        {
            var now               = DateTimeOffset.Now;
            var excludedTag       = "Maintenance";
            var changeVersion2    = new DefaultChange("2.0.0", "Added", "Some 2.0.0 Summary", now);
            var changeVersion1Pt5 = new DefaultChange("1.5.0", excludedTag, "Some 1.5.0 Summary", now.AddDays(-1));
            var changeVersion1    = new DefaultChange("1.0.0", "Added", "Some 1.0.0 Summary", now.AddDays(-2));
            var changes           = new List <IChange> {
                changeVersion2, changeVersion1Pt5, changeVersion1
            };
            var expectedChanges = new List <IChange> {
                changeVersion2, changeVersion1
            };

            var filteredChanges = new FilteredChanges <IChange>(changes, null, new List <string> {
                excludedTag
            });

            Assert.That(filteredChanges, Is.EquivalentTo(expectedChanges));
        }
コード例 #12
0
        public void VerifyGetAsValueDictionaryVersionOrderingIsDescendingMixedDigits()
        {
            var expectedChange1 = new DefaultChange(new ChangeVersion("0.10.0"), "Added", "This is the latest 0.10.0", DateTime.Today, "REL-1231");
            var expectedChange2 = new DefaultChange(new ChangeVersion("0.10.0"), "Removed", "This is the middle 0.10.0", DateTime.Today.AddHours(-2), "REL-1232");
            var expectedChange3 = new DefaultChange(new ChangeVersion("0.10.0"), "Removed", "This is the earliest 0.10.0", DateTime.Today.AddHours(-3), "REL-1233");
            var expectedChange4 = new DefaultChange(new ChangeVersion("0.9.0"), "Added", "This is a change", DateTime.Today.AddDays(-1), "REL-1234");
            var expectedChange5 = new DefaultChange(new ChangeVersion("0.9.0"), "Removed", "This is the middle 0.9.0", DateTime.Today.AddDays(-2), "REL-1235");
            var expectedChange6 = new DefaultChange(new ChangeVersion("0.9.0"), "Removed", "This is the earliest 0.9.0", DateTime.Today.AddDays(-3), "REL-1236");

            var changeCache = new ChangeCache();

            changeCache.Add(new List <IChange> {
                expectedChange1, expectedChange2, expectedChange3, expectedChange4, expectedChange5, expectedChange6
            });

            var actualValueDictionary = changeCache.GetAsValueDictionary();
            var actualVersions        = (List <Dictionary <string, object> >)actualValueDictionary["versions"];

            Assert.That(actualVersions[0]["version"], Is.EqualTo(expectedChange1.Version));
            Assert.That(actualVersions[1]["version"], Is.EqualTo(expectedChange4.Version));
        }
コード例 #13
0
        public void VerifyMultipleChangesWithDifferentKeysAddedSuccessfully()
        {
            var today              = DateTime.Today;
            var expectedChange1    = new DefaultChange("0.1.0", "Added", "This is a change", today, "REL-1234");
            var expectedChange2    = new DefaultChange("0.1.0", "Removed", "This is a change", today, "REL-1235");
            var expectedChangeKey1 = new ChangeCache.ChangeKey(expectedChange1);
            var expectedChangeKey2 = new ChangeCache.ChangeKey(expectedChange2);

            var changeCache = new ChangeCache();

            changeCache.Add(new List <IChange> {
                expectedChange1, expectedChange2
            });

            changeCache.ChangeKeyToChanges.TryGetValue(expectedChangeKey1, out var actualChanges1);

            CollectionAssert.Contains(actualChanges1, expectedChange1);
            CollectionAssert.DoesNotContain(actualChanges1, expectedChange2);

            changeCache.ChangeKeyToChanges.TryGetValue(expectedChangeKey2, out var actualChanges2);

            CollectionAssert.Contains(actualChanges2, expectedChange2);
            CollectionAssert.DoesNotContain(actualChanges2, expectedChange1);
        }
コード例 #14
0
        public void VerifyGetAsValueDictionaryIsSuccessful()
        {
            var expectedChange1 = new DefaultChange("0.2.0", "Added", "This is the latest 0.2.0", DateTime.Today, "REL-1231");
            var expectedChange2 = new DefaultChange("0.2.0", "Removed", "This is the middle 0.2.0", DateTime.Today.AddHours(-2), "REL-1232");
            var expectedChange3 = new DefaultChange("0.2.0", "Removed", "This is the earliest 0.2.0", DateTime.Today.AddHours(-3), "REL-1233");
            var expectedChange4 = new DefaultChange("0.1.0", "Added", "This is a change", DateTime.Today.AddDays(-1), "REL-1234");
            var expectedChange5 = new DefaultChange("0.1.0", "Removed", "This is the middle 0.1.0", DateTime.Today.AddDays(-2), "REL-1235");
            var expectedChange6 = new DefaultChange("0.1.0", "Removed", "This is the earliest 0.1.0", DateTime.Today.AddDays(-3), "REL-1236");

            var changeCache = new ChangeCache();

            changeCache.Add(new List <IChange> {
                expectedChange1, expectedChange2, expectedChange3, expectedChange4, expectedChange5, expectedChange6
            });

            var actualValueDictionary = changeCache.GetAsValueDictionary();
            var actualVersions        = (List <Dictionary <string, object> >)actualValueDictionary["versions"];
            var version2                        = actualVersions.Find(v => v.ContainsValue("0.2.0"));
            var version2Tags                    = (List <Dictionary <string, object> >)version2["tags"];
            var version2AddedDictionary         = version2Tags.Find(t => t.ContainsValue("Added"));
            var version2AddedChanges            = (List <Dictionary <string, object> >)version2AddedDictionary["changes"];
            var version2AddedChangeSummaries    = version2AddedChanges.Select(c => c["summary"]);
            var version2AddedChangeReferences   = version2AddedChanges.Select(c => c["reference"]);
            var version2RemovedDictionary       = version2Tags.Find(t => t.ContainsValue("Removed"));
            var version2RemovedChanges          = (List <Dictionary <string, object> >)version2RemovedDictionary["changes"];
            var version2RemovedChangeSummaries  = version2RemovedChanges.Select(c => c["summary"]);
            var version2RemovedChangeReferences = version2RemovedChanges.Select(c => c["reference"]);

            Assert.That(version2["date"], Is.EqualTo(expectedChange1.Date.ToString("yyyy-MM-dd")));
            Assert.That(version2AddedChangeSummaries, Is.EquivalentTo(new List <string> {
                expectedChange1.Summary
            }));
            Assert.That(version2AddedChangeReferences, Is.EquivalentTo(new List <string> {
                expectedChange1.Reference
            }));
            Assert.That(version2RemovedChangeSummaries, Is.EquivalentTo(new List <string> {
                expectedChange2.Summary, expectedChange3.Summary
            }));
            Assert.That(version2RemovedChangeReferences, Is.EquivalentTo(new List <string> {
                expectedChange2.Reference, expectedChange3.Reference
            }));

            var version1                        = actualVersions.Find(v => v.ContainsValue("0.1.0"));
            var version1Tags                    = (List <Dictionary <string, object> >)version1["tags"];
            var version1AddedDictionary         = version1Tags.Find(t => t.ContainsValue("Added"));
            var version1AddedChanges            = (List <Dictionary <string, object> >)version1AddedDictionary["changes"];
            var version1AddedChangeSummaries    = version1AddedChanges.Select(c => c["summary"]);
            var version1AddedChangeReferences   = version1AddedChanges.Select(c => c["reference"]);
            var version1RemovedDictionary       = version1Tags.Find(t => t.ContainsValue("Removed"));
            var version1RemovedChanges          = (List <Dictionary <string, object> >)version1RemovedDictionary["changes"];
            var version1RemovedChangeSummaries  = version1RemovedChanges.Select(c => c["summary"]);
            var version1RemovedChangeReferences = version1RemovedChanges.Select(c => c["reference"]);

            Assert.That(version1["date"], Is.EqualTo(expectedChange4.Date.ToString("yyyy-MM-dd")));
            Assert.That(version1AddedChangeSummaries, Is.EquivalentTo(new List <string> {
                expectedChange4.Summary
            }));
            Assert.That(version1AddedChangeReferences, Is.EquivalentTo(new List <string> {
                expectedChange4.Reference
            }));
            Assert.That(version1RemovedChangeSummaries, Is.EquivalentTo(new List <string> {
                expectedChange5.Summary, expectedChange6.Summary
            }));
            Assert.That(version1RemovedChangeReferences, Is.EquivalentTo(new List <string> {
                expectedChange5.Reference, expectedChange6.Reference
            }));
        }