コード例 #1
0
ファイル: WixFileTests.cs プロジェクト: tknerr/GitVersion
        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.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 vars   = VariableProvider.GetVariablesFor(semVer, config, false);

            StringBuilder   log    = new StringBuilder();
            Action <string> action = s => log.AppendLine(s);

            Logger.SetLoggers(action, action, action, action);
            using (var wixVersionFileUpdater = new WixVersionFileUpdater(workingDir, vars, fileSystem))
            {
                wixVersionFileUpdater.Update();
            }

            fileSystem.ReadAllText(WixVersionFileUpdater.GetWixVersionFileName()).
            ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved")));
        }
コード例 #2
0
    public void ShouldReplaceAssemblyVersionWhenCreatingVisualBasicAssemblyVersionFileAndEnsureAssemblyInfo()
    {
        var fileSystem = new TestFileSystem();
        var version    = new SemanticVersion
        {
            BuildMetaData = new SemanticVersionBuildMetaData(3, "foo", "hash", DateTimeOffset.Now),
            Major         = 2,
            Minor         = 3,
            Patch         = 1
        };

        const string workingDir       = "C:\\Testing";
        const string assemblyInfoFile = @"AssemblyVersion(""1.0.0.0"");
AssemblyInformationalVersion(""1.0.0.0"");
AssemblyFileVersion(""1.0.0.0"");";

        fileSystem.WriteAllText("C:\\Testing\\AssemblyInfo.vb", assemblyInfoFile);
        var variable = VariableProvider.GetVariablesFor(version, new TestEffectiveConfiguration(), false);
        var args     = new Arguments
        {
            EnsureAssemblyInfo         = true,
            UpdateAssemblyInfo         = true,
            UpdateAssemblyInfoFileName = new HashSet <string> {
                "AssemblyInfo.vb"
            }
        };

        using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem))
        {
            const string expected = @"AssemblyVersion(""2.3.1.0"");
AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");
AssemblyFileVersion(""2.3.1.0"");";
            fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.vb").ShouldBe(expected);
        }
    }
コード例 #3
0
    static void AssertVariablesAreWrittenToFile(string f)
    {
        var writes          = new List <string>();
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "beta1",
            BuildMetaData = "5"
        };

        semanticVersion.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
        semanticVersion.BuildMetaData.Sha        = "commitSha";

        var config = new TestEffectiveConfiguration();

        var variables = VariableProvider.GetVariablesFor(semanticVersion, config, false);

        var j = new Jenkins(f);

        j.WriteIntegration(writes.Add, variables);

        writes[1].ShouldBe("1.2.3-beta.1+5");

        File.Exists(f).ShouldBe(true);

        var props = File.ReadAllText(f);

        props.ShouldContain("GitVersion_Major=1");
        props.ShouldContain("GitVersion_Minor=2");
    }
コード例 #4
0
    static void VerifyAssemblyVersion(ICompiler compiler, AssemblyVersioningScheme avs, string assemblyInformationalFormat = null)
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 2,
            Minor         = 3,
            Patch         = 4,
            PreReleaseTag = "beta.5",
            BuildMetaData = new SemanticVersionBuildMetaData(6,
                                                             "master", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z")),
        };

        var config = new TestEffectiveConfiguration(assemblyVersioningScheme: avs, assemblyInformationalFormat: assemblyInformationalFormat);

        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
        var assemblyInfoText = compiler.Builder.GetAssemblyInfoText(versionVariables, "Fake");

        assemblyInfoText.ShouldMatchApproved(c => c.UseCallerLocation().SubFolder(compiler.ApprovedSubFolder));

        var compilation = compiler.Compile(assemblyInfoText);

        var emitResult = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
コード例 #5
0
    private static void VerifyAssemblyInfoFile(
        string assemblyFileContent,
        string fileName,
        AssemblyVersioningScheme versioningScheme     = AssemblyVersioningScheme.MajorMinorPatch,
        Action <IFileSystem, VersionVariables> verify = null)
    {
        var fileSystem = Substitute.For <IFileSystem>();
        var version    = new SemanticVersion
        {
            BuildMetaData = new SemanticVersionBuildMetaData(3, "foo", "hash", DateTimeOffset.Now),
            Major         = 2,
            Minor         = 3,
            Patch         = 1
        };

        fileSystem.Exists(fileName).Returns(true);
        fileSystem.ReadAllText(fileName).Returns(assemblyFileContent);
        fileSystem.When(f => f.WriteAllText(fileName, Arg.Any <string>())).Do(c =>
        {
            assemblyFileContent = c.ArgAt <string>(1);
            fileSystem.ReadAllText(fileName).Returns(assemblyFileContent);
        });

        var config    = new TestEffectiveConfiguration(assemblyVersioningScheme: versioningScheme);
        var variables = VariableProvider.GetVariablesFor(version, config, false);

        verify(fileSystem, variables);
    }
コード例 #6
0
    public void VerifyCreatedCode()
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                                                             "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();
        var versionVariables    = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false);
        var assemblyInfoText    = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables);

        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.dll")
                          .WithOptions(new CSharpCompilationOptions(OutputKind.NetModule))
                          .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                          .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));


        var emitResult = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
        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 variableProvider = new VariableProvider(new NullLog());
            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)));
        }
コード例 #8
0
 public override bool Execute()
 {
     try
     {
         SemanticVersion versionAndBranch;
         if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch))
         {
             var thisType  = typeof(GetVersion);
             var variables = VariableProvider.GetVariablesFor(versionAndBranch);
             foreach (var variable in variables)
             {
                 thisType.GetProperty(variable.Key).SetValue(this, variable.Value, null);
             }
         }
         return(true);
     }
     catch (WarningException errorException)
     {
         logger.LogWarning(errorException.Message);
         return(true);
     }
     catch (Exception exception)
     {
         logger.LogError("Error occurred: " + exception);
         return(false);
     }
     finally
     {
         Logger.Reset();
     }
 }
コード例 #9
0
    static void VerifyAssemblyVersion(AssemblyVersioningScheme avs, string assemblyInformationalFormat = null)
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 2,
            Minor         = 3,
            Patch         = 4,
            PreReleaseTag = "beta.5",
            BuildMetaData = new SemanticVersionBuildMetaData(6,
                                                             "master", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z")),
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();


        var config = new TestEffectiveConfiguration(assemblyVersioningScheme: avs, assemblyInformationalFormat: assemblyInformationalFormat);

        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, "Fake");

        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.dll")
                          .WithOptions(new CSharpCompilationOptions(OutputKind.NetModule))
                          .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                          .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        var emitResult = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
コード例 #10
0
    public void VerifyCreatedCode_NoNamespaceConflict()
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                                                             "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var assemblyInfoBuilder = new AssemblyInfoBuilder();

        var config = new TestEffectiveConfiguration();

        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
        var assemblyInfoText = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, "Fake.System");

        Approvals.Verify(assemblyInfoText);

        var compilation = CSharpCompilation.Create("Fake.System.dll")
                          .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
                          .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                          .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText));

        var emitResult = compilation.Emit(new MemoryStream());

        Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));
    }
コード例 #11
0
    public void VerifyCreatedCode([ValueSource("compilers")] ICompiler compiler)
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5,
                                                             "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };

        var config = new TestEffectiveConfiguration();

        var versionVariables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
        var assemblyInfoText = compiler.Builder.GetAssemblyInfoText(versionVariables, "Fake");

        assemblyInfoText.ShouldMatchApproved(c => c.SubFolder(compiler.ApprovedSubFolder));

        var compilation = compiler.Compile(assemblyInfoText);

        using (var stream = new MemoryStream())
        {
            var emitResult = compilation.Emit(stream);

            Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor)));

            stream.Seek(0, SeekOrigin.Begin);
            var assembly = Assembly.Load(stream.ToArray());
            VerifyGitVersionInformationAttribute(assembly, versionVariables);
        }
    }
コード例 #12
0
    public void ShouldCreateAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInfo(string fileExtension)
    {
        var fileSystem       = new TestFileSystem();
        var workingDir       = Path.GetTempPath();
        var assemblyInfoFile = new HashSet <string>
        {
            "AssemblyInfo." + fileExtension,
            Path.Combine("src", "Project", "Properties", "VersionAssemblyInfo." + fileExtension)
        };
        var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);
        var arguments = new Arguments
        {
            EnsureAssemblyInfo         = true,
            UpdateAssemblyInfo         = true,
            UpdateAssemblyInfoFileName = assemblyInfoFile
        };

        using (new AssemblyInfoFileUpdate(arguments, workingDir, variables, fileSystem))
        {
            foreach (var item in assemblyInfoFile)
            {
                var fullPath = Path.Combine(workingDir, item);
                fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension)));
            }
        }
    }
コード例 #13
0
        public void InnerExecute()
        {
            Tuple <CachedVersion, GitVersionContext> result;
            var gitDirectory = GitDirFinder.TreeWalkForDotGitDir(SolutionDirectory);

            if (gitDirectory == null)
            {
                throw new DirectoryNotFoundException(string.Format("Unable to locate a git repository in \"{0}\". Make sure that the solution is located in a git controlled folder. If you are using continous integration make sure that the sources are checked out on the build agent.", SolutionDirectory));
            }

            var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem);

            if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, configuration, NoFetch))
            {
                return;
            }

            var authentication = new Authentication();

            var cachedVersion            = result.Item1;
            var gitVersionContext        = result.Item2;
            var config                   = gitVersionContext.Configuration;
            var assemblyVersioningScheme = config.AssemblyVersioningScheme;
            var versioningMode           = config.VersioningMode;

            var variablesFor = VariableProvider.GetVariablesFor(
                cachedVersion.SemanticVersion, assemblyVersioningScheme, versioningMode,
                config.ContinuousDeploymentFallbackTag,
                gitVersionContext.IsCurrentCommitTagged);

            WriteIntegrationParameters(cachedVersion, BuildServerList.GetApplicableBuildServers(authentication), variablesFor);
        }
コード例 #14
0
    public void ShouldReplaceAssemblyVersionWithStar()
    {
        var fileSystem = Substitute.For <IFileSystem>();
        var version    = new SemanticVersion
        {
            BuildMetaData = new SemanticVersionBuildMetaData(3, "foo", "hash", DateTimeOffset.Now),
            Major         = 2,
            Minor         = 3,
            Patch         = 1
        };

        const string workingDir       = "C:\\Testing";
        const string assemblyInfoFile = @"AssemblyVersion(""1.0.0.*"");
AssemblyInformationalVersion(""1.0.0.*"");
AssemblyFileVersion(""1.0.0.*"");";

        fileSystem.Exists("C:\\Testing\\AssemblyInfo.cs").Returns(true);
        fileSystem.ReadAllText("C:\\Testing\\AssemblyInfo.cs").Returns(assemblyInfoFile);

        var config   = new TestEffectiveConfiguration(assemblyVersioningScheme: AssemblyVersioningScheme.MajorMinor);
        var variable = VariableProvider.GetVariablesFor(version, config, false);
        var args     = new Arguments
        {
            UpdateAssemblyInfo         = true,
            UpdateAssemblyInfoFileName = "AssemblyInfo.cs"
        };

        using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem))
        {
            const string expected = @"AssemblyVersion(""2.3.0.0"");
AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"");
AssemblyFileVersion(""2.3.1.0"");";
            fileSystem.Received().WriteAllText("C:\\Testing\\AssemblyInfo.cs", expected);
        }
    }
コード例 #15
0
        public void InnerExecute()
        {
            Tuple <CachedVersion, GitVersionContext> result;
            var gitDirectory  = GitDirFinder.TreeWalkForGitDir(SolutionDirectory);
            var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem);

            if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, configuration))
            {
                return;
            }

            var authentication = new Authentication();

            var cachedVersion            = result.Item1;
            var gitVersionContext        = result.Item2;
            var config                   = gitVersionContext.Configuration;
            var assemblyVersioningScheme = config.AssemblyVersioningScheme;
            var versioningMode           = config.VersioningMode;

            var variablesFor = VariableProvider.GetVariablesFor(
                cachedVersion.SemanticVersion, assemblyVersioningScheme, versioningMode,
                config.ContinuousDeploymentFallbackTag,
                gitVersionContext.IsCurrentCommitTagged);

            WriteIntegrationParameters(cachedVersion, BuildServerList.GetApplicableBuildServers(authentication), variablesFor);
        }
コード例 #16
0
        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;
            }
        }
コード例 #17
0
        public void AssemblyVersion(
            int major, int minor, int patch, string buildMetadata,
            AssemblyVersioningScheme versioningScheme, bool addNumberOfCommitsSinceTagOnMasterBranchToFileVersion,
            string version, string fileVersion)
        {
            var semVer = new SemanticVersion
            {
                Major         = major,
                Minor         = minor,
                Patch         = patch,
                BuildMetaData = buildMetadata
            };

            semVer.BuildMetaData.ReleaseDate = new ReleaseDate
            {
                OriginalCommitSha = "originalCommitSha",
                OriginalDate      = DateTimeOffset.Parse("2014-03-01 00:00:01Z"),
                CommitSha         = "commitSha",
                Date = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
            };

            var vars = VariableProvider.GetVariablesFor(semVer, versioningScheme, addNumberOfCommitsSinceTagOnMasterBranchToFileVersion);

            vars[VariableProvider.AssemblyVersion].ShouldBe(version);
            vars[VariableProvider.AssemblyFileVersion].ShouldBe(fileVersion);
        }
コード例 #18
0
        public override bool Execute()
        {
            try
            {
                CachedVersion versionAndBranch;
                var           gitDirectory  = GitDirFinder.TreeWalkForGitDir(SolutionDirectory);
                var           configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem);

                // TODO This should be covered by tests
                // Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag
                if (DevelopBranchTag != null)
                {
                    configuration.DevelopBranchTag = DevelopBranchTag;
                }

                if (ReleaseBranchTag != null)
                {
                    configuration.ReleaseBranchTag = ReleaseBranchTag;
                }

                if (TagPrefix != null)
                {
                    configuration.TagPrefix = TagPrefix;
                }

                if (NextVersion != null)
                {
                    configuration.NextVersion = NextVersion;
                }

                if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, configuration))
                {
                    var thisType  = typeof(GetVersion);
                    var variables = VariableProvider.GetVariablesFor(versionAndBranch.SemanticVersion, configuration);
                    foreach (var variable in variables)
                    {
                        thisType.GetProperty(variable.Key).SetValue(this, variable.Value, null);
                    }
                }
                return(true);
            }
            catch (WarningException errorException)
            {
                logger.LogWarning(errorException.Message);
                return(true);
            }
            catch (Exception exception)
            {
                logger.LogError("Error occurred: " + exception);
                return(false);
            }
            finally
            {
                Logger.Reset();
            }
        }
コード例 #19
0
    public void AssertFullSemver(string fullSemver, IRepository repository = null, string commitId = null)
    {
        var gitVersionContext = new GitVersionContext(repository ?? Repository, configuration, IsForTrackedBranchOnly, commitId);
        var executeGitVersion = ExecuteGitVersion(gitVersionContext);
        var variables         = VariableProvider.GetVariablesFor(executeGitVersion,
                                                                 gitVersionContext.Configuration.AssemblyVersioningScheme,
                                                                 gitVersionContext.Configuration.VersioningMode,
                                                                 gitVersionContext.Configuration.ContinuousDeploymentFallbackTag,
                                                                 gitVersionContext.IsCurrentCommitTagged);

        variables.FullSemVer.ShouldBe(fullSemver);
    }
コード例 #20
0
    public void ShouldStartSearchFromWorkingDirectory()
    {
        var          fileSystem = Substitute.For <IFileSystem>();
        const string workingDir = "C:\\Testing";
        var          variables  = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false);

        using (new AssemblyInfoFileUpdate(new Arguments {
            UpdateAssemblyInfo = true
        }, workingDir, variables, fileSystem))
        {
            fileSystem.Received().DirectoryGetFiles(Arg.Is(workingDir), Arg.Any <string>(), Arg.Any <SearchOption>());
        }
    }
コード例 #21
0
        public ExecutionResults ExecuteGitVersion(bool inProcess = true)
        {
            if (!inProcess)
            {
                return(GitVersionHelper.ExecuteIn(RepositoryPath));
            }

            var vf = new GitVersionFinder();
            var sv = vf.FindVersion(new GitVersionContext(Repository));

            var vars = VariableProvider.GetVariablesFor(sv);

            return(new InProcessExecutionResults(vars));
        }
コード例 #22
0
    public void ShouldStartSearchFromWorkingDirectory()
    {
        var fileSystem        = Substitute.For <IFileSystem>();
        var workingDir        = Path.GetTempPath();
        var assemblyInfoFiles = new HashSet <string>();
        var variables         = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);

        using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFiles, workingDir, variables, fileSystem, false))
        {
            assemblyInfoFileUpdater.Update();

            fileSystem.Received().DirectoryGetFiles(Arg.Is(workingDir), Arg.Any <string>(), Arg.Any <SearchOption>());
        }
    }
コード例 #23
0
    public void ShouldNotCreateAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo(string fileExtension)
    {
        var fileSystem       = new TestFileSystem();
        var workingDir       = Path.GetTempPath();
        var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension;
        var fullPath         = Path.Combine(workingDir, assemblyInfoFile);
        var variables        = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);

        using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, false))
        {
            assemblyInfoFileUpdater.Update();

            fileSystem.Exists(fullPath).ShouldBeFalse();
        }
    }
コード例 #24
0
    public void ShouldNotCreateAssemblyInfoFileForUnknownSourceCodeAndEnsureAssemblyInfo()
    {
        var fileSystem       = Substitute.For <IFileSystem>();
        var workingDir       = Path.GetTempPath();
        var assemblyInfoFile = "VersionAssemblyInfo.js";
        var fullPath         = Path.Combine(workingDir, assemblyInfoFile);
        var variables        = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);

        using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, true))
        {
            assemblyInfoFileUpdater.Update();

            fileSystem.Received(0).WriteAllText(fullPath, Arg.Any <string>());
        }
    }
コード例 #25
0
    public void Json()
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5, "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var variables = VariableProvider.GetVariablesFor(semanticVersion, new Config());
        var json      = JsonOutputFormatter.ToJson(variables);

        Approvals.Verify(json);
    }
コード例 #26
0
    public void ShouldStartSearchFromWorkingDirectory()
    {
        var          fileSystem = Substitute.For <IFileSystem>();
        const string workingDir = "C:\\Testing";

        var config    = new TestEffectiveConfiguration();
        var variables = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), config, false);

        using (new AssemblyInfoFileUpdate(new Arguments {
            UpdateAssemblyInfo = true
        }, workingDir, variables, fileSystem))
        {
            fileSystem.Received().DirectoryGetFiles(Arg.Is(workingDir), Arg.Any <string>(), Arg.Any <SearchOption>());
        }
    }
コード例 #27
0
    public void ShouldCreateAssemblyInfoFileAtPathWhenNotExistsAndEnsureAssemblyInfo(string fileExtension)
    {
        var fileSystem       = new TestFileSystem();
        var workingDir       = Path.GetTempPath();
        var assemblyInfoFile = Path.Combine("src", "Project", "Properties", "VersionAssemblyInfo." + fileExtension);
        var fullPath         = Path.Combine(workingDir, assemblyInfoFile);
        var variables        = VariableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false);

        using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, true))
        {
            assemblyInfoFileUpdater.Update();

            fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension)));
        }
    }
コード例 #28
0
    public void Json()
    {
        var semanticVersion = new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            PreReleaseTag = "unstable4",
            BuildMetaData = new SemanticVersionBuildMetaData(5, "feature1", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        };
        var variables = VariableProvider.GetVariablesFor(semanticVersion, AssemblyVersioningScheme.MajorMinorPatch, VersioningMode.ContinuousDelivery, "ci", false);
        var json      = JsonOutputFormatter.ToJson(variables);

        Approvals.Verify(json);
    }
コード例 #29
0
    public void OutputsShouldMatchVariableProvider()
    {
        var taskType   = typeof(GetVersion);
        var properties = taskType.GetProperties()
                         .Where(p => p.GetCustomAttributes(typeof(OutputAttribute), false).Any())
                         .Select(p => p.Name);
        var variables = VariableProvider.GetVariablesFor(new SemanticVersion
        {
            Major         = 1,
            Minor         = 2,
            Patch         = 3,
            BuildMetaData = new SemanticVersionBuildMetaData(5, "develop", "commitSha", DateTimeOffset.Parse("2014-03-06 23:59:59Z"))
        }).Keys;

        CollectionAssert.AreEquivalent(properties, variables);
    }
コード例 #30
0
    public VersionVariables GetVersion(IRepository repository = null, string commitId = null)
    {
        var gitVersionContext = new GitVersionContext(repository ?? Repository, 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;
        }
    }