diff --git a/src/dotnet-core-uninstall/Shared/BundleInfo/Bundle.cs b/src/dotnet-core-uninstall/Shared/BundleInfo/Bundle.cs index b65eeabf..c2394dfd 100644 --- a/src/dotnet-core-uninstall/Shared/BundleInfo/Bundle.cs +++ b/src/dotnet-core-uninstall/Shared/BundleInfo/Bundle.cs @@ -53,7 +53,7 @@ public override string ToString() } } - internal class Bundle : Bundle, IComparable, IComparable>, IEquatable> + internal class Bundle : Bundle, IComparable, IComparable, IEquatable> where TBundleVersion: BundleVersion, IComparable { public new TBundleVersion Version => base.Version as TBundleVersion; @@ -64,10 +64,10 @@ public Bundle(TBundleVersion version, BundleArch arch, string uninstallCommand, public int CompareTo(object obj) { - return CompareTo(obj as Bundle); + return CompareTo(obj as Bundle); } - public int CompareTo(Bundle other) + public int CompareTo(Bundle other) { if (other == null) { @@ -76,7 +76,7 @@ public int CompareTo(Bundle other) return Version.Equals(other.Version) ? Arch - other.Arch : - Version.CompareTo(other.Version); + Version.SemVer.CompareTo(other.Version.SemVer); } public static IEnumerable> FilterWithSameBundleType(IEnumerable bundles) diff --git a/src/dotnet-core-uninstall/Shared/BundleInfo/Versioning/BundleVersion.cs b/src/dotnet-core-uninstall/Shared/BundleInfo/Versioning/BundleVersion.cs index 4cb6bd5b..cb86990f 100644 --- a/src/dotnet-core-uninstall/Shared/BundleInfo/Versioning/BundleVersion.cs +++ b/src/dotnet-core-uninstall/Shared/BundleInfo/Versioning/BundleVersion.cs @@ -93,5 +93,10 @@ public override int GetHashCode() } public abstract Bundle ToBundle(BundleArch arch, string uninstallCommand, string displayName); + + public SemanticVersion GetVersionWithoutTags() + { + return new SemanticVersion(this.Major, this.Minor, this.SemVer.Patch); + } } } diff --git a/src/dotnet-core-uninstall/Shared/VSVersioning/VisualStudioSafeVersionsExtractor.cs b/src/dotnet-core-uninstall/Shared/VSVersioning/VisualStudioSafeVersionsExtractor.cs index 488388ef..7a9c0d45 100644 --- a/src/dotnet-core-uninstall/Shared/VSVersioning/VisualStudioSafeVersionsExtractor.cs +++ b/src/dotnet-core-uninstall/Shared/VSVersioning/VisualStudioSafeVersionsExtractor.cs @@ -30,7 +30,8 @@ private static (IDictionary, string>, IEnumerable) A var dividedBundles = new Dictionary, string>(); foreach (var (division, explaination) in WindowsVersionDivisionsToExplaination) { - var bundlesInRange = bundleList.Where(bundle => bundle.Version is SdkVersion && division.Item1 <= bundle.Version.SemVer && bundle.Version.SemVer < division.Item2); + var bundlesInRange = bundleList.Where(bundle => bundle.Version is SdkVersion && + division.Item1 <= bundle.Version.GetVersionWithoutTags() && bundle.Version.GetVersionWithoutTags() < division.Item2); bundleList = bundleList.Except(bundlesInRange); if (bundlesInRange.Count() > 0) { diff --git a/test/dotnet-core-uninstall.Tests/Shared/VSVersioning/VSVersionTests.cs b/test/dotnet-core-uninstall.Tests/Shared/VSVersioning/VSVersionTests.cs index 0a0bea2e..ceb8bf15 100644 --- a/test/dotnet-core-uninstall.Tests/Shared/VSVersioning/VSVersionTests.cs +++ b/test/dotnet-core-uninstall.Tests/Shared/VSVersioning/VSVersionTests.cs @@ -259,5 +259,60 @@ private string[] ExpandExpectationShortHand(string[] input) return output; } + + [WindowsOnlyFact] + internal void TestUninstallableStringsCorrectManySDKs() + { + var bundles = new List + { + new Bundle(new SdkVersion("3.0.100-preview-0"), BundleArch.X64, string.Empty, "3.0.100"), + new Bundle(new RuntimeVersion("2.0.0"), BundleArch.X64, string.Empty, "2.0.0"), + }; + + for (int i = 0; i < 5; i++) + { + bundles.Add(new Bundle(new SdkVersion("2.0." + i), BundleArch.X64, string.Empty, "2.0." + i)); + bundles.Add(new Bundle(new SdkVersion("2.0." + i + "-preview-0"), BundleArch.X64, string.Empty, "2.0." + i + "-preview-0")); + bundles.Add(new Bundle(new SdkVersion("2.0." + i + "-preview-1"), BundleArch.X64, string.Empty, "2.0." + i + "-preview-1")); + } + + var strings = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(bundles); + strings.Count.Should().Be(bundles.Count); + + var expectedProtected = new string[]{ "3.0.100", "2.0.4" }; + AssertRequirementStringsCorrect(bundles, strings, expectedProtected); + } + + [WindowsOnlyFact] + internal void TestUninstallableStringsCorrectAcrossRequirementDivisions() + { + var bundles = new List + { + new Bundle(new SdkVersion("2.0.0"), BundleArch.X64, string.Empty, "2.0.0"), + new Bundle(new SdkVersion("2.0.0-preview-0"), BundleArch.X64, string.Empty, "2.0.0-preview-0"), + new Bundle(new SdkVersion("2.0.0-preview-1"), BundleArch.X64, string.Empty, "2.0.0-preview-1") + }; + + var strings = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(bundles); + var expectedProtected = new string[] { "2.0.0" }; + AssertRequirementStringsCorrect(bundles, strings, expectedProtected); + } + + private void AssertRequirementStringsCorrect(List bundles, Dictionary bundleStringPairs, string[] expectedProtected) + { + bundleStringPairs.Count.Should().Be(bundles.Count); + + var expectedUninstallable = bundles.Select(bundle => bundle.DisplayName) + .Except(expectedProtected); + + bundleStringPairs.Where(pair => pair.Key.Version is SdkVersion) + .Where(pair => string.IsNullOrEmpty(pair.Value)) + .Select(pair => pair.Key.DisplayName) + .Should().BeEquivalentTo(expectedUninstallable); + + bundleStringPairs.Where(pair => !string.IsNullOrEmpty(pair.Value)) + .Select(pair => pair.Key.DisplayName) + .Should().BeEquivalentTo(expectedProtected); + } } }