internal void TestGetListCommandUninstallableStrings(IEnumerable <Bundle> bundles, string[] sdkExpected, string[] runtimeExpected) { bundles = bundles.Concat(new List <Bundle> { new Bundle <AspNetRuntimeVersion>(new AspNetRuntimeVersion("1.0.0"), new BundleArch(), string.Empty, "AspNetVersion"), new Bundle <AspNetRuntimeVersion>(new AspNetRuntimeVersion("10.0.0"), new BundleArch(), string.Empty, "AspNetVersion"), new Bundle <HostingBundleVersion>(new HostingBundleVersion("1.0.0"), new BundleArch(), string.Empty, "HostingBundleVersion"), new Bundle <HostingBundleVersion>(new HostingBundleVersion("10.0.0"), new BundleArch(), string.Empty, "HostingBundleVersion") }); var strings = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(bundles); strings.Count().Should().Be(bundles.Count()); var sdkBundles = strings.Where(pair => pair.Key.Version is SdkVersion).ToArray(); var sdkStrings = sdkBundles.Select(pair => pair.Value); var runtimeBundles = strings.Where(pair => pair.Key.Version is RuntimeVersion).ToArray(); var runtimeStrings = runtimeBundles.Select(pair => pair.Value); var otherBundles = strings.Except(sdkBundles).Except(runtimeBundles); sdkStrings.Should().BeEquivalentTo(sdkExpected); runtimeStrings.Should().BeEquivalentTo(runtimeExpected); otherBundles.Should().HaveCount(4); // All bundles above the upper limit are required otherBundles.Where(pair => pair.Key.Version.SemVer >= VisualStudioSafeVersionsExtractor.UpperLimit) .ToList().ForEach(str => str.Value.Should().Be(string.Format(LocalizableStrings.UpperLimitRequirement, VisualStudioSafeVersionsExtractor.UpperLimit))); // Non-sdk bundles are always uninstallable below the upper limit otherBundles.Where(pair => pair.Key.Version.SemVer < VisualStudioSafeVersionsExtractor.UpperLimit) .ToList().ForEach(str => str.Value.Should().Be(string.Empty)); }
public static IDictionary <Bundle, string> GetFilteredWithRequirementStrings(IBundleCollector bundleCollector) { var allBundles = bundleCollector.GetAllInstalledBundles(); var filteredBundles = GetFilteredBundles(allBundles); return(VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(allBundles) .Where(pair => filteredBundles.Contains(pair.Key)) .ToDictionary(i => i.Key, i => i.Value)); }
private static IEnumerable <Bundle> FilterRequiredBundles(IEnumerable <Bundle> allBundles, IEnumerable <Token> tokens) { var explicitlyListedBundles = tokens .Where(token => SemanticVersion.TryParse(token.Value, out SemanticVersion semVerOut)) .Select(token => SemanticVersion.Parse(token.Value)); return(VisualStudioSafeVersionsExtractor.GetUninstallableBundles(allBundles) .Concat(allBundles.Where(b => explicitlyListedBundles.Contains(b.Version.SemVer))) .Distinct() .ToList()); }
private static void Execute( IEnumerable <Bundle> bundles, IEnumerable <BundleTypePrintInfo> supportedBundleTypes) { Console.WriteLine(RuntimeInfo.RunningOnWindows ? LocalizableStrings.WindowsListCommandOutput : LocalizableStrings.MacListCommandOutput); var listCommandParseResult = CommandLineConfigs.ListCommand.Parse(Environment.GetCommandLineArgs()); var verbose = listCommandParseResult.CommandResult.GetVerbosityLevel().Equals(VerbosityLevel.Detailed) || listCommandParseResult.CommandResult.GetVerbosityLevel().Equals(VerbosityLevel.Diagnostic); var typeSelection = listCommandParseResult.CommandResult.GetTypeSelection(); var archSelection = listCommandParseResult.CommandResult.GetArchSelection(); var stackView = new StackLayoutView(); var filteredBundlesByArch = bundles.Where(bundle => archSelection.HasFlag(bundle.Arch)); var footnotes = new List <string>(); foreach (var bundleType in supportedBundleTypes) { if (typeSelection.HasFlag(bundleType.Type)) { var filteredBundlesByType = bundleType .Filter(filteredBundlesByArch); var uninstallMap = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(filteredBundlesByType); stackView.Add(new ContentView(bundleType.Header)); stackView.Add(bundleType.GridViewGenerator.Invoke(uninstallMap, verbose)); stackView.Add(new ContentView(string.Empty)); footnotes.AddRange(filteredBundlesByType .Where(bundle => bundle.Version.HasFootnote) .Select(bundle => bundle.Version.Footnote)); } } foreach (var footnote in footnotes) { stackView.Add(new ContentView($"* {footnote}")); } if (footnotes.Count > 0) { stackView.Add(new ContentView(string.Empty)); } stackView.Render( new ConsoleRenderer(new SystemConsole()), new Region(0, 0, Console.WindowWidth, int.MaxValue)); }
internal void TestGetUninstallableWindows(string[] versions, bool[] allowed) { var bundles = new List <Bundle>(); foreach (string v in versions) { bundles.Add(new Bundle <SdkVersion>(new SdkVersion(v), new BundleArch(), string.Empty, string.Empty)); } var uninstallable = VisualStudioSafeVersionsExtractor.GetUninstallableBundles(bundles); CheckAllowed(bundles, uninstallable, allowed, null); }
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); }
internal void TestGetUninstallableMac(string[] sdkVersions, bool[] sdkAllowed, string[] runtimeVersions, bool[] runtimeAllowed) { var bundles = new List <Bundle>(); foreach (string v in sdkVersions) { bundles.Add(new Bundle <SdkVersion>(new SdkVersion(v), new BundleArch(), string.Empty, string.Empty)); } foreach (string v in runtimeVersions) { bundles.Add(new Bundle <RuntimeVersion>(new RuntimeVersion(v), new BundleArch(), string.Empty, string.Empty)); } var uninstallable = VisualStudioSafeVersionsExtractor.GetUninstallableBundles(bundles); CheckAllowed(bundles, uninstallable, sdkAllowed, runtimeAllowed); }
public static Dictionary <BundleTypePrintInfo, Dictionary <Bundle, string> > GetFilteredBundlesWithRequirements( IEnumerable <Bundle> bundles, IEnumerable <BundleTypePrintInfo> supportedBundleTypes, ParseResult parseResult) { var uninstallMap = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(bundles); var typeSelection = parseResult.CommandResult.GetTypeSelection(); var archSelection = parseResult.CommandResult.GetArchSelection(); var filteredBundlesByArch = bundles.Where(bundle => archSelection.HasFlag(bundle.Arch)); return(supportedBundleTypes.Where(type => typeSelection.HasFlag(type.Type)) .Select(type => new KeyValuePair <BundleTypePrintInfo, Dictionary <Bundle, string> >(type, uninstallMap.Where(pair => type.Filter(filteredBundlesByArch).Contains(pair.Key)).ToDictionary(i => i.Key, i => i.Value))) .ToDictionary(i => i.Key, i => i.Value)); }
internal void TestGetUninstallableNonSdkVersions(IEnumerable <Bundle> bundles, bool[] sdkAllowed, bool[] runtimeAllowed) { bundles = bundles.Concat(new List <Bundle> { new Bundle <AspNetRuntimeVersion>(new AspNetRuntimeVersion("1.0.0"), new BundleArch(), string.Empty, "AspNetVersion"), new Bundle <AspNetRuntimeVersion>(new AspNetRuntimeVersion("10.0.0"), new BundleArch(), string.Empty, "AspNetVersion"), new Bundle <HostingBundleVersion>(new HostingBundleVersion("1.0.0"), new BundleArch(), string.Empty, "HostingBundleVersion"), new Bundle <HostingBundleVersion>(new HostingBundleVersion("10.0.0"), new BundleArch(), string.Empty, "HostingBundleVersion") }); var uninstallable = VisualStudioSafeVersionsExtractor.GetUninstallableBundles(bundles); // Check that we still have all of the non-sdk bundles uninstallable.Where(b => b.Version is AspNetRuntimeVersion).Should().HaveCount(1); uninstallable.Where(b => b.Version is HostingBundleVersion).Should().HaveCount(1); CheckAllowed(bundles, uninstallable, sdkAllowed, runtimeAllowed); }
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); }
public IEnumerable <Bundle> GetInstalledBundles() { return(VisualStudioSafeVersionsExtractor.GetUninstallableBundles(GetAllInstalledBundles())); }