예제 #1
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.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")));
        }
    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");
        assemblyInfoText.ShouldMatchApproved();

        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)));
    }
    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");
    }
    public void ShouldAddAssemblyVersionIfMissingFromInfoFile()
    {
        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 assemblyInfoFileContent = @"";

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

        var config = new TestEffectiveConfiguration(assemblyVersioningScheme: AssemblyVersioningScheme.MajorMinor);

        var variable = VariableProvider.GetVariablesFor(version, config, false);
        var args = new Arguments
        {
            UpdateAssemblyInfo = true,
            UpdateAssemblyInfoFileName = new HashSet<string> { "AssemblyInfo.cs" }
        };

        using (new AssemblyInfoFileUpdate(args, workingDir, variable, fileSystem))
        {
            const string expected = @"
        [assembly: AssemblyVersion(""2.3.0.0"")]
        [assembly: AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")]
        [assembly: AssemblyFileVersion(""2.3.1.0"")]";
            fileSystem.Received().WriteAllText("C:\\Testing\\AssemblyInfo.cs", expected);
        }
    }
        private void VerifyAssemblyInfoFile(
            string assemblyFileContent,
            string fileName,
            AssemblyVersioningScheme versioningScheme     = AssemblyVersioningScheme.MajorMinorPatch,
            Action <IFileSystem, VersionVariables> verify = null)
        {
            fileSystem = Substitute.For <IFileSystem>();
            var version = new SemanticVersion
            {
                BuildMetaData = new SemanticVersionBuildMetaData("versionSourceHash", 3, "foo", "hash", "shortHash", DateTimeOffset.Now, 0),
                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?.Invoke(fileSystem, variables);
        }
    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>());
        }
    }
예제 #7
0
        public void ProvidesVariableshWithCustomAssemblyInfoFormatSupportingAnySpecialCharcter()
        {
            var semVer = new SemanticVersion();
            var textWithSpecialCharacters = @"+ -=#![]^&@$%:<>/\-çñáÁ统";
            var config = new TestEffectiveConfiguration(
                assemblyInformationalFormat: $"Special characters: {textWithSpecialCharacters}",
                assemblyInformationalIsSemver: false
                );

            var vars = variableProvider.GetVariablesFor(semVer, config, false);

            vars.InformationalVersion.ShouldContain(textWithSpecialCharacters);
        }
예제 #8
0
        public void ShouldLogWarningWhenUsingDefaultInformationalVersionInCustomFormat()
        {
            var semVer = new SemanticVersion
            {
                Major = 1,
                Minor = 2,
                Patch = 3,
            };

            var propertyName = nameof(SemanticVersionFormatValues.DefaultInformationalVersion);
            var config       = new TestEffectiveConfiguration(assemblyInformationalFormat: $"{{{propertyName}}}");

            variableProvider.GetVariablesFor(semVer, config, false);
            logMessages.ShouldContain(message => message.Trim().StartsWith("WARN") && message.Contains(propertyName), 1, $"Expected a warning to be logged when using the variable {propertyName} in a configuration format template");
        }
예제 #9
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")));
        }
    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 config = new TestEffectiveConfiguration();

        var variables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
        var json = JsonOutputFormatter.ToJson(variables);
        Approvals.Verify(json);
    }
        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 variables = VariableProvider.GetVariablesFor(semanticVersion, config, false);
            var json      = JsonOutputFormatter.ToJson(variables);

            json.ShouldMatchApproved(c => c.SubFolder("Approved"));
        }
예제 #12
0
    public void ProvidesVariablesInContinuousDeliveryModeForStable()
    {
        var semVer = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            BuildMetaData = "5.Branch.develop"
        };

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

        var config = new TestEffectiveConfiguration();

        var vars = VariableProvider.GetVariablesFor(semVer, config, false);

        JsonOutputFormatter.ToJson(vars).ShouldMatchApproved(c => c.SubFolder("Approved"));
    }
    public void ProvidesVariablesInContinuousDeploymentModeForPreRelease()
    {
        var semVer = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            PreReleaseTag = "unstable.4",
            BuildMetaData = "5.Branch.develop"
        };

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

        var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment);

        var vars = VariableProvider.GetVariablesFor(semVer, config, false);

        JsonOutputFormatter.ToJson(vars).ShouldMatchApproved();
    }
예제 #14
0
        public void ProvidesVariablesInContinuousDeploymentModeWithTagSetToUseBranchName()
        {
            var semVer = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                BuildMetaData = "5.Branch.develop"
            };

            semVer.BuildMetaData.Branch     = "feature";
            semVer.BuildMetaData.Sha        = "commitSha";
            semVer.BuildMetaData.ShortSha   = "commitShortSha";
            semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");

            var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tag: "useBranchName");
            var vars   = variableProvider.GetVariablesFor(semVer, config, false);

            vars.FullSemVer.ShouldBe("1.2.3-feature.5");
        }
예제 #15
0
    public void ProvidesVariablesInContinuousDeliveryModeForPreReleaseWithPadding()
    {
        var semVer = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            PreReleaseTag = "unstable.4",
            BuildMetaData = "5.Branch.develop"
        };

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

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

        var vars = VariableProvider.GetVariablesFor(semVer, config, false);

        Approvals.Verify(JsonOutputFormatter.ToJson(vars));
    }
예제 #16
0
        public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern()
        {
            var semVer = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                PreReleaseTag = "PullRequest",
                BuildMetaData = "5.Branch.develop"
            };

            semVer.BuildMetaData.Branch     = "pull/2/merge";
            semVer.BuildMetaData.Sha        = "commitSha";
            semVer.BuildMetaData.ShortSha   = "commitShortSha";
            semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");

            var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tagNumberPattern: @"[/-](?<number>\d+)[-/]");
            var vars   = variableProvider.GetVariablesFor(semVer, config, false);

            vars.FullSemVer.ShouldBe("1.2.3-PullRequest0002.5");
        }
예제 #17
0
        public void ProvidesVariablesInContinuousDeploymentModeForStable()
        {
            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("2014-03-06 23:59:59Z");

            var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment);

            var vars = variableProvider.GetVariablesFor(semVer, config, false);

            vars.ToString().ShouldMatchApproved(c => c.SubFolder("Approved"));
        }
    public void BuildNumberIsFullSemVer()
    {
        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);
        new BuildServer().WriteIntegration(writes.Add, variables);

        writes[1].ShouldBe("1.2.3-beta.1+5");
    }
예제 #19
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")));
        }
예제 #20
0
        public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranch()
        {
            var semVer = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                BuildMetaData = "5.Branch.feature/123"
            };

            semVer.BuildMetaData.Branch           = "feature/123";
            semVer.BuildMetaData.VersionSourceSha = "versionSourceSha";
            semVer.BuildMetaData.Sha        = "commitSha";
            semVer.BuildMetaData.ShortSha   = "commitShortSha";
            semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");


            var config = new TestEffectiveConfiguration();

            var vars = variableProvider.GetVariablesFor(semVer, config, false);

            JsonOutputFormatter.ToJson(vars).ShouldMatchApproved(c => c.SubFolder("Approved"));
        }
예제 #21
0
        public void ProvidesVariablesInContinuousDeliveryModeForPreReleaseWithPadding()
        {
            var semVer = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                PreReleaseTag = "unstable.4",
                BuildMetaData = "5.Branch.develop"
            };

            semVer.BuildMetaData.VersionSourceSha = "versionSourceSha";
            semVer.BuildMetaData.Sha        = "commitSha";
            semVer.BuildMetaData.ShortSha   = "commitShortSha";
            semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");


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

            var vars = variableProvider.GetVariablesFor(semVer, config, false);

            vars.ToString().ShouldMatchApproved(c => c.SubFolder("Approved"));
        }
예제 #22
0
        public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomAssemblyInformationalFormat()
        {
            var semVer = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                BuildMetaData = "5.Branch.feature/123"
            };

            semVer.BuildMetaData.Branch           = "feature/123";
            semVer.BuildMetaData.VersionSourceSha = "versionSourceSha";
            semVer.BuildMetaData.Sha        = "commitSha";
            semVer.BuildMetaData.ShortSha   = "commitShortSha";
            semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");


            var config = new TestEffectiveConfiguration(assemblyInformationalFormat: "{Major}.{Minor}.{Patch}+{CommitsSinceVersionSource}.Branch.{BranchName}.Sha.{ShortSha}");

            var vars = variableProvider.GetVariablesFor(semVer, config, false);

            vars.ToString().ShouldMatchApproved(c => c.SubFolder("Approved"));
        }
예제 #23
0
        public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged()
        {
            var semVer = new SemanticVersion
            {
                Major         = 1,
                Minor         = 2,
                Patch         = 3,
                BuildMetaData =
                {
                    VersionSourceSha          = "versionSourceSha",
                    CommitsSinceTag           =                  5,
                    CommitsSinceVersionSource =                  5,
                    Sha        = "commitSha",
                    ShortSha   = "commitShortSha",
                    CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
                }
            };

            var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment);

            var vars = variableProvider.GetVariablesFor(semVer, config, true);

            vars.ToString().ShouldMatchApproved(c => c.SubFolder("Approved"));
        }
예제 #24
0
        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"));
        }
    public void VerifyCreatedCode_NoNamespaceConflict([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.System");
        assemblyInfoText.ShouldMatchApproved(c => c.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)));
    }
    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)));
    }
    public void ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged()
    {
        var semVer = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            BuildMetaData =
            {
                CommitsSinceTag = 5,
                CommitsSinceVersionSource = 5,
                Sha = "commitSha",
                CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z")
            }
        };

        var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment);

        var vars = VariableProvider.GetVariablesFor(semVer, config, true);

        JsonOutputFormatter.ToJson(vars).ShouldMatchApproved();
    }
예제 #28
0
    public void ProvidesVariablesInContinuousDeploymentModeWithTagNamePattern()
    {
        var semVer = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            PreReleaseTag = "PullRequest",
            BuildMetaData = "5.Branch.develop"
        };

        semVer.BuildMetaData.Branch = "pull/2/merge";
        semVer.BuildMetaData.Sha = "commitSha";
        semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");

        var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tagNumberPattern: @"[/-](?<number>\d+)[-/]");
        var vars = VariableProvider.GetVariablesFor(semVer, config, false);

        vars.FullSemVer.ShouldBe("1.2.3-PullRequest0002.5");
    }
예제 #29
0
    public void ProvidesVariablesInContinuousDeploymentModeWithTagSetToUseBranchName()
    {
        var semVer = new SemanticVersion
        {
            Major = 1,
            Minor = 2,
            Patch = 3,
            BuildMetaData = "5.Branch.develop"
        };

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

        var config = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, tag: "useBranchName");
        var vars = VariableProvider.GetVariablesFor(semVer, config, false);

        vars.FullSemVer.ShouldBe("1.2.3-feature.5");
    }
    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);
    }
    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)));
    }