Ejemplo n.º 1
0
        public async Task Task_replaces_commit_messages_with_messages_from_the_configured_directory(string?sourceDirectoryPath)
        {
            // ARRANGE
            using var repositoryDirectory = new TemporaryDirectory();

            var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();
            {
                config.RepositoryPath = repositoryDirectory;

                if (sourceDirectoryPath is not null)
                {
                    config.MessageOverrides.SourceDirectoryPath = sourceDirectoryPath;
                }
            }


            var commit1 = GetGitCommit(id: TestGitIds.Id1, commitMessage: "Original Message 1");
            var commit2 = GetGitCommit(id: TestGitIds.Id2, commitMessage: "Original Message 2");

            var repo = new Mock <IGitRepository>(MockBehavior.Strict);
            {
                repo.SetupTryGetCommit();
                repo.SetupTryGetCommit(commit1);
                repo.SetupTryGetCommit(commit2);
            }

            var versionChangeLog = GetSingleVersionChangeLog("1.2.3", TestGitIds.Id1);

            {
                versionChangeLog.Add(commit1);
                versionChangeLog.Add(commit2);
            }

            repositoryDirectory.AddFile(
                $"{sourceDirectoryPath ?? ".config/changelog/message-overrides"}/{commit2.Id.ToString(abbreviate: false)}",
                "Overridden Message 2");

            var sut = new LoadMessageOverridesFromFileSystemTask(m_Logger, config, repo.Object);

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

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);
            Assert.Collection(
                versionChangeLog.AllCommits,
                c => Assert.Equal(commit1, c),
                c => Assert.Equal(commit2.WithCommitMessage("Overridden Message 2"), c)
                );
        }
Ejemplo n.º 2
0
        public async Task Task_does_nothing_for_empty_changelog()
        {
            // ARRANGE
            var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();
            var repo   = new Mock <IGitRepository>(MockBehavior.Strict);

            var sut = new LoadMessageOverridesFromFileSystemTask(m_Logger, config, repo.Object);

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

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Skipped, result);
        }
Ejemplo n.º 3
0
        public async Task Task_fails_if_multiple_files_in_the_override_directory_resolve_to_the_same_commit()
        {
            // ARRANGE
            using var overrideDirectory = new TemporaryDirectory();

            var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();
            {
                config.MessageOverrides.SourceDirectoryPath = overrideDirectory;
            }

            var commit1 = GetGitCommit(id: TestGitIds.Id1, commitMessage: "Original Message 1");
            var commit2 = GetGitCommit(id: TestGitIds.Id2, commitMessage: "Original Message 2");

            var repo = new Mock <IGitRepository>(MockBehavior.Strict);
            {
                repo.SetupTryGetCommit();
                repo.SetupTryGetCommit(commit1);
                repo.SetupTryGetCommit(commit2);
            }

            var versionChangeLog = GetSingleVersionChangeLog("1.2.3", TestGitIds.Id1);

            {
                versionChangeLog.Add(commit1);
                versionChangeLog.Add(commit2);
            }

            overrideDirectory.AddFile(commit2.Id.ToString(abbreviate: true), "Overridden Message 2.1");
            overrideDirectory.AddFile(commit2.Id.ToString(abbreviate: false), "Overridden Message 2.2");

            var sut = new LoadMessageOverridesFromFileSystemTask(m_Logger, config, repo.Object);

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

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Error, result);
            Assert.Collection(
                versionChangeLog.AllCommits,
                c => Assert.Equal(commit1, c),
                c => Assert.Equal(commit2, c)
                );
        }
Ejemplo n.º 4
0
        public async Task Task_ignores_files_in_the_override_directory_if_the_commit_cannot_be_resolved()
        {
            // ARRANGE
            using var overrideDirectory = new TemporaryDirectory();

            var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();
            {
                config.MessageOverrides.SourceDirectoryPath = overrideDirectory;
            }

            var commit1 = GetGitCommit(id: TestGitIds.Id1, commitMessage: "Original Message 1");
            var commit2 = GetGitCommit(id: TestGitIds.Id2, commitMessage: "Original Message 2");

            var repo = new Mock <IGitRepository>(MockBehavior.Strict);
            {
                repo.SetupTryGetCommit();
                repo.SetupTryGetCommit(commit1);
                repo.SetupTryGetCommit(commit2);
            }

            var versionChangeLog = GetSingleVersionChangeLog("1.2.3", TestGitIds.Id1);

            {
                versionChangeLog.Add(commit1);
                versionChangeLog.Add(commit2);
            }

            overrideDirectory.AddFile("not-a-commit-id", "Some content");

            var sut = new LoadMessageOverridesFromFileSystemTask(m_Logger, config, repo.Object);

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

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);
            Assert.Collection(
                versionChangeLog.AllCommits,
                c => Assert.Equal(commit1, c),
                c => Assert.Equal(commit2, c)
                );
        }
Ejemplo n.º 5
0
        public async Task Task_succeeds_if_override_directory_does_not_exist(string sourceDirectoryPath)
        {
            // ARRANGE
            using var repositoryDirectory = new TemporaryDirectory();

            var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();
            {
                config.RepositoryPath = repositoryDirectory;
                config.MessageOverrides.SourceDirectoryPath = sourceDirectoryPath;
            }

            var commit1 = GetGitCommit(id: TestGitIds.Id1, commitMessage: "Original Message 1");
            var commit2 = GetGitCommit(id: TestGitIds.Id2, commitMessage: "Original Message 2");

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

            var versionChangeLog = GetSingleVersionChangeLog("1.2.3", TestGitIds.Id1);
            {
                versionChangeLog.Add(commit1);
                versionChangeLog.Add(commit2);
            }

            var sut = new LoadMessageOverridesFromFileSystemTask(m_Logger, config, repo.Object);

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

            // ASSERT
            Assert.Equal(ChangeLogTaskResult.Success, result);
            Assert.Collection(
                versionChangeLog.AllCommits,
                c => Assert.Equal(commit1, c),
                c => Assert.Equal(commit2, c)
                );
        }