Esempio n. 1
0
        public async Task Repository_path_can_be_passed_as_relative_path()
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();
            var repositoryPath = temporaryDirectory.AddSubDirectory("repo");

            var git = new GitWrapper(repositoryPath, m_TestOutputHelper);
            await git.InitAsync();

            await git.ConfigAsync("user.name", "Example");

            await git.ConfigAsync("user.email", "*****@*****.**");

            var commit = await git.CommitAsync("feat: Some New feature");

            await git.TagAsync("v1.0.0", commit);

            await Task.Delay(500);

            var expectedOutputPath = Path.Combine(repositoryPath, "changelog.md");

            // ACT
            var result = await RunApplicationAsync(
                args : new[] { "--repository", "repo" },
                workingDirectory : temporaryDirectory,
                commandId : nameof(Repository_path_can_be_passed_as_relative_path)
                );

            // ASSERT
            Assert.Equal(0, result.ExitCode);
            Assert.True(File.Exists(expectedOutputPath));
        }
Esempio n. 2
0
        public async Task The_expected_configuration_file_is_used(string[] configurationFilesOnDisk, string?configurationFileParameter, string expectedConfigurationFile)
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();

            var git = new GitWrapper(temporaryDirectory, m_TestOutputHelper);
            await git.InitAsync();

            await git.ConfigAsync("user.name", "Example");

            await git.ConfigAsync("user.email", "*****@*****.**");

            // Create all configuration files with distinct output path settings
            var outputNames = new Dictionary <string, string>();

            foreach (var configurationFilePath in configurationFilesOnDisk)
            {
                var outputName = $"{Guid.NewGuid()}.md";
                temporaryDirectory.AddFile(
                    configurationFilePath,
                    $@"{{ ""changelog"" : {{ ""outputPath"" : ""{outputName}"" }} }}"
                    );

                outputNames.Add(configurationFilePath, outputName);
            }

            // Determine the expected output path (based on the output path we can determine which configuration file was used).
            // If none of the configuration file is expected to be used (expectedConfigurationFile is null), expect the changelog to be written to the default location
            var expectedOutputPath = expectedConfigurationFile is null
                ? Path.Combine(temporaryDirectory, "changelog.md")
                : Path.Combine(temporaryDirectory, outputNames[expectedConfigurationFile]);

            var args = new List <string>()
            {
                "--verbose"
            };

            // When specified, append the configurationFilePath commandline parameter
            if (configurationFileParameter is not null)
            {
                args.Add("--configurationFilePath");
                args.Add(configurationFileParameter);
            }

            // ACT
            var result = await RunApplicationAsync(
                args : args,
                workingDirectory : temporaryDirectory,
                commandId : $"{nameof(The_expected_configuration_file_is_used)}([{String.Join(",", configurationFilesOnDisk)}], \"{configurationFileParameter}\", \"{expectedConfigurationFile}\")"
                );

            // ASSERT
            Assert.Equal(0, result.ExitCode);
            Assert.True(File.Exists(expectedOutputPath));
        }
Esempio n. 3
0
        public async Task When_no_repository_is_specified_the_repository_is_located_from_the_current_directory(string relativeWorkingDirectoryPath)
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();
            var workingDirectory = temporaryDirectory.AddSubDirectory(relativeWorkingDirectoryPath);

            var git = new GitWrapper(temporaryDirectory, m_TestOutputHelper);
            await git.InitAsync();

            await git.ConfigAsync("user.name", "Example");

            await git.ConfigAsync("user.email", "*****@*****.**");

            var commit = await git.CommitAsync("feat: Some New feature");

            await git.TagAsync("v1.0.0", commit);

            await Task.Delay(500);

            var expectedOutputPath = Path.Combine(temporaryDirectory, "changelog.md");
            var expectedOutput     = String.Join(Environment.NewLine,
                                                 "# Change Log",
                                                 "",
                                                 "## 1.0.0",
                                                 "",
                                                 $"#### <a id=\"changelog-heading-{commit.Id.Id}\"></a> Some New feature",
                                                 "",
                                                 $"- Commit: `{commit.Id.AbbreviatedId}`",
                                                 "");

            // ACT
            var result = await RunApplicationAsync(
                args : new[] { "--verbose" },
                workingDirectory : workingDirectory,
                commandId : $"{nameof(When_no_repository_is_specified_the_repository_is_located_from_the_current_directory)}(\"{relativeWorkingDirectoryPath}\")"
                );

            // ASSERT
            Assert.Equal(0, result.ExitCode);
            Assert.True(File.Exists(expectedOutputPath));
            Assert.Equal(expectedOutput, File.ReadAllText(expectedOutputPath));
        }
Esempio n. 4
0
        public async Task Change_log_is_generated_from_the_specified_repository()
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();

            var git = new GitWrapper(temporaryDirectory, m_TestOutputHelper);
            await git.InitAsync();

            await git.ConfigAsync("user.name", "Example");

            await git.ConfigAsync("user.email", "*****@*****.**");

            var commit = await git.CommitAsync("feat: Some New feature");

            await git.TagAsync("v1.0.0", commit);

            await Task.Delay(500);

            var expectedOutputPath = Path.Combine(temporaryDirectory, "changelog.md");
            var expectedOutput     = String.Join(Environment.NewLine,
                                                 "# Change Log",
                                                 "",
                                                 "## 1.0.0",
                                                 "",
                                                 $"#### <a id=\"changelog-heading-{commit.Id.Id}\"></a> Some New feature",
                                                 "",
                                                 $"- Commit: `{commit.Id.AbbreviatedId}`",
                                                 "");

            // ACT
            var result = await RunApplicationAsync(
                args : new[] { "--repository", temporaryDirectory },
                commandId : nameof(Change_log_is_generated_from_the_specified_repository)
                );

            // ASSERT
            Assert.Equal(0, result.ExitCode);
            Assert.True(File.Exists(expectedOutputPath));
            Assert.Equal(expectedOutput, File.ReadAllText(expectedOutputPath));
        }