Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing comparer exception issue #114

Merged
merged 3 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/dotnet-core-uninstall/Shared/BundleInfo/Bundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override string ToString()
}
}

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

public int CompareTo(object obj)
{
return CompareTo(obj as Bundle<TBundleVersion>);
return CompareTo(obj as Bundle);
}

public int CompareTo(Bundle<TBundleVersion> other)
public int CompareTo(Bundle other)
{
if (other == null)
{
Expand All @@ -76,7 +76,7 @@ public int CompareTo(Bundle<TBundleVersion> other)

return Version.Equals(other.Version) ?
Arch - other.Arch :
Version.CompareTo(other.Version);
Version.SemVer.CompareTo(other.Version.SemVer);
}

public static IEnumerable<Bundle<TBundleVersion>> FilterWithSameBundleType(IEnumerable<Bundle> bundles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ private static (IDictionary<IEnumerable<Bundle>, string>, IEnumerable<Bundle>) A
var dividedBundles = new Dictionary<IEnumerable<Bundle>, 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,60 @@ private string[] ExpandExpectationShortHand(string[] input)

return output;
}

[WindowsOnlyFact]
internal void TestUninstallableStringsCorrectManySDKs()
{
var bundles = new List<Bundle>
{
new Bundle<SdkVersion>(new SdkVersion("3.0.100-preview-0"), BundleArch.X64, string.Empty, "3.0.100"),
new Bundle<RuntimeVersion>(new RuntimeVersion("2.0.0"), BundleArch.X64, string.Empty, "2.0.0"),
};

for (int i = 0; i < 5; i++)
{
bundles.Add(new Bundle<SdkVersion>(new SdkVersion("2.0." + i), BundleArch.X64, string.Empty, "2.0." + i));
bundles.Add(new Bundle<SdkVersion>(new SdkVersion("2.0." + i + "-preview-0"), BundleArch.X64, string.Empty, "2.0." + i + "-preview-0"));
bundles.Add(new Bundle<SdkVersion>(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<Bundle>
{
new Bundle<SdkVersion>(new SdkVersion("2.0.0"), BundleArch.X64, string.Empty, "2.0.0"),
new Bundle<SdkVersion>(new SdkVersion("2.0.0-preview-0"), BundleArch.X64, string.Empty, "2.0.0-preview-0"),
new Bundle<SdkVersion>(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<Bundle> bundles, Dictionary<Bundle, string> 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);
}
}
}