From 0f8d01e17d70695334ef308a7c65846c07836cfe Mon Sep 17 00:00:00 2001 From: sfoslund Date: Wed, 22 Jan 2020 14:13:27 -0800 Subject: [PATCH] Fixing and adding test coverage for preview issue between requirement divisions --- .../BundleInfo/Versioning/BundleVersion.cs | 5 ++++ .../VisualStudioSafeVersionsExtractor.cs | 3 +- .../Shared/VSVersioning/VSVersionTests.cs | 28 +++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) 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 7125c465..12370f6b 100644 --- a/test/dotnet-core-uninstall.Tests/Shared/VSVersioning/VSVersionTests.cs +++ b/test/dotnet-core-uninstall.Tests/Shared/VSVersioning/VSVersionTests.cs @@ -280,15 +280,37 @@ internal void TestUninstallableStringsCorrectManySDKs() strings.Count.Should().Be(bundles.Count); var expectedProtected = new string[]{ "3.0.100", "2.0.4" }; + AssertRequirementStringsCorrect(bundles, strings, expectedProtected); + } + + [Fact] + 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); - strings.Where(pair => pair.Key.Version is SdkVersion) + bundleStringPairs.Where(pair => pair.Key.Version is SdkVersion) .Where(pair => string.IsNullOrEmpty(pair.Value)) .Select(pair => pair.Key.DisplayName) .Should().BeEquivalentTo(expectedUninstallable); - - strings.Where(pair => !string.IsNullOrEmpty(pair.Value)) + + bundleStringPairs.Where(pair => !string.IsNullOrEmpty(pair.Value)) .Select(pair => pair.Key.DisplayName) .Should().BeEquivalentTo(expectedProtected); }