public void FindsGitDirectoryInParent()
        {
            var childDir = Path.Combine(workDirectory, "child");

            Directory.CreateDirectory(childDir);

            try
            {
                var arguments = new Arguments {
                    TargetPath = childDir, NoFetch = true
                };
                var options = Options.Create(arguments);

                var gitPreparer               = new GitPreparer(log, environment, options);
                var configurationProvider     = new ConfigProvider(testFileSystem, log, configFileLocator, gitPreparer, configInitWizard);
                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, environment);

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

                gitVersionCalculator.CalculateVersionVariables();
            }
            catch (Exception ex)
            {
                // TODO I think this test is wrong.. It throws a different exception
                // `RepositoryNotFoundException` means that it couldn't find the .git directory,
                // any other exception means that the .git was found but there was some other issue that this test doesn't care about.
                Assert.IsNotAssignableFrom <RepositoryNotFoundException>(ex);
            }
        }
        private void RepositoryScope(ILog log, Action <EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
        {
            // Make sure GitVersion doesn't trigger build server mode when we are running the tests
            environment.SetEnvironmentVariable(AppVeyor.EnvironmentVariableName, null);
            environment.SetEnvironmentVariable(TravisCi.EnvironmentVariableName, null);
            environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, null);

            using var fixture = new EmptyRepositoryFixture();

            var arguments = new Arguments {
                TargetPath = fixture.RepositoryPath
            };
            var options = Options.Create(arguments);

            var gitPreparer               = new GitPreparer(log, environment, options);
            var stepFactory               = new ConfigInitStepFactory();
            var configInitWizard          = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
            var configurationProvider     = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
            var baseVersionCalculator     = new BaseVersionCalculator(this.log, null);
            var mainlineVersionCalculator = new MainlineVersionCalculator(this.log, metaDataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(this.log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator);
            var variableProvider          = new VariableProvider(nextVersionCalculator, new TestEnvironment());
            var gitVersionCalculator      = new GitVersionCalculator(fileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options);

            fixture.Repository.MakeACommit();
            var vv = gitVersionCalculator.CalculateVersionVariables();

            vv.AssemblySemVer.ShouldBe("0.1.0.0");
            vv.FileName.ShouldNotBeNullOrEmpty();

            fixtureAction?.Invoke(fixture, vv);
        }
        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);
        }