public void TestGetChangelogBy_WithoutClosedMilestone()
        {
            IMarkdownParser markdownParser = new MarkdownParser();

            Milestone milestone = new MilestoneBuilder
            {
                Title = "v1.2.3",
            }.Build();
            MilestoneObject milestoneObject = new MilestoneObject(milestone, new PullRequest[]
            {
            });
            Dictionary <string, IList <string> > entries = new Dictionary <string, IList <string> >
            {
                {
                    "added", new[]
                    {
                        "first added entry",
                        "second added entry",
                    }
                },
            };
            VersionEntry versionEntry = new VersionEntry(milestoneObject, entries);

            string result = markdownParser.GetChangelogBy(versionEntry);

            string expected = "## v1.2.3 (OPEN)\n\n### added\n\n* first added entry\n* second added entry";

            AreEqual(expected, result);
        }
        public void TestGetChangelogBy_VersionEntryWithEmptyEntry()
        {
            IMarkdownParser markdownParser = new MarkdownParser();

            Milestone milestone = new MilestoneBuilder
            {
                Title    = "v1.2.3",
                ClosedAt = DateTimeOffset.ParseExact("01.11.1993", "dd.MM.yyyy",
                                                     CultureInfo.InvariantCulture),
            }.Build();
            MilestoneObject milestoneObject = new MilestoneObject(milestone, new PullRequest[]
            {
            });
            Dictionary <string, IList <string> > entries = new Dictionary <string, IList <string> >
            {
                {
                    "added", new string[0]
                },
                {
                    "changed", new[]
                    {
                        "first changed entry",
                        "second changed entry",
                    }
                },
            };
            VersionEntry versionEntry = new VersionEntry(milestoneObject, entries);

            string result = markdownParser.GetChangelogBy(versionEntry);

            string expected = "## v1.2.3 (1993-11-01)\n\n### changed\n\n* first changed entry\n* second changed entry";

            AreEqual(expected, result);
        }
        public void TestGetChangelogBy_VersionWithoutEntries()
        {
            IMarkdownParser markdownParser = new MarkdownParser();

            Milestone milestone = new MilestoneBuilder
            {
                Title    = "v1.2.3",
                ClosedAt = DateTimeOffset.ParseExact("01.11.1993", "dd.MM.yyyy",
                                                     CultureInfo.InvariantCulture),
            }.Build();
            MilestoneObject milestoneObject = new MilestoneObject(milestone, new PullRequest[]
            {
            });
            Dictionary <string, IList <string> > entries = new Dictionary <string, IList <string> >();
            VersionEntry versionEntry = new VersionEntry(milestoneObject, entries);

            string result = markdownParser.GetChangelogBy(versionEntry);

            AreEqual(String.Empty, result);
        }
Пример #4
0
        public async Task TestLoadPullRequestsAsync()
        {
            Options     options = new Options();
            Mock <ILog> logMock = new Mock <ILog>();
            Mock <IEnvironmentAbstraction> environmentMock    = new Mock <IEnvironmentAbstraction>();
            Mock <IFileSystem>             fileSystemMock     = new Mock <IFileSystem>();
            Mock <IGitHubClient>           gitHubClientMock   = new Mock <IGitHubClient>();
            Mock <IMarkdownParser>         markdownParserMock = new Mock <IMarkdownParser>();

            Milestone milestone = new MilestoneBuilder
            {
                Title    = "v1.0.0",
                ClosedAt = DateTimeOffset.ParseExact("15.09.1993", "dd.MM.yyyy",
                                                     CultureInfo.InvariantCulture),
            }.Build();
            PullRequest pullRequest = new PullRequestBuilder
            {
                Milestone = milestone,
                Body      = File.ReadAllText("./Assets/description_at-the-middle.md"),
            }.Build();

            gitHubClientMock.Setup(mock => mock.Repository.Get(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(new Repository(1337)));
            gitHubClientMock.Setup(mock => mock.PullRequest.GetAllForRepository(It.IsAny <long>(), It.IsAny <PullRequestRequest>()))
            .Returns(Task.FromResult(
                         new List <PullRequest> {
                pullRequest
            }.AsReadOnly() as IReadOnlyList <PullRequest>));

            TestVerbHandler verbHandler = new TestVerbHandler(options, logMock.Object, environmentMock.Object,
                                                              fileSystemMock.Object, gitHubClientMock.Object,
                                                              markdownParserMock.Object);

            IReadOnlyList <PullRequest> result = await verbHandler.LoadPullRequestsAsync();

            NotNull(result);
            AreEqual(1, result.Count);
            AreEqual(pullRequest, result[0]);
        }