示例#1
0
        public async Task Run_adds_pull_request_links_to_footers(string footerText, int prNumber, string owner, string repo)
        {
            // ARRANGE
            var repoMock = new Mock <IGitRepository>(MockBehavior.Strict);

            repoMock.Setup(x => x.Remotes).Returns(new[] { new GitRemote("origin", "http://github.com/owner/repo.git") });

            m_GitHubCommitsClientMock
            .Setup(x => x.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(
                (string owner, string repo, string sha) => Task.FromResult <GitHubCommit>(new TestGitHubCommit($"https://example.com/{sha}"))
                );
            m_GitHubIssuesClientMock
            .Setup(x => x.Get(owner, repo, prNumber))
            .ThrowsAsync(new NotFoundException("Message", HttpStatusCode.NotFound));

            m_GitHubPullRequestsClient
            .Setup(x => x.Get(owner, repo, prNumber))
            .Returns(
                Task.FromResult <PullRequest>(new TestGitHubPullRequest($"https://example.com/pr/{prNumber}"))
                );


            var sut = new GitHubLinkTask(m_Logger, repoMock.Object, m_GitHubClientFactoryMock.Object);

            var changeLog = new ApplicationChangeLog()
            {
                GetSingleVersionChangeLog(
                    "1.2.3",
                    null,
                    GetChangeLogEntry(summary: "Entry1", commit: "01", footers: new []
                {
                    new ChangeLogEntryFooter(new CommitMessageFooterName("Issue"), footerText)
                })
                    )
            };

            // ACT
            var result = await sut.RunAsync(changeLog);

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);

            var entries = changeLog.ChangeLogs.SelectMany(x => x.AllEntries).ToArray();

            Assert.All(entries, entry =>
            {
                Assert.All(entry.Footers.Where(x => x.Name == new CommitMessageFooterName("Issue")), footer =>
                {
                    Assert.NotNull(footer.WebUri);
                    var expectedUri = new Uri($"https://example.com/pr/{prNumber}");
                    Assert.Equal(expectedUri, footer.WebUri);
                });
            });

            m_GitHubPullRequestsClient.Verify(x => x.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()), Times.Once);
            m_GitHubIssuesClientMock.Verify(x => x.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()), Times.Once);
        }
示例#2
0
        public async Task Run_adds_a_link_to_all_commits_if_url_can_be_parsed()
        {
            // ARRANGE
            var repoMock = new Mock <IGitRepository>(MockBehavior.Strict);

            repoMock.Setup(x => x.Remotes).Returns(new[] { new GitRemote("origin", "http://github.com/owner/repo.git") });

            m_GitHubCommitsClientMock
            .Setup(x => x.Get("owner", "repo", It.IsAny <string>()))
            .Returns(
                (string owner, string repo, string sha) => Task.FromResult <GitHubCommit>(new TestGitHubCommit($"https://example.com/{sha}"))
                );

            var sut = new GitHubLinkTask(m_Logger, repoMock.Object, m_GitHubClientFactoryMock.Object);

            var changeLog = new ApplicationChangeLog()
            {
                GetSingleVersionChangeLog(
                    "1.2.3",
                    null,
                    GetChangeLogEntry(summary: "Entry1", commit: "01"),
                    GetChangeLogEntry(summary: "Entry2", commit: "02")
                    ),
                GetSingleVersionChangeLog(
                    "4.5.6",
                    null,
                    GetChangeLogEntry(summary: "Entry1", commit: "03"),
                    GetChangeLogEntry(summary: "Entry2", commit: "04")
                    )
            };

            // ACT
            var result = await sut.RunAsync(changeLog);

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);
            var entries = changeLog.ChangeLogs.SelectMany(x => x.AllEntries).ToArray();

            Assert.All(entries, entry =>
            {
                Assert.NotNull(entry.CommitWebUri);
                var expectedUri = new Uri($"https://example.com/{entry.Commit}");
                Assert.Equal(expectedUri, entry.CommitWebUri);

                m_GitHubCommitsClientMock.Verify(x => x.Get("owner", "repo", entry.Commit.Id), Times.Once);
            });

            m_GitHubCommitsClientMock.Verify(x => x.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(entries.Length));
        }
示例#3
0
        public async Task Run_does_nothing_if_repository_does_not_have_remotes()
        {
            // ARRANGE
            var repoMock = new Mock <IGitRepository>(MockBehavior.Strict);

            repoMock.SetupEmptyRemotes();

            var sut       = new GitHubLinkTask(m_Logger, m_DefaultConfiguration, repoMock.Object, m_GitHubClientFactoryMock.Object);
            var changeLog = new ApplicationChangeLog();

            // ACT
            var result = await sut.RunAsync(changeLog);

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Skipped, result);
            m_GitHubClientFactoryMock.Verify(x => x.CreateClient(It.IsAny <string>()), Times.Never);
        }
示例#4
0
        public async Task Run_ignores_footers_which_cannot_be_parsed(string footerText)
        {
            // ARRANGE
            var repoMock = new Mock <IGitRepository>(MockBehavior.Strict);

            repoMock.Setup(x => x.Remotes).Returns(new[] { new GitRemote("origin", "http://github.com/owner/repo.git") });

            m_GitHubCommitsClientMock
            .Setup(x => x.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(
                (string owner, string repo, string sha) => Task.FromResult <GitHubCommit>(new TestGitHubCommit($"https://example.com/{sha}"))
                );

            var sut = new GitHubLinkTask(m_Logger, repoMock.Object, m_GitHubClientFactoryMock.Object);

            var changeLog = new ApplicationChangeLog()
            {
                GetSingleVersionChangeLog(
                    "1.2.3",
                    null,
                    GetChangeLogEntry(summary: "Entry1", commit: "01", footers: new []
                {
                    new ChangeLogEntryFooter(new CommitMessageFooterName("Irrelevant"), footerText),
                })
                    )
            };

            // ACT
            var result = await sut.RunAsync(changeLog);

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);

            var entries = changeLog.ChangeLogs.SelectMany(x => x.AllEntries).ToArray();

            Assert.All(entries, entry =>
            {
                Assert.All(entry.Footers, footer =>
                {
                    Assert.Null(footer.WebUri);
                });
            });

            m_GitHubIssuesClientMock.Verify(x => x.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()), Times.Never);
            m_GitHubPullRequestsClient.Verify(x => x.Get(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()), Times.Never);
        }
示例#5
0
        public async Task Run_does_nothing_if_remote_url_cannot_be_parsed(string url)
        {
            // ARRANGE
            var repoMock = new Mock <IGitRepository>(MockBehavior.Strict);

            repoMock.Setup(x => x.Remotes).Returns(new[] { new GitRemote("origin", url) });

            var sut       = new GitHubLinkTask(m_Logger, repoMock.Object, m_GitHubClientFactoryMock.Object);
            var changeLog = new ApplicationChangeLog();

            // ACT
            var result = await sut.RunAsync(changeLog);

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Skipped, result);
            m_GitHubClientFactoryMock.Verify(x => x.CreateClient(It.IsAny <string>()), Times.Never);
        }
示例#6
0
        public async Task Run_creates_client_through_client_factory(string hostName)
        {
            // ARRANGE
            var repoMock = new Mock <IGitRepository>(MockBehavior.Strict);

            repoMock.Setup(x => x.Remotes).Returns(new[] { new GitRemote("origin", $"http://{hostName}/owner/repo.git") });

            var sut = new GitHubLinkTask(m_Logger, repoMock.Object, m_GitHubClientFactoryMock.Object);

            // ACT
            var result = await sut.RunAsync(new ApplicationChangeLog());

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);

            m_GitHubClientFactoryMock.Verify(x => x.CreateClient(It.IsAny <string>()), Times.Once);
            m_GitHubClientFactoryMock.Verify(x => x.CreateClient(hostName), Times.Once);
        }
示例#7
0
        public async Task Run_does_nothing_if_remote_url_cannot_be_parsed(string remoteName, string url)
        {
            // ARRANGE
            var configuration = ChangeLogConfigurationLoader.GetDefaultConfiguration();

            configuration.Integrations.GitHub.RemoteName = remoteName;

            var repoMock = new Mock <IGitRepository>(MockBehavior.Strict);

            repoMock.SetupRemotes(remoteName, url);

            var sut       = new GitHubLinkTask(m_Logger, configuration, repoMock.Object, m_GitHubClientFactoryMock.Object);
            var changeLog = new ApplicationChangeLog();

            // ACT
            var result = await sut.RunAsync(changeLog);

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Skipped, result);
            m_GitHubClientFactoryMock.Verify(x => x.CreateClient(It.IsAny <string>()), Times.Never);
        }