public NextVersionCalculatorTests()
        {
            var metaDataCalculator = new MetaDataCalculator();

            log = new NullLog();
            mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);
        }
        public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool isForTrackedBranchOnly = true, string targetBranch = null)
        {
            if (configuration == null)
            {
                configuration = new Config();
                configuration.Reset();
            }

            var log = new NullLog();
            var metaDataCalculator        = new MetaDataCalculator();
            var baseVersionCalculator     = new TestBaseVersionStrategiesCalculator(log);
            var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator);
            var variableProvider          = new VariableProvider(nextVersionCalculator, new TestEnvironment());
            var gitVersionContext         = new GitVersionContext(repository ?? fixture.Repository, log, targetBranch, configuration, isForTrackedBranchOnly, commitId);
            var executeGitVersion         = ExecuteGitVersion(gitVersionContext);
            var variables = variableProvider.GetVariablesFor(executeGitVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged);

            try
            {
                return(variables);
            }
            catch (Exception)
            {
                Console.WriteLine("Test failing, dumping repository graph");
                gitVersionContext.Repository.DumpGraph();
                throw;
            }
        }
        public void ShouldCreateFile(string fileExtension)
        {
            var fileSystem = new TestFileSystem();
            var directory  = Path.GetTempPath();
            var fileName   = "GitVersionInformation.g." + fileExtension;
            var fullPath   = Path.Combine(directory, fileName);

            var semanticVersion = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                PreReleaseTag = "unstable4",
                BuildMetaData = new SemanticVersionBuildMetaData("versionSourceSha", 5,
                                                                 "feature1", "commitSha", "commitShortSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
            };

            var log = new NullLog();
            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 variables = variableProvider.GetVariablesFor(semanticVersion, new TestEffectiveConfiguration(), false);
            var generator = new GitVersionInformationGenerator(fileName, directory, variables, fileSystem);

            generator.Generate();

            fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension)));
        }
Beispiel #4
0
        public void Setup()
        {
            ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute <TestAttribute>();
            var log = new NullLog();
            var metaDataCalculator        = new MetaDataCalculator();
            var baseVersionCalculator     = new BaseVersionCalculator(log, null);
            var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator);

            variableProvider = new VariableProvider(nextVersionCalculator, new TestEnvironment());
        }
        public void SetUp()
        {
            environment = new TestEnvironment();
            log         = new NullLog();
            var metaDataCalculator        = new MetaDataCalculator();
            var baseVersionCalculator     = new BaseVersionCalculator(log, null);
            var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator);

            variableProvider = new VariableProvider(nextVersionCalculator, new TestEnvironment());
        }
        private static SemanticVersion ExecuteGitVersion(GitVersionContext context)
        {
            var log = new NullLog();
            var metadataCalculator        = new MetaDataCalculator();
            var baseVersionCalculator     = new TestBaseVersionStrategiesCalculator(log);
            var mainlineVersionCalculator = new MainlineVersionCalculator(log, metadataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(log, metadataCalculator, baseVersionCalculator, mainlineVersionCalculator);
            var vf = new GitVersionFinder(log, nextVersionCalculator);

            return(vf.FindVersion(context));
        }
 public void Setup()
 {
     _metaDataCalculator = new MetaDataCalculator();
     _listOfGuesses      = new List <AmountOfGuesses> {
         new(4, 2),
         new(4, 3),
         new(5, 3),
         new(5, 6),
         new(5, 8),
         new(6, 5),
         new(7, 6),
         new(8, 7)
     };
 }
        public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer)
        {
            var root             = Path.Combine(workDirectory, name);
            var dynamicDirectory = Path.Combine(root, "D"); // dynamic, keeping directory as short as possible
            var workingDirectory = Path.Combine(root, "W"); // working, keeping directory as short as possible
            var arguments        = new Arguments
            {
                TargetUrl = url,
                DynamicRepositoryLocation = dynamicDirectory,
                TargetBranch = targetBranch,
                NoFetch      = false,
                TargetPath   = workingDirectory,
                CommitId     = commitId
            };
            var options = Options.Create(arguments);

            Directory.CreateDirectory(dynamicDirectory);
            Directory.CreateDirectory(workingDirectory);

            var testFileSystem      = new TestFileSystem();
            var log                 = new NullLog();
            var configFileLocator   = new DefaultConfigFileLocator(testFileSystem, log);
            var gitVersionCache     = new GitVersionCache(testFileSystem, log);
            var buildServerResolver = new BuildServerResolver(null, log);

            var metadataCalculator        = new MetaDataCalculator();
            var baseVersionCalculator     = new TestBaseVersionStrategiesCalculator(log);
            var mainlineVersionCalculator = new MainlineVersionCalculator(log, metadataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(log, metadataCalculator, baseVersionCalculator, mainlineVersionCalculator);
            var gitVersionFinder          = new GitVersionFinder(log, nextVersionCalculator);

            var gitPreparer      = new GitPreparer(log, new TestEnvironment(), options);
            var stepFactory      = new ConfigInitStepFactory();
            var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);

            var configurationProvider = new ConfigProvider(testFileSystem, log, configFileLocator, gitPreparer, configInitWizard);

            var variableProvider     = new VariableProvider(nextVersionCalculator, new TestEnvironment());
            var gitVersionCalculator = new GitVersionCalculator(testFileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options);

            var versionVariables = gitVersionCalculator.CalculateVersionVariables();

            Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer);
        }
Beispiel #9
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")));
        }
        public void Json()
        {
            var semanticVersion = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 0,
                PreReleaseTag = "unstable4",
                BuildMetaData = new SemanticVersionBuildMetaData("versionSourceSha", 5, "feature1", "commitSha", "commitShortSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
            };

            var config = new TestEffectiveConfiguration();

            var log = new NullLog();
            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 variables = variableProvider.GetVariablesFor(semanticVersion, config, false);
            var json      = JsonOutputFormatter.ToJson(variables);

            json.ShouldMatchApproved(c => c.SubFolder("Approved"));
        }