/// <inheritdoc/> public override bool Match(ImplementationVersion version) { if (version == null) { throw new ArgumentNullException(nameof(version)); } return((LowerInclusive == null || version >= LowerInclusive) && (UpperExclusive == null || version < UpperExclusive)); }
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}"); }
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); } }
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); } }
/// <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))); } }
/// <inheritdoc/> public override bool Match(ImplementationVersion version) => !Version.Equals(version ?? throw new ArgumentNullException(nameof(version)));
/// <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)); }
/// <summary> /// Determines whether a specific version lies within this range. /// </summary> public abstract bool Match(ImplementationVersion version);