public void Process_ValidVersions_SetsMembers(
            string version,
            string expectedVersion,
            int major,
            int minor,
            int patch,
            int revision)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Configuration =
                {
                    Version = version
                }
            };

            // Act
            _sut.Process(context);

            // Assert
            context.Result.Version.Should().Be(expectedVersion);
            context.Result.Major.Should().Be(major);
            context.Result.Minor.Should().Be(minor);
            context.Result.Patch.Should().Be(patch);
            context.Result.Revision.Should().Be(revision);
        }
Example #2
0
        public void Process_MetadataParts_NonRelease_Is_Formatted(
            string[] parts,
            string version,
            int height)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Configuration = GetRepositoryConfiguration(version, meta: parts),
                Result        = GetVersionResult(height, version, false)
            };

            string expected;

            if (parts.Length > 0)
            {
                expected = $"{version}-c{context.Result.Sha7}+{string.Join(".", parts)}";
            }
            else
            {
                expected = $"{version}-c{context.Result.Sha7}";
            }

            // Act
            _sut.Process(context);

            // Assert
            context.Result.Formats.Should().ContainKey("Semver2");
            context.Result.Formats["Semver2"].Should().Be(expected);
        }
        public void Height_In_Version(
            string version,
            string expectedVersion,
            int commits,
            int major,
            int minor,
            int patch,
            int revision)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Configuration =
                {
                    Version = version
                },
                Result =
                {
                    Height = commits
                }
            };

            // Act
            _sut.Process(context);

            // Assert
            context.Result.Version.Should().Be(expectedVersion);
            context.Result.Major.Should().Be(major);
            context.Result.Minor.Should().Be(minor);
            context.Result.Patch.Should().Be(patch);
            context.Result.Revision.Should().Be(revision);
        }
        public void Resolve_ReplacesToken2_IfNeeded(string input, string expected)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Result = GetVersionResult(10)
            };

            // Act
            var result = _sut.Resolve(context, input);

            // Assert
            result.Should().Be(expected);
        }
        public void Apply_AppendsToken_IfNeeded(bool isRelease, IEnumerable <string> input, IEnumerable <string> expected)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Configuration = GetRepositoryConfiguration("1.2.3"),
                Result        = GetVersionResult(10, release: isRelease)
            };

            // Act
            var result = _sut.Apply(context, input);

            // Assert
            result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering());
        }
        public void Apply_Appends_IfRequired(string version, IEnumerable <string> input, IEnumerable <string> expected)
        {
            // Arrange
            var sut     = new HeightTokenRule();
            var context = new MockVersionContext
            {
                Configuration =
                {
                    Version = version
                }
            };

            // Act
            var result = sut.Apply(context, input);

            // Assert
            result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering());
        }
        public void Resolve_ReplacesToken_IfNeeded(bool usePadding, int height, string input, string expected)
        {
            // Arrange
            var sut     = new HeightTokenRule(usePadding);
            var context = new MockVersionContext
            {
                Result =
                {
                    Height = height
                }
            };

            // Act
            var result = sut.Resolve(context, input);

            // Assert
            result.Should().Be(expected);
        }
        [InlineData("master", "{branchNameSuffix}", "[mr]", "aste")] // Ignore Spelling: mr,aste
        public void Resolve_CustomPattern_Replaces_BranchName(string branchName, string input, string pattern, string expected)
        {
            // Arrange
            var sut     = new BranchNameSuffixTokenRule(pattern);
            var context = new MockVersionContext
            {
                Result =
                {
                    CanonicalBranchName = branchName
                }
            };

            // Act
            var result = sut.Resolve(context, input);

            // Assert
            result.Should().Be(expected);
        }
Example #9
0
        public void Resolve_Replaces_BranchName(string branchName, string input, string expected)
        {
            // Arrange
            var sut     = new ShortBranchNameTokenRule();
            var context = new MockVersionContext
            {
                Result =
                {
                    BranchName = branchName
                }
            };

            // Act
            var result = sut.Resolve(context, input);

            // Assert
            result.Should().Be(expected);
        }
Example #10
0
        public void Resolve_ReplacesToken_IfNeeded(string input, int id, string expected)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Result =
                {
                    CanonicalBranchName = $"refs/pull/{id}/merge",
                    Height              = 10
                }
            };

            // Act
            var result = _sut.Resolve(context, input);

            // Assert
            result.Should().Be(expected);
        }
        public void Process_InvalidVersion_Throws(string version)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Configuration =
                {
                    Version = version
                }
            };

            // Act
            Action action = () => _sut.Process(context);

            // Asset
            action.Should().Throw <InvalidOperationException>()
            .WithMessage($"Version '{context.Configuration.Version}' is not in a valid format.");
        }
Example #12
0
        public void Apply_ReturnsInput()
        {
            // Arrange
            var context = new MockVersionContext
            {
                Configuration = GetRepositoryConfiguration("1.2.3"),
                Result        =
                {
                    Height = 10
                }
            };
            var input = new[] { "this", "will", "not", "change", "{pr}" };

            // Act
            var result = _sut.Apply(context, input);

            // Assert
            result.Should().BeEquivalentTo(input, options => options.WithStrictOrdering());
        }
        public void Process_LabelParts_Release_Is_Formatted(
            string[] parts,
            string version,
            int height,
            string expected)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Configuration = GetRepositoryConfiguration(version, label: parts),
                Result        = GetVersionResult(height, version, true)
            };

            // Act
            _sut.Process(context);

            // Assert
            context.Result.Formats.Should().ContainKey("Semver1");
            context.Result.Formats["Semver1"].Should().Be(expected);
        }
Example #14
0
        public void Process_LabelParts_NonRelease_Is_Formatted(
            string[] parts,
            string version,
            int height,
            string expectedPart)
        {
            // Arrange
            var context = new MockVersionContext
            {
                Configuration = GetRepositoryConfiguration(version, label: parts),
                Result        = GetVersionResult(height, version, false)
            };

            var divider      = parts.Length > 0 ? '.' : '-';
            var fullExpected = $"{expectedPart}{divider}c{context.Result.Sha7}";

            // Act
            _sut.Process(context);

            // Assert
            context.Result.Formats.Should().ContainKey("Semver2");
            context.Result.Formats["Semver2"].Should().Be(fullExpected);
        }