Skip to content

Commit 36be3f8

Browse files
authored
Merge pull request #114 from sfoslund/FixingCompareIssue
Fixing comparer exception issue
2 parents 6fc40ba + e0f466c commit 36be3f8

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

src/dotnet-core-uninstall/Shared/BundleInfo/Bundle.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public override string ToString()
5353
}
5454
}
5555

56-
internal class Bundle<TBundleVersion> : Bundle, IComparable, IComparable<Bundle<TBundleVersion>>, IEquatable<Bundle<TBundleVersion>>
56+
internal class Bundle<TBundleVersion> : Bundle, IComparable, IComparable<Bundle>, IEquatable<Bundle<TBundleVersion>>
5757
where TBundleVersion: BundleVersion, IComparable<TBundleVersion>
5858
{
5959
public new TBundleVersion Version => base.Version as TBundleVersion;
@@ -64,10 +64,10 @@ public Bundle(TBundleVersion version, BundleArch arch, string uninstallCommand,
6464

6565
public int CompareTo(object obj)
6666
{
67-
return CompareTo(obj as Bundle<TBundleVersion>);
67+
return CompareTo(obj as Bundle);
6868
}
6969

70-
public int CompareTo(Bundle<TBundleVersion> other)
70+
public int CompareTo(Bundle other)
7171
{
7272
if (other == null)
7373
{
@@ -76,7 +76,7 @@ public int CompareTo(Bundle<TBundleVersion> other)
7676

7777
return Version.Equals(other.Version) ?
7878
Arch - other.Arch :
79-
Version.CompareTo(other.Version);
79+
Version.SemVer.CompareTo(other.Version.SemVer);
8080
}
8181

8282
public static IEnumerable<Bundle<TBundleVersion>> FilterWithSameBundleType(IEnumerable<Bundle> bundles)

src/dotnet-core-uninstall/Shared/BundleInfo/Versioning/BundleVersion.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,10 @@ public override int GetHashCode()
9393
}
9494

9595
public abstract Bundle ToBundle(BundleArch arch, string uninstallCommand, string displayName);
96+
97+
public SemanticVersion GetVersionWithoutTags()
98+
{
99+
return new SemanticVersion(this.Major, this.Minor, this.SemVer.Patch);
100+
}
96101
}
97102
}

src/dotnet-core-uninstall/Shared/VSVersioning/VisualStudioSafeVersionsExtractor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ private static (IDictionary<IEnumerable<Bundle>, string>, IEnumerable<Bundle>) A
3030
var dividedBundles = new Dictionary<IEnumerable<Bundle>, string>();
3131
foreach (var (division, explaination) in WindowsVersionDivisionsToExplaination)
3232
{
33-
var bundlesInRange = bundleList.Where(bundle => bundle.Version is SdkVersion && division.Item1 <= bundle.Version.SemVer && bundle.Version.SemVer < division.Item2);
33+
var bundlesInRange = bundleList.Where(bundle => bundle.Version is SdkVersion &&
34+
division.Item1 <= bundle.Version.GetVersionWithoutTags() && bundle.Version.GetVersionWithoutTags() < division.Item2);
3435
bundleList = bundleList.Except(bundlesInRange);
3536
if (bundlesInRange.Count() > 0)
3637
{

test/dotnet-core-uninstall.Tests/Shared/VSVersioning/VSVersionTests.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,60 @@ private string[] ExpandExpectationShortHand(string[] input)
259259

260260
return output;
261261
}
262+
263+
[WindowsOnlyFact]
264+
internal void TestUninstallableStringsCorrectManySDKs()
265+
{
266+
var bundles = new List<Bundle>
267+
{
268+
new Bundle<SdkVersion>(new SdkVersion("3.0.100-preview-0"), BundleArch.X64, string.Empty, "3.0.100"),
269+
new Bundle<RuntimeVersion>(new RuntimeVersion("2.0.0"), BundleArch.X64, string.Empty, "2.0.0"),
270+
};
271+
272+
for (int i = 0; i < 5; i++)
273+
{
274+
bundles.Add(new Bundle<SdkVersion>(new SdkVersion("2.0." + i), BundleArch.X64, string.Empty, "2.0." + i));
275+
bundles.Add(new Bundle<SdkVersion>(new SdkVersion("2.0." + i + "-preview-0"), BundleArch.X64, string.Empty, "2.0." + i + "-preview-0"));
276+
bundles.Add(new Bundle<SdkVersion>(new SdkVersion("2.0." + i + "-preview-1"), BundleArch.X64, string.Empty, "2.0." + i + "-preview-1"));
277+
}
278+
279+
var strings = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(bundles);
280+
strings.Count.Should().Be(bundles.Count);
281+
282+
var expectedProtected = new string[]{ "3.0.100", "2.0.4" };
283+
AssertRequirementStringsCorrect(bundles, strings, expectedProtected);
284+
}
285+
286+
[WindowsOnlyFact]
287+
internal void TestUninstallableStringsCorrectAcrossRequirementDivisions()
288+
{
289+
var bundles = new List<Bundle>
290+
{
291+
new Bundle<SdkVersion>(new SdkVersion("2.0.0"), BundleArch.X64, string.Empty, "2.0.0"),
292+
new Bundle<SdkVersion>(new SdkVersion("2.0.0-preview-0"), BundleArch.X64, string.Empty, "2.0.0-preview-0"),
293+
new Bundle<SdkVersion>(new SdkVersion("2.0.0-preview-1"), BundleArch.X64, string.Empty, "2.0.0-preview-1")
294+
};
295+
296+
var strings = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(bundles);
297+
var expectedProtected = new string[] { "2.0.0" };
298+
AssertRequirementStringsCorrect(bundles, strings, expectedProtected);
299+
}
300+
301+
private void AssertRequirementStringsCorrect(List<Bundle> bundles, Dictionary<Bundle, string> bundleStringPairs, string[] expectedProtected)
302+
{
303+
bundleStringPairs.Count.Should().Be(bundles.Count);
304+
305+
var expectedUninstallable = bundles.Select(bundle => bundle.DisplayName)
306+
.Except(expectedProtected);
307+
308+
bundleStringPairs.Where(pair => pair.Key.Version is SdkVersion)
309+
.Where(pair => string.IsNullOrEmpty(pair.Value))
310+
.Select(pair => pair.Key.DisplayName)
311+
.Should().BeEquivalentTo(expectedUninstallable);
312+
313+
bundleStringPairs.Where(pair => !string.IsNullOrEmpty(pair.Value))
314+
.Select(pair => pair.Key.DisplayName)
315+
.Should().BeEquivalentTo(expectedProtected);
316+
}
262317
}
263318
}

0 commit comments

Comments
 (0)