Esempio n. 1
0
        public void NoWarnOnGitVersionYmlFile()
        {
            SetupConfigFileContent(string.Empty);

            var stringLogger = string.Empty;

            void Action(string info) => stringLogger = info;

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            var options = Options.Create(new Arguments {
                TargetPath = repoPath
            });
            var sp = ConfigureServices(services =>
            {
                services.AddSingleton(options);
                services.AddSingleton <ILog>(log);
            });

            configProvider = sp.GetService <IConfigProvider>();

            configProvider.Provide(repoPath);

            stringLogger.Length.ShouldBe(0);
        }
Esempio n. 2
0
        public void CacheFileIsMissing()
        {
            var stringBuilder = new StringBuilder();

            void Action(string s) => stringBuilder.AppendLine(s);

            var logAppender = new TestLogAppender(Action);

            log = new Log(logAppender);

            using var fixture = new EmptyRepositoryFixture();

            var arguments = new Arguments {
                TargetPath = fixture.RepositoryPath
            };

            var gitVersionCalculator = GetGitVersionCalculator(arguments, log);

            fixture.Repository.MakeACommit();
            _ = gitVersionCalculator.CalculateVersionVariables();

            var logsMessages = stringBuilder.ToString();

            logsMessages.ShouldContain("yml not found", () => logsMessages);
        }
Esempio n. 3
0
        public void CacheFileIsMissing()
        {
            var stringBuilder = new StringBuilder();

            void Action(string s) => stringBuilder.AppendLine(s);

            var logAppender = new TestLogAppender(Action);

            log = new Log(logAppender);

            using var fixture = new EmptyRepositoryFixture();

            var gitVersionOptions = new GitVersionOptions {
                WorkingDirectory = fixture.RepositoryPath
            };

            fixture.Repository.MakeACommit();
            var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions, log, fixture.Repository);

            gitVersionCalculator.CalculateVersionVariables();

            var logsMessages = stringBuilder.ToString();

            logsMessages.ShouldContain("yml not found", Case.Insensitive, logsMessages);
        }
        private string WithDefaultConfigFileLocator(Action <IConfigFileLocator> action)
        {
            var stringLogger = string.Empty;

            void Action(string info) => stringLogger = info;

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            var configFileLocator = new DefaultConfigFileLocator(fileSystem, log);

            action(configFileLocator);

            return(stringLogger);
        }
Esempio n. 5
0
        public void UsernameWithoutPassword()
        {
            var s = string.Empty;

            void Action(string info) => s = info;

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            const string repoUrl = "http://[email protected]/DefaultCollection/_git/CAS";

            log.Info(repoUrl);

            s.Contains(repoUrl).ShouldBe(true);
        }
Esempio n. 6
0
        public void LoggerObscuresPassword(string protocol)
        {
            const string username = "******";
            const string password = "******";
            var          s        = string.Empty;

            void Action(string info) => s = info;

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            log.Info($"{protocol}://{username}:{password}@workspace.visualstudio.com/DefaultCollection/_git/CAS");

            s.Contains(password).ShouldBe(false);
        }
        public void CacheFileIsMissing()
        {
            var stringBuilder = new StringBuilder();

            void Action(string s) => stringBuilder.AppendLine(s);

            var logAppender = new TestLogAppender(Action);

            log             = new Log(logAppender);
            gitVersionCache = new GitVersionCache(fileSystem, log);

            RepositoryScope();
            var logsMessages = stringBuilder.ToString();

            logsMessages.ShouldContain("yml not found", () => logsMessages);
        }
Esempio n. 8
0
        public void UpdateWixVersionFileWhenFileAlreadyExists()
        {
            var workingDir = Path.GetTempPath();
            var semVer     = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                BuildMetaData = "5.Branch.develop"
            };

            semVer.BuildMetaData.VersionSourceSha = "versionSourceSha";
            semVer.BuildMetaData.Sha        = "commitSha";
            semVer.BuildMetaData.ShortSha   = "commitShortSha";
            semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2019-02-20 23:59:59Z");

            var config = new TestEffectiveConfiguration(buildMetaDataPadding: 2, legacySemVerPadding: 5);

            var stringBuilder = new StringBuilder();

            void Action(string s) => stringBuilder.AppendLine(s);

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            var sp = ConfigureServices(service =>
            {
                service.AddSingleton <ILog>(log);
            });

            var fileSystem       = sp.GetService <IFileSystem>();
            var variableProvider = sp.GetService <IVariableProvider>();
            var versionVariables = variableProvider.GetVariablesFor(semVer, config, false);

            using var wixVersionFileUpdater = sp.GetService <IWixVersionFileUpdater>();

            // fake an already existing file
            var file = Path.Combine(workingDir, WixVersionFileUpdater.WixVersionFileName);

            fileSystem.WriteAllText(file, new string('x', 1024 * 1024));

            wixVersionFileUpdater.Execute(versionVariables, new WixVersionContext(workingDir));

            fileSystem
            .ReadAllText(file)
            .ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved")));
        }
Esempio n. 9
0
        public void NoWarnOnGitVersionYmlFile()
        {
            SetupConfigFileContent(string.Empty);

            var stringLogger = string.Empty;

            void Action(string info) => stringLogger = info;

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log);

            ConfigurationProvider.Provide(repoPath, defaultConfigFileLocator);

            stringLogger.Length.ShouldBe(0);
        }
        public void NoWarnOnCustomYmlFileOutsideRepoPath()
        {
            var stringLogger = string.Empty;

            void Action(string info) => stringLogger = info;

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            var sp = GetServiceProvider(arguments, log);

            configFileLocator = sp.GetService <IConfigFileLocator>();
            fileSystem        = sp.GetService <IFileSystem>();

            SetupConfigFileContent(string.Empty, path: @"c:\\Unrelated\\path");

            var configurationProvider = sp.GetService <IConfigProvider>();

            configurationProvider.Provide(repoPath);
            stringLogger.Length.ShouldBe(0);
        }
Esempio n. 11
0
        public void NoWarnOnCustomYmlFile()
        {
            var stringLogger = string.Empty;

            void Action(string info) => stringLogger = info;

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            var sp = GetServiceProvider(gitVersionOptions, log);

            configFileLocator = sp.GetService <IConfigFileLocator>();
            fileSystem        = sp.GetService <IFileSystem>();

            SetupConfigFileContent(string.Empty);

            var configurationProvider = sp.GetService <IConfigProvider>();

            configurationProvider.Provide(repoPath);
            stringLogger.Length.ShouldBe(0);
        }
Esempio n. 12
0
        public void NoWarnOnGitVersionYmlFile()
        {
            SetupConfigFileContent(string.Empty);

            var stringLogger = string.Empty;

            void Action(string info) => stringLogger = info;

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            var defaultConfigFileLocator = new DefaultConfigFileLocator(fileSystem, log);
            var gitPreparer = new GitPreparer(log, environment, Options.Create(new Arguments {
                TargetPath = repoPath
            }));

            configProvider = new ConfigProvider(fileSystem, log, defaultConfigFileLocator, gitPreparer, configInitWizard);

            configProvider.Provide(repoPath);

            stringLogger.Length.ShouldBe(0);
        }
Esempio n. 13
0
        public void NoWarnOnCustomYmlFileOutsideRepoPath()
        {
            SetupConfigFileContent(string.Empty, path: @"c:\\Unrelated\\path");

            var stringLogger = string.Empty;

            void Action(string info) => stringLogger = info;

            var logAppender = new TestLogAppender(Action);

            log = new Log(logAppender);

            configFileLocator = new NamedConfigFileLocator(fileSystem, log, options);
            var gitPreparer = new GitPreparer(log, new TestEnvironment(), Options.Create(new Arguments {
                TargetPath = repoPath
            }));
            var configInitWizard      = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
            var configurationProvider = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);

            configurationProvider.Provide(repoPath);
            stringLogger.Length.ShouldBe(0);
        }
Esempio n. 14
0
        public void UpdateWixVersionFile()
        {
            var fileSystem = new TestFileSystem();
            var workingDir = Path.GetTempPath();
            var semVer     = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                BuildMetaData = "5.Branch.develop"
            };

            semVer.BuildMetaData.VersionSourceSha = "versionSourceSha";
            semVer.BuildMetaData.Sha        = "commitSha";
            semVer.BuildMetaData.ShortSha   = "commitShortSha";
            semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2019-02-20 23:59:59Z");

            var config = new TestEffectiveConfiguration(buildMetaDataPadding: 2, legacySemVerPadding: 5);

            var stringBuilder = new StringBuilder();

            void Action(string s) => stringBuilder.AppendLine(s);

            var logAppender = new TestLogAppender(Action);
            var log         = new Log(logAppender);

            var metaDataCalculator        = new MetaDataCalculator();
            var baseVersionCalculator     = new BaseVersionCalculator(log, null);
            var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator);
            var variableProvider          = new VariableProvider(nextVersionCalculator, new TestEnvironment());
            var vars = variableProvider.GetVariablesFor(semVer, config, false);

            using var wixVersionFileUpdater = new WixVersionFileUpdater(workingDir, vars, fileSystem, log);
            wixVersionFileUpdater.Update();
            fileSystem.ReadAllText(wixVersionFileUpdater.WixVersionFile).
            ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved")));
        }
Esempio n. 15
0
        public void CacheFileExistsOnDisk()
        {
            const string versionCacheFileContent = @"
        Major: 4
        Minor: 10
        Patch: 3
        PreReleaseTag: test.19
        PreReleaseTagWithDash: -test.19
        PreReleaseLabel: test
        PreReleaseLabelWithDash: -test
        PreReleaseNumber: 19
        WeightedPreReleaseNumber: 19
        BuildMetaData:
        BuildMetaDataPadded:
        FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
        MajorMinorPatch: 4.10.3
        SemVer: 4.10.3-test.19
        LegacySemVer: 4.10.3-test19
        LegacySemVerPadded: 4.10.3-test0019
        AssemblySemVer: 4.10.3.0
        AssemblySemFileVer: 4.10.3.0
        FullSemVer: 4.10.3-test.19
        InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
        BranchName: feature/test
        EscapedBranchName: feature-test
        Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
        ShortSha: dd2a29af
        NuGetVersionV2: 4.10.3-test0019
        NuGetVersion: 4.10.3-test0019
        NuGetPreReleaseTagV2: test0019
        NuGetPreReleaseTag: test0019
        VersionSourceSha: 4.10.2
        CommitsSinceVersionSource: 19
        CommitsSinceVersionSourcePadded: 0019
        CommitDate: 2015-11-10
        UncommittedChanges: 0
        ";

            var stringBuilder = new StringBuilder();

            void Action(string s) => stringBuilder.AppendLine(s);

            var logAppender = new TestLogAppender(Action);

            log = new Log(logAppender);

            using var fixture = new EmptyRepositoryFixture();
            fixture.Repository.MakeACommit();

            var gitVersionOptions = new GitVersionOptions {
                WorkingDirectory = fixture.RepositoryPath
            };

            var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions, log);

            var versionVariables = gitVersionCalculator.CalculateVersionVariables();

            versionVariables.AssemblySemVer.ShouldBe("0.1.0.0");

            fileSystem.WriteAllText(versionVariables.FileName, versionCacheFileContent);
            versionVariables = gitVersionCalculator.CalculateVersionVariables();
            versionVariables.AssemblySemVer.ShouldBe("4.10.3.0");

            var logsMessages = stringBuilder.ToString();

            logsMessages.ShouldContain("Deserializing version variables from cache file", Case.Insensitive, logsMessages);
        }
        public void CacheFileExistsOnDisk()
        {
            const string versionCacheFileContent = @"
        Major: 4
        Minor: 10
        Patch: 3
        PreReleaseTag: test.19
        PreReleaseTagWithDash: -test.19
        PreReleaseLabel: test
        PreReleaseNumber: 19
        WeightedPreReleaseNumber: 19
        BuildMetaData:
        BuildMetaDataPadded:
        FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
        MajorMinorPatch: 4.10.3
        SemVer: 4.10.3-test.19
        LegacySemVer: 4.10.3-test19
        LegacySemVerPadded: 4.10.3-test0019
        AssemblySemVer: 4.10.3.0
        AssemblySemFileVer: 4.10.3.0
        FullSemVer: 4.10.3-test.19
        InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
        BranchName: feature/test
        Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
        ShortSha: dd2a29af
        NuGetVersionV2: 4.10.3-test0019
        NuGetVersion: 4.10.3-test0019
        NuGetPreReleaseTagV2: test0019
        NuGetPreReleaseTag: test0019
        VersionSourceSha: 4.10.2
        CommitsSinceVersionSource: 19
        CommitsSinceVersionSourcePadded: 0019
        CommitDate: 2015-11-10
        ";

            var stringBuilder = new StringBuilder();

            void Action(string s) => stringBuilder.AppendLine(s);

            var logAppender = new TestLogAppender(Action);

            log = new Log(logAppender);

            gitVersionCache = new GitVersionCache(fileSystem, log);

            RepositoryScope(log, (fixture, vv) =>
            {
                fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);

                var arguments = new Arguments {
                    TargetPath = fixture.RepositoryPath
                };
                var gitVersionCalculator = GetGitVersionCalculator(arguments);

                vv = gitVersionCalculator.CalculateVersionVariables();
                vv.AssemblySemVer.ShouldBe("4.10.3.0");
            });

            var logsMessages = stringBuilder.ToString();

            logsMessages.ShouldContain("Deserializing version variables from cache file", () => logsMessages);
        }