|
3 | 3 | using UniGetUI.Core.Data; |
4 | 4 | using UniGetUI.Core.SettingsEngine; |
5 | 5 | using UniGetUI.PackageEngine.Classes.Manager; |
| 6 | +using UniGetUI.PackageEngine.Enums; |
6 | 7 | using UniGetUI.PackageEngine.Interfaces; |
7 | 8 | using UniGetUI.PackageEngine.Managers.WingetManager; |
8 | 9 | using UniGetUI.PackageEngine.ManagerClasses.Classes; |
9 | 10 | using UniGetUI.PackageEngine.PackageClasses; |
| 11 | +using UniGetUI.PackageEngine.Serializable; |
10 | 12 | using UniGetUI.PackageEngine.Tests.Infrastructure.Assertions; |
11 | 13 | using UniGetUI.PackageEngine.Tests.Infrastructure.Builders; |
12 | 14 |
|
@@ -298,23 +300,24 @@ public void FindCandidateExecutableFilesReturnsEmptyWhenNoCliToolExists() |
298 | 300 | [Fact] |
299 | 301 | public void PingetCliHelperDeserializesListResponsesWithGeneratedContext() |
300 | 302 | { |
| 303 | + // pinget 0.4.1+ emits snake_case keys. |
301 | 304 | const string json = """ |
302 | 305 | { |
303 | 306 | "matches": [ |
304 | 307 | { |
305 | 308 | "name": "Contoso Tool", |
306 | 309 | "id": "Contoso.Tool", |
307 | | - "localId": null, |
308 | | - "installedVersion": "1.2.3", |
309 | | - "availableVersion": "2.0.0", |
310 | | - "sourceName": "winget", |
| 310 | + "local_id": null, |
| 311 | + "installed_version": "1.2.3", |
| 312 | + "available_version": "2.0.0", |
| 313 | + "source_name": "winget", |
311 | 314 | "publisher": null, |
312 | 315 | "scope": null, |
313 | | - "installerCategory": null, |
314 | | - "installLocation": null, |
315 | | - "packageFamilyNames": [], |
316 | | - "productCodes": [], |
317 | | - "upgradeCodes": [] |
| 316 | + "installer_category": null, |
| 317 | + "install_location": null, |
| 318 | + "package_family_names": [], |
| 319 | + "product_codes": [], |
| 320 | + "upgrade_codes": [] |
318 | 321 | } |
319 | 322 | ], |
320 | 323 | "warnings": [], |
@@ -708,6 +711,149 @@ public void WinGetCliHelperUsesPingetProviderForPackageDetails() |
708 | 711 | ); |
709 | 712 | } |
710 | 713 |
|
| 714 | + [Theory] |
| 715 | + [InlineData(0)] // OperationType.Install |
| 716 | + [InlineData(1)] // OperationType.Update |
| 717 | + [InlineData(2)] // OperationType.Uninstall |
| 718 | + public void WinGetOperationHelperEmitsWinGetCompatibleFlagsForSystemCli(int operationType) |
| 719 | + { |
| 720 | + var manager = new WinGet(); |
| 721 | + SetCliToolKind(manager, WinGetCliToolKind.SystemWinGet); |
| 722 | + var package = new PackageBuilder() |
| 723 | + .WithManager(manager) |
| 724 | + .WithId("Contoso.Tool") |
| 725 | + .WithVersion("1.0.0") |
| 726 | + .WithNewVersion("2.0.0") |
| 727 | + .Build(); |
| 728 | + |
| 729 | + var parameters = manager.OperationHelper.GetParameters( |
| 730 | + package, |
| 731 | + new InstallOptions(), |
| 732 | + (OperationType)operationType |
| 733 | + ); |
| 734 | + |
| 735 | + Assert.Contains("--accept-source-agreements", parameters); |
| 736 | + Assert.Contains("--disable-interactivity", parameters); |
| 737 | + } |
| 738 | + |
| 739 | + [Fact] |
| 740 | + public void WinGetOperationHelperSkipsUnsupportedFlagsForPingetInstall() |
| 741 | + { |
| 742 | + var manager = new WinGet(); |
| 743 | + SetCliToolKind(manager, WinGetCliToolKind.BundledPinget); |
| 744 | + var package = new PackageBuilder() |
| 745 | + .WithManager(manager) |
| 746 | + .WithId("Spotify.Spotify") |
| 747 | + .Build(); |
| 748 | + |
| 749 | + var parameters = manager.OperationHelper.GetParameters( |
| 750 | + package, |
| 751 | + new InstallOptions(), |
| 752 | + OperationType.Install |
| 753 | + ); |
| 754 | + |
| 755 | + Assert.DoesNotContain("--accept-source-agreements", parameters); |
| 756 | + Assert.DoesNotContain("--disable-interactivity", parameters); |
| 757 | + // pinget install does accept these. |
| 758 | + Assert.Contains("--accept-package-agreements", parameters); |
| 759 | + Assert.Contains("--force", parameters); |
| 760 | + Assert.Contains("--silent", parameters); |
| 761 | + } |
| 762 | + |
| 763 | + [Fact] |
| 764 | + public void WinGetOperationHelperSkipsUnsupportedFlagsForPingetUpgrade() |
| 765 | + { |
| 766 | + var manager = new WinGet(); |
| 767 | + SetCliToolKind(manager, WinGetCliToolKind.BundledPinget); |
| 768 | + var package = new PackageBuilder() |
| 769 | + .WithManager(manager) |
| 770 | + .WithId("Contoso.Tool") |
| 771 | + .WithVersion("1.0.0") |
| 772 | + .WithNewVersion("2.0.0") |
| 773 | + .Build(); |
| 774 | + var options = new InstallOptions |
| 775 | + { |
| 776 | + InteractiveInstallation = true, |
| 777 | + CustomInstallLocation = @"C:\Apps\Contoso", |
| 778 | + }; |
| 779 | + |
| 780 | + var parameters = manager.OperationHelper.GetParameters( |
| 781 | + package, |
| 782 | + options, |
| 783 | + OperationType.Update |
| 784 | + ); |
| 785 | + |
| 786 | + Assert.DoesNotContain("--accept-source-agreements", parameters); |
| 787 | + Assert.DoesNotContain("--disable-interactivity", parameters); |
| 788 | + // pinget upgrade does NOT accept these even though winget upgrade does. |
| 789 | + Assert.DoesNotContain("--accept-package-agreements", parameters); |
| 790 | + Assert.DoesNotContain("--force", parameters); |
| 791 | + Assert.DoesNotContain("--interactive", parameters); |
| 792 | + Assert.DoesNotContain("--location", parameters); |
| 793 | + // pinget upgrade still supports --include-unknown and --silent. |
| 794 | + Assert.Contains("--include-unknown", parameters); |
| 795 | + Assert.Contains("--silent", parameters); |
| 796 | + } |
| 797 | + |
| 798 | + [Fact] |
| 799 | + public void WinGetOperationHelperSkipsUnsupportedFlagsForPingetUninstall() |
| 800 | + { |
| 801 | + var manager = new WinGet(); |
| 802 | + SetCliToolKind(manager, WinGetCliToolKind.BundledPinget); |
| 803 | + var package = new PackageBuilder() |
| 804 | + .WithManager(manager) |
| 805 | + .WithId("Contoso.Tool") |
| 806 | + .WithVersion("1.0.0") |
| 807 | + .Build(); |
| 808 | + |
| 809 | + var parameters = manager.OperationHelper.GetParameters( |
| 810 | + package, |
| 811 | + new InstallOptions(), |
| 812 | + OperationType.Uninstall |
| 813 | + ); |
| 814 | + |
| 815 | + Assert.DoesNotContain("--accept-source-agreements", parameters); |
| 816 | + Assert.DoesNotContain("--disable-interactivity", parameters); |
| 817 | + } |
| 818 | + |
| 819 | + [Fact] |
| 820 | + public void WinGetOperationHelperOmitsProxyArgumentForPinget() |
| 821 | + { |
| 822 | + Settings.Set(Settings.K.EnableProxy, true); |
| 823 | + Settings.Set(Settings.K.EnableProxyAuth, false); |
| 824 | + Settings.SetValue(Settings.K.ProxyURL, "http://proxy.example.test:3128/"); |
| 825 | + try |
| 826 | + { |
| 827 | + var manager = new WinGet(); |
| 828 | + SetCliToolKind(manager, WinGetCliToolKind.BundledPinget); |
| 829 | + var package = new PackageBuilder() |
| 830 | + .WithManager(manager) |
| 831 | + .WithId("Contoso.Tool") |
| 832 | + .Build(); |
| 833 | + |
| 834 | + var parameters = manager.OperationHelper.GetParameters( |
| 835 | + package, |
| 836 | + new InstallOptions(), |
| 837 | + OperationType.Install |
| 838 | + ); |
| 839 | + |
| 840 | + Assert.DoesNotContain(parameters, p => p.StartsWith("--proxy", StringComparison.Ordinal)); |
| 841 | + } |
| 842 | + finally |
| 843 | + { |
| 844 | + Settings.Set(Settings.K.EnableProxy, false); |
| 845 | + Settings.SetValue(Settings.K.ProxyURL, ""); |
| 846 | + } |
| 847 | + } |
| 848 | + |
| 849 | + private static void SetCliToolKind(WinGet manager, WinGetCliToolKind kind) |
| 850 | + { |
| 851 | + typeof(WinGet) |
| 852 | + .GetProperty(nameof(WinGet.SelectedCliToolKind), System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)! |
| 853 | + .GetSetMethod(nonPublic: true)! |
| 854 | + .Invoke(manager, [kind]); |
| 855 | + } |
| 856 | + |
711 | 857 | private sealed class TestableWinGet : WinGet |
712 | 858 | { |
713 | 859 | public IReadOnlyList<Package> InvokeGetInstalledPackages() => base.GetInstalledPackages_UnSafe(); |
|
0 commit comments