Beispiel #1
0
        public void ParseRangeString_should_parse_valid_ranges()
        {
            // Arrange
            var rules = new Dictionary <string, Tuple <SemanticVersion, SemanticVersion> >
            {
                {
                    "1.0",
                    new Tuple <SemanticVersion, SemanticVersion>(
                        SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0)),
                        SemanticVersionRange.Inclusive(SemanticVersion.MaxValue))
                },
                {
                    "(,1.0]",
                    new Tuple <SemanticVersion, SemanticVersion>(
                        SemanticVersionRange.Exclusive(SemanticVersion.Unspecified),
                        SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0)))
                },
                {
                    "(,1.0)",
                    new Tuple <SemanticVersion, SemanticVersion>(
                        SemanticVersionRange.Exclusive(SemanticVersion.Unspecified),
                        SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0)))
                },
                {
                    "[1.0]",
                    new Tuple <SemanticVersion, SemanticVersion>(
                        SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0)),
                        SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0)))
                },
                {
                    "(1.0,)",
                    new Tuple <SemanticVersion, SemanticVersion>(
                        SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0)),
                        SemanticVersionRange.Exclusive(SemanticVersion.MaxValue))
                },
                {
                    "(1.0,2.0)",
                    new Tuple <SemanticVersion, SemanticVersion>(
                        SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0)),
                        SemanticVersionRange.Exclusive(new SemanticVersion(2, 0, 0)))
                },
                {
                    "[1.0,2.0]",
                    new Tuple <SemanticVersion, SemanticVersion>(
                        SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0)),
                        SemanticVersionRange.Inclusive(new SemanticVersion(2, 0, 0)))
                }
            };

            foreach (var rule in rules)
            {
                // Act
                var actual = SemanticVersionRange.ParseRangeString(rule.Key);

                // Assert
                actual.Item1.Should().Be(rule.Value.Item1);
                actual.Item2.Should().Be(rule.Value.Item2);
            }
        }
Beispiel #2
0
        public void ExclusiveVersion_CompareTo_should_return_positive_value()
        {
            // Arrange
            var version = SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0));

            // Act
            // Assert
            version.CompareTo(new SemanticVersion(0, 9, 0)).Should().BeGreaterThan(0);
        }
Beispiel #3
0
        public void Parse_should_return_parsed_range()
        {
            // Arrange
            var expected = new SemanticVersionRange("1.0");

            // Act
            var actual = SemanticVersionRange.Parse("1.0");

            // Assert
            actual.Should().Be(expected);
        }
Beispiel #4
0
        public void TryParse_should_return_false_and_assign_result()
        {
            // Arrange
            SemanticVersionRange result = null;

            // Act
            var actual = SemanticVersionRange.TryParse("1.0", out result);

            // Assert
            actual.Should().BeTrue();
            result.Should().Be(new SemanticVersionRange("1.0"));
        }
Beispiel #5
0
        public void Compare_should_return_true_for_values_in_range()
        {
            // Arrange
            var rules = new List <Tuple <SemanticVersionRange, SemanticVersion> >
            {
                new Tuple <SemanticVersionRange, SemanticVersion>(
                    new SemanticVersionRange(SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0)),
                                             SemanticVersionRange.Inclusive(SemanticVersion.MaxValue)),
                    new SemanticVersion(1, 0, 0)
                    ),
                new Tuple <SemanticVersionRange, SemanticVersion>(
                    new SemanticVersionRange(SemanticVersionRange.Exclusive(SemanticVersion.Unspecified),
                                             SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0))),
                    new SemanticVersion(1, 0, 0)
                    ),
                new Tuple <SemanticVersionRange, SemanticVersion>(
                    new SemanticVersionRange(SemanticVersionRange.Exclusive(SemanticVersion.Unspecified),
                                             SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0))),
                    new SemanticVersion(0, 9, 0)
                    ),
                new Tuple <SemanticVersionRange, SemanticVersion>(
                    new SemanticVersionRange(SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0)),
                                             SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0))),
                    new SemanticVersion(1, 0, 0)
                    ),
                new Tuple <SemanticVersionRange, SemanticVersion>(
                    new SemanticVersionRange(SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0)),
                                             SemanticVersionRange.Inclusive(SemanticVersion.MaxValue)),
                    new SemanticVersion(1, 1, 0)
                    ),
                new Tuple <SemanticVersionRange, SemanticVersion>(
                    new SemanticVersionRange(SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0)),
                                             SemanticVersionRange.Exclusive(new SemanticVersion(2, 0, 0))),
                    new SemanticVersion(1, 5, 0)
                    ),
                new Tuple <SemanticVersionRange, SemanticVersion>(
                    new SemanticVersionRange(SemanticVersionRange.Inclusive(new SemanticVersion(1, 0, 0)),
                                             SemanticVersionRange.Inclusive(new SemanticVersion(2, 0, 0))),
                    new SemanticVersion(1, 0, 0)
                    )
            };

            foreach (var rule in rules)
            {
                // Act

                // Assert

                rule.Item1.Contains(rule.Item2).Should().BeTrue();
            }
        }
Beispiel #6
0
        public void ToString_should_render_proper_NuGet_style_range_strings()
        {
            // Arrange
            var formats = new[] { "1.0", "(,1.0]", "(,1.0)", "[1.0]", "(1.0,)", "(1.0,2.0)", "[1.0,2.0]" };

            foreach (var format in formats)
            {
                // Act
                var range = new SemanticVersionRange(format);

                // Assert
                var actual = range.ToString().Should().Be(format);
            }
        }
Beispiel #7
0
        public void TryParse_should_not_throw_and_returns_false()
        {
            // Arrange
            var values = new[] { null, string.Empty, " ", "asdasdasd" };
            SemanticVersionRange result = null;
            bool success = false;

            foreach (var value in values)
            {
                // Act
                Assert.DoesNotThrow(() => success = SemanticVersionRange.TryParse(value, out result));

                // Assert
                success.Should().BeFalse();
                result.Should().BeNull();
            }
        }
Beispiel #8
0
        public void ExclusiveVersion_CompareTo_should_return_negative_values()
        {
            // Arrange
            var version = (SemanticVersionRange.ExclusiveVersion)SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0));

            version.IsLowerBound = false;

            var a = (SemanticVersionRange.ExclusiveVersion)SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 0));

            a.IsLowerBound = false;

            var b = (SemanticVersionRange.ExclusiveVersion)SemanticVersionRange.Exclusive(new SemanticVersion(1, 0, 1));

            b.IsLowerBound = false;

            // Act
            // Assert
            version.CompareTo(a).Should().BeLessThan(0);
            version.CompareTo(b).Should().BeLessThan(0);
        }
        /// <summary>
        ///     Attempts to safely parse a <see cref="SemanticVersionRange" /> from a string.
        /// </summary>
        /// <param name="range">The range.</param>
        /// <param name="result">
        ///     The resulting <see cref="SemanticVersionRange" />.
        /// </param>
        /// <returns>
        ///     True if <paramref name="range" /> is successfully parsed and the value assigned to <paramref name="result" />; otherwise, false.
        /// </returns>
        public static bool TryParse(string range, out SemanticVersionRange result)
        {
            result = null;

            if (string.IsNullOrWhiteSpace(range))
            {
                return(false);
            }

            try
            {
                result = Parse(range);

                return(true);
            }
            catch
            {
                return(false);
            }
        }