/// <inheritdoc/>
 public override bool Match(ImplementationVersion version)
 {
     if (version == null)
     {
         throw new ArgumentNullException(nameof(version));
     }
     return((LowerInclusive == null || version >= LowerInclusive) &&
            (UpperExclusive == null || version < UpperExclusive));
 }
Esempio n. 2
0
        public void TestTemplateVariable()
        {
            var version = new ImplementationVersion("1-pre{var}");

            version.ContainsTemplateVariables.Should().BeTrue();
            version.ToString().Should().Be("1-pre{var}");

            version = new ImplementationVersion("{var}");
            version.ContainsTemplateVariables.Should().BeTrue();
            version.ToString().Should().Be("{var}");
        }
Esempio n. 3
0
        public void TestSort()
        {
            var sortedVersions = new[] { "0.1", "1", "1.0", "1.1", "1.2-pre", "1.2-pre1", "1.2-rc1", "1.2", "1.2-0", "1.2-post", "1.2-post1-pre", "1.2-post1", "1.2.1-pre", "1.2.1.4", "1.2.3", "1.2.10", "3" };

            for (int i = 0; i < sortedVersions.Length - 1; i++)
            {
                var v1 = new ImplementationVersion(sortedVersions[i]);
                var v2 = new ImplementationVersion(sortedVersions[i + 1]);
                v1.Should().BeLessThan(v2);
                v2.Should().BeGreaterThan(v1);
            }
        }
Esempio n. 4
0
        public void TestTryCreate()
        {
            var validVersions = new[] { "0.1", "1", "1.0", "1.1", "1.1-", "1.2-pre", "1.2-pre1", "1.2-rc1", "1.2", "1.2-0", "1.2--0", "1.2-post", "1.2-post1-pre", "1.2-post1", "1.2.1-pre", "1.2.1.4", "1.2.3", "1.2.10", "3" };

            foreach (string version in validVersions)
            {
                ImplementationVersion.TryCreate(version, out var result).Should().BeTrue(because: version);
                result !.ToString().Should().Be(version);
            }

            var invalidVersions = new[] { "", "a", "pre-1", "1.0-1post" };

            foreach (string version in invalidVersions)
            {
                ImplementationVersion.TryCreate(version, out _).Should().BeFalse(because: version);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Parses a string into a <see cref="VersionRange"/> part.
        /// </summary>
        /// <exception cref="FormatException"><paramref name="value"/> is not a valid version range string.</exception>
        public static VersionRangePart FromString(string value)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException(nameof(value));
            }
            #endregion

            if (value.Contains(".."))
            {
                string start        = value.GetLeftPartAtFirstOccurrence("..");
                var    startVersion = string.IsNullOrEmpty(start) ? null : new ImplementationVersion(start);

                ImplementationVersion?endVersion;
                string end = value.GetRightPartAtFirstOccurrence("..");
                if (string.IsNullOrEmpty(end))
                {
                    endVersion = null;
                }
                else
                {
                    if (!end.StartsWith("!"))
                    {
                        throw new FormatException(string.Format(Resources.VersionRangeEndNotExclusive, end));
                    }
                    endVersion = new ImplementationVersion(end.Substring(1));
                }

                return(new VersionRangePartRange(startVersion, endVersion));
            }
            else if (value.StartsWith("!"))
            {
                return(new VersionRangePartExclude(
                           new ImplementationVersion(value.Substring(1))));
            }
            else
            {
                return(new VersionRangePartExact(
                           new ImplementationVersion(value)));
            }
        }
Esempio n. 6
0
 /// <inheritdoc/>
 public override bool Match(ImplementationVersion version) => !Version.Equals(version ?? throw new ArgumentNullException(nameof(version)));
Esempio n. 7
0
 /// <summary>
 /// Creates a new version exclusion.
 /// </summary>
 /// <param name="version">The version to be excluded.</param>
 public VersionRangePartExclude(ImplementationVersion version)
 {
     Version = version ?? throw new ArgumentNullException(nameof(version));
 }
Esempio n. 8
0
 /// <summary>
 /// Determines whether a specific version lies within this range.
 /// </summary>
 public abstract bool Match(ImplementationVersion version);