From b1a619873ddaf9206ca1a7c6aaa608f083ff8db4 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 18 Jan 2023 15:27:44 -0800 Subject: [PATCH 01/18] Add Pester tests and update pipeline --- azure-pipelines.yml | 127 ++++++++------ .../Commands/FindPackageCommand.cs | 10 +- .../Commands/GetPackageCommand.cs | 2 +- .../Commands/GetSourceCommand.cs | 2 +- .../Commands/InstallPackageCommand.cs | 2 +- .../Commands/UninstallPackageCommand.cs | 2 +- .../Module/Format.ps1xml | 159 ++++++++++++++++-- .../PSObjects/FoundCatalogPackage.cs | 65 +++++++ .../PSObjects/InstallResult.cs | 55 ++++++ .../PSObjects/InstalledCatalogPackage.cs | 65 +++++++ .../PSObjects/SourceResult.cs | 41 +++++ .../PSObjects/UninstallResult.cs | 55 ++++++ .../tests/Find-WinGetPackage.Tests.ps1 | 34 ++++ .../tests/Get-WinGetPackage.Tests.ps1 | 35 ++++ .../tests/Get-WinGetSource.Tests.ps1 | 17 ++ ...Install-Update-Uninstall-WinGetPackage.ps1 | 58 +++++++ src/PowerShell/tests/Setup.Tests.ps1 | 0 17 files changed, 653 insertions(+), 76 deletions(-) create mode 100644 src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs create mode 100644 src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs create mode 100644 src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs create mode 100644 src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs create mode 100644 src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs create mode 100644 src/PowerShell/tests/Find-WinGetPackage.Tests.ps1 create mode 100644 src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 create mode 100644 src/PowerShell/tests/Get-WinGetSource.Tests.ps1 create mode 100644 src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.ps1 create mode 100644 src/PowerShell/tests/Setup.Tests.ps1 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ec5edba4d8..c0b12f6e6e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -146,28 +146,28 @@ jobs: inputs: secureFile: 'PsExec.exe' - - task: CmdLine@2 - displayName: Run Unit Tests Unpackaged Under System Context - inputs: - script: | - $(PsExec.secureFilePath) -accepteula -s -i $(buildOutDir)\AppInstallerCLITests\AppInstallerCLITests.exe -logto $(artifactsDir)\AICLI-Unpackaged-System.log -s -r junit -o $(artifactsDir)\TEST-AppInstallerCLI-Unpackaged-System.xml - workingDirectory: '$(buildOutDir)\AppInstallerCLITests' - continueOnError: true - - - task: PowerShell@2 - displayName: Run Unit Tests Packaged - inputs: - filePath: 'src\AppInstallerCLITests\Run-TestsInPackage.ps1' - arguments: '-Args "~[pips]" -BuildRoot $(buildOutDir) -PackageRoot AppInstallerCLIPackage\bin\$(buildPlatform)\$(buildConfiguration) -LogTarget $(artifactsDir)\AICLI-Packaged.log -TestResultsTarget $(artifactsDir)\TEST-AppInstallerCLI-Packaged.xml -ScriptWait' - workingDirectory: 'src' - continueOnError: true - - - task: PublishTestResults@2 - displayName: Publish Unit Test Results - inputs: - testResultsFormat: 'JUnit' - testResultsFiles: '$(artifactsDir)\TEST-*.xml' - failTaskOnFailedTests: true + # - task: CmdLine@2 + # displayName: Run Unit Tests Unpackaged Under System Context + # inputs: + # script: | + # $(PsExec.secureFilePath) -accepteula -s -i $(buildOutDir)\AppInstallerCLITests\AppInstallerCLITests.exe -logto $(artifactsDir)\AICLI-Unpackaged-System.log -s -r junit -o $(artifactsDir)\TEST-AppInstallerCLI-Unpackaged-System.xml + # workingDirectory: '$(buildOutDir)\AppInstallerCLITests' + # continueOnError: true + + # - task: PowerShell@2 + # displayName: Run Unit Tests Packaged + # inputs: + # filePath: 'src\AppInstallerCLITests\Run-TestsInPackage.ps1' + # arguments: '-Args "~[pips]" -BuildRoot $(buildOutDir) -PackageRoot AppInstallerCLIPackage\bin\$(buildPlatform)\$(buildConfiguration) -LogTarget $(artifactsDir)\AICLI-Packaged.log -TestResultsTarget $(artifactsDir)\TEST-AppInstallerCLI-Packaged.xml -ScriptWait' + # workingDirectory: 'src' + # continueOnError: true + + # - task: PublishTestResults@2 + # displayName: Publish Unit Test Results + # inputs: + # testResultsFormat: 'JUnit' + # testResultsFiles: '$(artifactsDir)\TEST-*.xml' + # failTaskOnFailedTests: true - task: DownloadSecureFile@1 name: AppInstallerTest @@ -248,30 +248,30 @@ jobs: TargetFolder: 'src\AppInstallerCLIPackage\bin\$(buildPlatform)\$(buildConfiguration)' Contents: Microsoft.Management.Deployment.winmd - - template: templates/e2e-test.template.yml - parameters: - title: "E2E Tests Packaged" - isPackaged: true - filter: "TestCategory!=InProcess&TestCategory!=OutOfProcess" - - - template: templates/e2e-test.template.yml - parameters: - title: "COM API E2E Tests (In-process)" - isPackaged: false - filter: "TestCategory=InProcess" - - - template: templates/e2e-test.template.yml - parameters: - title: "COM API E2E Tests (Out-of-process)" - isPackaged: true - filter: "TestCategory=OutOfProcess" - - - task: CopyFiles@2 - displayName: 'Copy E2E Tests Package Log to artifacts folder' - inputs: - SourceFolder: '$(temp)\E2ETestLogs' - TargetFolder: '$(artifactsDir)\E2ETestsPackagedLog' - condition: succeededOrFailed() + # - template: templates/e2e-test.template.yml + # parameters: + # title: "E2E Tests Packaged" + # isPackaged: true + # filter: "TestCategory!=InProcess&TestCategory!=OutOfProcess" + + # - template: templates/e2e-test.template.yml + # parameters: + # title: "COM API E2E Tests (In-process)" + # isPackaged: false + # filter: "TestCategory=InProcess" + + # - template: templates/e2e-test.template.yml + # parameters: + # title: "COM API E2E Tests (Out-of-process)" + # isPackaged: true + # filter: "TestCategory=OutOfProcess" + + # - task: CopyFiles@2 + # displayName: 'Copy E2E Tests Package Log to artifacts folder' + # inputs: + # SourceFolder: '$(temp)\E2ETestLogs' + # TargetFolder: '$(artifactsDir)\E2ETestsPackagedLog' + # condition: succeededOrFailed() - task: CopyFiles@2 displayName: 'Copy Files: WinGetUtilInterop.UnitTests' @@ -281,15 +281,15 @@ jobs: CleanTargetFolder: true OverWrite: true - - task: VSTest@2 - displayName: 'Run tests: WinGetUtilInterop.UnitTests' - inputs: - testSelector: 'testAssemblies' - testAssemblyVer2: 'WinGetUtilInterop.UnitTests.dll' - searchFolder: '$(Build.ArtifactStagingDirectory)\WinGetUtilInterop.UnitTests' - codeCoverageEnabled: true - platform: 'Any CPU' - configuration: '$(BuildConfiguration)' + # - task: VSTest@2 + # displayName: 'Run tests: WinGetUtilInterop.UnitTests' + # inputs: + # testSelector: 'testAssemblies' + # testAssemblyVer2: 'WinGetUtilInterop.UnitTests.dll' + # searchFolder: '$(Build.ArtifactStagingDirectory)\WinGetUtilInterop.UnitTests' + # codeCoverageEnabled: true + # platform: 'Any CPU' + # configuration: '$(BuildConfiguration)' - task: CopyFiles@2 displayName: 'Copy Util to artifacts folder' @@ -300,6 +300,23 @@ jobs: TargetFolder: '$(artifactsDir)' condition: succeededOrFailed() + - task: PowerShell@2 + displayName: 'Run Pester Tests for PowerShell Module' + targetType: 'inline' + pwsh: true + script: | + Import-Module Pester -PassThru + Import-Module '$(buildOutDir)\PowerShell\Microsoft.WinGet.Client\Microsoft.WinGet.Client.psd1' + Invoke-Pester -Path 'src\PowerShell\tests\' -CI -Output Detailed -OutputFile '$(buildOutDir)\Microsoft.WinGet.Client.Tests.xml' + + - task: PublishTestResults@2 + displayName: 'Publish Pester Tests' + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'Microsoft.WinGet.Client.Tests.xml' + mergeTestResults: true + failTaskOnFailedTests: true + - task: CopyFiles@2 displayName: 'Copy PowerShell Module Files' inputs: diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/FindPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/FindPackageCommand.cs index 59c6589d36..f8e0eb21d4 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/FindPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/FindPackageCommand.cs @@ -5,17 +5,17 @@ // ----------------------------------------------------------------------------- namespace Microsoft.WinGet.Client.Commands -{ +{ using System.Management.Automation; using Microsoft.Management.Deployment; using Microsoft.WinGet.Client.Commands.Common; - using Microsoft.WinGet.Client.Common; - + using Microsoft.WinGet.Client.Common; + /// /// Searches configured sources for packages. /// [Cmdlet(VerbsCommon.Find, Constants.WinGetNouns.Package)] - [OutputType(typeof(MatchResult))] + [OutputType(typeof(Management.Deployment.CatalogPackage))] public sealed class FindPackageCommand : BaseFinderExtendedCommand { /// @@ -27,7 +27,7 @@ protected override void ProcessRecord() var results = this.FindPackages(CompositeSearchBehavior.RemotePackagesFromRemoteCatalogs); for (var i = 0; i < results.Count; i++) { - this.WriteObject(results[i]); + this.WriteObject(new PSObjects.FoundCatalogPackage(results[i].CatalogPackage)); } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/GetPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/GetPackageCommand.cs index 6743e01988..08629583ae 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/GetPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/GetPackageCommand.cs @@ -27,7 +27,7 @@ protected override void ProcessRecord() var results = this.FindPackages(CompositeSearchBehavior.LocalCatalogs); for (var i = 0; i < results.Count; i++) { - this.WriteObject(results[i].CatalogPackage); + this.WriteObject(new PSObjects.InstalledCatalogPackage(results[i].CatalogPackage)); } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/GetSourceCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/GetSourceCommand.cs index fbe52e02d8..a7575e1bc2 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/GetSourceCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/GetSourceCommand.cs @@ -36,7 +36,7 @@ protected override void ProcessRecord() var results = GetPackageCatalogReferences(this.Name); for (var i = 0; i < results.Count; i++) { - this.WriteObject(results[i]); + this.WriteObject(new PSObjects.SourceResult(results[i])); } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs index 8d0342522d..b02ce4789d 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs @@ -66,7 +66,7 @@ protected override void ProcessRecord() { InstallOptions options = this.GetInstallOptions(version); InstallResult result = this.InstallPackage(package, options); - this.WriteObject(result); + this.WriteObject(new PSObjects.InstallResult(result)); }); } diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/UninstallPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/UninstallPackageCommand.cs index 0225facf19..9e4951d86f 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/UninstallPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/UninstallPackageCommand.cs @@ -46,7 +46,7 @@ protected override void ProcessRecord() { UninstallOptions options = this.GetUninstallOptions(version); UninstallResult result = this.UninstallPackage(package, options); - this.WriteObject(result); + this.WriteObject(new PSObjects.UninstallResult(result)); }); } diff --git a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml index 3c140ab2b5..efd3dc35d0 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml +++ b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml @@ -50,9 +50,9 @@ - Microsoft.Management.Deployment.PackageCatalogReference + Microsoft.WinGet.Client.PSObjects.FoundCatalogPackage - Microsoft.Management.Deployment.PackageCatalogReference + Microsoft.WinGet.Client.PSObjects.FoundCatalogPackage @@ -61,23 +61,30 @@ - + 32 + - + + + + - $_.Info.Name + $_.Name - $_.Info.Argument + $_.Id - $_.Info.Type + $_.Version + + + $_.Source @@ -85,9 +92,9 @@ - Microsoft.Management.Deployment.CatalogPackage + Microsoft.WinGet.Client.PSObjects.InstalledCatalogPackage - Microsoft.Management.Deployment.CatalogPackage + Microsoft.WinGet.Client.PSObjects.InstalledCatalogPackage @@ -96,6 +103,7 @@ + 32 @@ -118,13 +126,140 @@ $_.Id - $_.InstalledVersion.Version + $_.Version + + + if ($_.IsUpdateAvailable) { $_.AvailableVersions[0] } + + + $_.Source + + + + + + + + Microsoft.WinGet.Client.PSObjects.InstallResult + + Microsoft.WinGet.Client.PSObjects.InstallResult + + + + + + + + + + + + + + + + + + + + + + + + $_.InstallerErrorCode + + + $_.Status + + + $_.RebootRequired + + + $_.ExtendedErrorCode + + + $_.CorrelationData + + + + + + + + Microsoft.WinGet.Client.PSObjects.UninstallResult + + Microsoft.WinGet.Client.PSObjects.UninstallResult + + + + + + + + + + + + + + + + + + + + + + + + $_.UninstallerErrorCode + + + $_.Status + + + $_.RebootRequired + + + $_.ExtendedErrorCode + + + $_.CorrelationData + + + + + + + + Microsoft.WinGet.Client.PSObjects.SourceResult + + Microsoft.WinGet.Client.PSObjects.SourceResult + + + + + 32 + + + + + + + + + + + + + + $_.Name - if ($_.IsUpdateAvailable) { $_.AvailableVersions[0].Version } + $_.Argument - $_.DefaultInstallVersion.PackageCatalog.Info.Name + $_.Type diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs new file mode 100644 index 0000000000..3dde5ed7b2 --- /dev/null +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs @@ -0,0 +1,65 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.PSObjects +{ + using System; + using System.Linq; + + /// + /// FoundCatalogPackage wrapper object for displaying to PowerShell. + /// + public class FoundCatalogPackage + { + /// + /// The id of the catalog package. + /// + public readonly string Id; + + /// + /// The name of the catalog package. + /// + public readonly string Name; + + /// + /// The version of the catalog package. + /// + public readonly string Version; + + /// + /// A boolean value indicating whether an update is available. + /// + public readonly bool IsUpdateAvailable; + + /// + /// The source of the catalog package. + /// + public readonly string Source; + + /// + /// A list of strings representing the available versions. + /// + public readonly string[] AvailableVersions; + + /// + /// Initializes a new instance of the class. + /// + /// The catalog package COM object. + public FoundCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + { + this.Id = catalogPackage.Id; + this.Name = catalogPackage.Name; + this.IsUpdateAvailable = catalogPackage.IsUpdateAvailable; + this.Version = catalogPackage.DefaultInstallVersion.Version; + this.Source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + + //if (this.IsUpdateAvailable) + //{ + // this.AvailableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); + //} + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs new file mode 100644 index 0000000000..2c89634cdb --- /dev/null +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs @@ -0,0 +1,55 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.PSObjects +{ + using System; + using Microsoft.Management.Deployment; + + /// + /// InstallResult wrapper object for displaying to PowerShell. + /// + public class InstallResult + { + /// + /// The correlation data of the install result. + /// + public readonly string CorrelationData; + + /// + /// The extended error code exception of the failed install result. + /// + public readonly Exception ExtendedErrorCode; + + /// + /// A boolean value indicating whether a reboot is required. + /// + public readonly bool RebootRequired; + + /// + /// The error code of an install. + /// + public readonly uint InstallerErrorCode; + + /// + /// The status of the install. + /// + public readonly InstallResultStatus Status; + + /// + /// Initializes a new instance of the class. + /// + /// The install result COM object. + public InstallResult(Management.Deployment.InstallResult installResult) + { + this.CorrelationData = installResult.CorrelationData; + this.ExtendedErrorCode = installResult.ExtendedErrorCode; + this.RebootRequired = installResult.RebootRequired; + this.InstallerErrorCode = installResult.InstallerErrorCode; + this.Status = installResult.Status; + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs new file mode 100644 index 0000000000..d36dca1d33 --- /dev/null +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs @@ -0,0 +1,65 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.PSObjects +{ + using System; + using System.Linq; + + /// + /// CatalogPackage wrapper object for displaying to PowerShell. + /// + public class InstalledCatalogPackage + { + /// + /// The id of the catalog package. + /// + public readonly string Id; + + /// + /// The name of the catalog package. + /// + public readonly string Name; + + /// + /// The version of the catalog package. + /// + public readonly string Version; + + /// + /// A boolean value indicating whether an update is available. + /// + public readonly bool IsUpdateAvailable; + + /// + /// The source of the catalog package. + /// + public readonly string Source; + + /// + /// A list of strings representing the available versions. + /// + public readonly string[] AvailableVersions; + + /// + /// Initializes a new instance of the class. + /// + /// The catalog package COM object. + public InstalledCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + { + this.Id = catalogPackage.Id; + this.Name = catalogPackage.Name; + this.IsUpdateAvailable = catalogPackage.IsUpdateAvailable; + this.Version = catalogPackage.InstalledVersion.Version; + this.Source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + + if (this.IsUpdateAvailable) + { + this.AvailableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); + } + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs new file mode 100644 index 0000000000..954600c22b --- /dev/null +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.PSObjects +{ + /// + /// SourceResult wrapper object for displaying to PowerShell. + /// + public class SourceResult + { + /// + /// The name of the source. + /// + public readonly string Name; + + /// + /// The argument of the source. + /// + public readonly string Argument; + + /// + /// The type of the source. + /// + public readonly string Type; + + /// + /// Initializes a new instance of the class. + /// + /// The PackageCatalogReference COM object. + public SourceResult(Management.Deployment.PackageCatalogReference catalogReference) + { + var info = catalogReference.Info; + this.Name = info.Name; + this.Argument = info.Argument; + this.Type = info.Type; + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs new file mode 100644 index 0000000000..9a344521a5 --- /dev/null +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs @@ -0,0 +1,55 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.PSObjects +{ + using System; + using Microsoft.Management.Deployment; + + /// + /// UninstallResult wrapper object for displaying to PowerShell. + /// + public class UninstallResult + { + /// + /// The correlation data of the install result. + /// + public readonly string CorrelationData; + + /// + /// The extended error code exception of the failed install result. + /// + public readonly Exception ExtendedErrorCode; + + /// + /// A boolean value indicating whether a reboot is required. + /// + public readonly bool RebootRequired; + + /// + /// The error code of the uninstall. + /// + public readonly uint UninstallerErrorCode; + + /// + /// The status of the uninstall. + /// + public readonly UninstallResultStatus Status; + + /// + /// Initializes a new instance of the class. + /// + /// The uninstalll result COM object. + public UninstallResult(Management.Deployment.UninstallResult uninstallResult) + { + this.CorrelationData = uninstallResult.CorrelationData; + this.ExtendedErrorCode = uninstallResult.ExtendedErrorCode; + this.RebootRequired = uninstallResult.RebootRequired; + this.UninstallerErrorCode = uninstallResult.UninstallerErrorCode; + this.Status = uninstallResult.Status; + } + } +} diff --git a/src/PowerShell/tests/Find-WinGetPackage.Tests.ps1 b/src/PowerShell/tests/Find-WinGetPackage.Tests.ps1 new file mode 100644 index 0000000000..38682eee8a --- /dev/null +++ b/src/PowerShell/tests/Find-WinGetPackage.Tests.ps1 @@ -0,0 +1,34 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for the Find-WinGetPackage cmdlet in the Microsoft.WinGet.Client PowerShell module. +#> + +Describe 'Find-WinGetPackage' { + It 'Given no parameters, lists all available packages' { + $allPackages = Find-WinGetPackage -Source TestSource + $allPackages.Count | Should -BeGreaterThan 0 + } + + It 'Find by Id' { + $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestExeInstaller' + $package.Name | Should -Be 'TestExeInstaller' + $package.Id | Should -Be 'AppInstallerTest.TestExeInstaller' + $package.Version | Should -Be '2.0.0.0' + $package.Source | Should -Be 'TestSource' + } + + It 'Find by Name' { + $package = Find-WinGetPackage -Source 'TestSource' -Name 'TestPortableExe' + $package[0].Name | Should -Be 'TestPortableExe' + $package[1].Name | Should -Be 'TestPortableExeWithCommand' + } + + It 'Find by Name sort by Version' { + $package = Find-WinGetPackage -Source 'TestSource' -Name 'TestPortableExe' | Sort-Object 'Version' + $package[0].Name | Should -Be 'TestPortableExeWithCommand' + $package[1].Name | Should -Be 'TestPortableExe' + } +} \ No newline at end of file diff --git a/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 b/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 new file mode 100644 index 0000000000..cce4063ed2 --- /dev/null +++ b/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 @@ -0,0 +1,35 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for the Get-WinGetPackage cmdlet in the Microsoft.WinGet.Client PowerShell module. +#> + +Describe 'Install-WinGetPackage' { + + It 'Install by Id' { + $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Get package by Id' { + $result = Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller + $result.Name | Should -Be 'TestExeInstaller' + $result.Id | Should -Be 'AppInstallerTest.TestExeInstaller' + $result.Version | Should -Be '1.0.0.0' + $result.AvailableVersions[0] | Should -Be '2.0.0.0' + $result.Source | Should -Be 'TestSource' + } + + It 'Get package by Name' { + $result = Get-WinGetPackage -Name TestExeInstaller + $result.Name | Should -Be 'TestExeInstaller' + $result.Id | Should -Be 'AppInstallerTest.TestExeInstaller' + $result.Version | Should -Be '1.0.0.0' + $result.AvailableVersions[0] | Should -Be '2.0.0.0' + $result.Source | Should -Be 'TestSource' + } +} \ No newline at end of file diff --git a/src/PowerShell/tests/Get-WinGetSource.Tests.ps1 b/src/PowerShell/tests/Get-WinGetSource.Tests.ps1 new file mode 100644 index 0000000000..45d16a633a --- /dev/null +++ b/src/PowerShell/tests/Get-WinGetSource.Tests.ps1 @@ -0,0 +1,17 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for the Get-WinGetSource cmdlet in the Microsoft.WinGet.Client PowerShell module. +#> + +Describe 'Get-WinGetSource' { + + It 'Get Test Source' { + $source = Get-WinGetSource -Name TestSource + $source.Name | Should -Be 'TestSource' + $source.Argument | Should -Be 'https://localhost:5001/TestKit/' + $source.Type | Should -Be 'Microsoft.PreIndexed.Package' + } +} \ No newline at end of file diff --git a/src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.ps1 b/src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.ps1 new file mode 100644 index 0000000000..d727fff34d --- /dev/null +++ b/src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.ps1 @@ -0,0 +1,58 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Tests for the Install-WinGetPackage cmdlet in the Microsoft.WinGet.Client PowerShell module. +#> + +Describe 'Install-WinGetPackage' { + + It 'Install by Id' { + $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Install by exact Name and Version' { + $result = Install-WinGetPackage -Name TestPortableExe -Version '2.0.0.0' -Exact + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } +} + +Describe 'Update-WinGetPackage' { + + It 'Update by Id' { + $result = Update-WinGetPackage -Id AppInstallerTest.TestExeInstaller + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Update by Name and Version' { + $result = Update-WinGetPackage -Name TestPortableExe + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } +} + +Describe 'Uninstall-WinGetPackage' { + + It 'Uninstall by Id' { + $result = Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller + $result.UninstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Uninstall by Name' { + $result = Uninstall-WinGetPackage -Name TestPortableExe + $result.UninstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } +} \ No newline at end of file diff --git a/src/PowerShell/tests/Setup.Tests.ps1 b/src/PowerShell/tests/Setup.Tests.ps1 new file mode 100644 index 0000000000..e69de29bb2 From d2c9978d732ccdb0c8c33ef8bcd9b5a8f847e689 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 18 Jan 2023 15:39:00 -0800 Subject: [PATCH 02/18] fix pipeline --- azure-pipelines.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c0b12f6e6e..e210b86fac 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -302,18 +302,19 @@ jobs: - task: PowerShell@2 displayName: 'Run Pester Tests for PowerShell Module' - targetType: 'inline' + inputs: + targetType: 'inline' + script: | + Import-Module Pester -PassThru + Import-Module '$(buildOutDir)\PowerShell\Microsoft.WinGet.Client\Microsoft.WinGet.Client.psd1' + Invoke-Pester -Path 'src\PowerShell\tests\' -CI -Output Detailed -OutputFile '$(buildOutDir)\Microsoft.WinGet.Client.Tests.xml' pwsh: true - script: | - Import-Module Pester -PassThru - Import-Module '$(buildOutDir)\PowerShell\Microsoft.WinGet.Client\Microsoft.WinGet.Client.psd1' - Invoke-Pester -Path 'src\PowerShell\tests\' -CI -Output Detailed -OutputFile '$(buildOutDir)\Microsoft.WinGet.Client.Tests.xml' - task: PublishTestResults@2 displayName: 'Publish Pester Tests' inputs: testResultsFormat: 'NUnit' - testResultsFiles: 'Microsoft.WinGet.Client.Tests.xml' + testResultsFiles: '$(buildOutDir)\Microsoft.WinGet.Client.Tests.xml' mergeTestResults: true failTaskOnFailedTests: true From 54fdca8dcf648b1a2a3efd7bb16be9b5d6b02394 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 18 Jan 2023 15:39:43 -0800 Subject: [PATCH 03/18] set pwsh to true --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e210b86fac..6880257fdb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -308,7 +308,7 @@ jobs: Import-Module Pester -PassThru Import-Module '$(buildOutDir)\PowerShell\Microsoft.WinGet.Client\Microsoft.WinGet.Client.psd1' Invoke-Pester -Path 'src\PowerShell\tests\' -CI -Output Detailed -OutputFile '$(buildOutDir)\Microsoft.WinGet.Client.Tests.xml' - pwsh: true + pwsh: true - task: PublishTestResults@2 displayName: 'Publish Pester Tests' From 7ae0eec77be23a3304ea63edebfd4ea03309c997 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 18 Jan 2023 16:47:39 -0800 Subject: [PATCH 04/18] fix build warnings/errors --- .../Module/Format.ps1xml | 48 ------------ .../PSObjects/FoundCatalogPackage.cs | 76 ++++++++++++------- .../PSObjects/InstallResult.cs | 57 +++++++++----- .../PSObjects/InstalledCatalogPackage.cs | 76 ++++++++++++------- .../PSObjects/SourceResult.cs | 39 ++++++---- .../PSObjects/UninstallResult.cs | 57 +++++++++----- ...-Update-Uninstall-WinGetPackage.Tests.ps1} | 0 src/PowerShell/tests/Setup.Tests.ps1 | 12 +++ 8 files changed, 216 insertions(+), 149 deletions(-) rename src/PowerShell/tests/{Install-Update-Uninstall-WinGetPackage.ps1 => Install-Update-Uninstall-WinGetPackage.Tests.ps1} (100%) diff --git a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml index efd3dc35d0..fcc317d4fc 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml +++ b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml @@ -1,54 +1,6 @@  - - Microsoft.Management.Deployment.MatchResult - - Microsoft.Management.Deployment.MatchResult - - - - - 32 - - - - 32 - - - - - - - - - - - - - - - - - $_.CatalogPackage.Name - - - $_.CatalogPackage.Id - - - $_.CatalogPackage.DefaultInstallVersion.Version - - - '{0}: {1}' -f $_.MatchCriteria.Field,$_.MatchCriteria.Value - - - $_.CatalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name - - - - - - Microsoft.WinGet.Client.PSObjects.FoundCatalogPackage diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs index 3dde5ed7b2..9f0c0f8e2d 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs @@ -6,7 +6,6 @@ namespace Microsoft.WinGet.Client.PSObjects { - using System; using System.Linq; /// @@ -14,52 +13,77 @@ namespace Microsoft.WinGet.Client.PSObjects /// public class FoundCatalogPackage { + private readonly string id; + private readonly string name; + private readonly string version; + private readonly bool isUpdateAvailable; + private readonly string source; + private readonly string[] availableVersions; + /// - /// The id of the catalog package. + /// Initializes a new instance of the class. /// - public readonly string Id; + /// The catalog package COM object. + public FoundCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + { + this.id = catalogPackage.Id; + this.name = catalogPackage.Name; + this.isUpdateAvailable = catalogPackage.IsUpdateAvailable; + this.version = catalogPackage.DefaultInstallVersion.Version; + this.source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + + if (this.isUpdateAvailable) + { + this.availableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); + } + } /// - /// The name of the catalog package. + /// Gets the id of the catalog package. /// - public readonly string Name; + public string Id + { + get { return this.id; } + } /// - /// The version of the catalog package. + /// Gets the name of the catalog package. /// - public readonly string Version; + public string Name + { + get { return this.name; } + } /// - /// A boolean value indicating whether an update is available. + /// Gets the version of the catalog package. /// - public readonly bool IsUpdateAvailable; + public string Version + { + get { return this.version; } + } /// - /// The source of the catalog package. + /// Gets a value indicating whether an update is available. /// - public readonly string Source; + public bool IsUpdateAvailable + { + get { return this.isUpdateAvailable; } + } /// - /// A list of strings representing the available versions. + /// Gets the source of the catalog package. /// - public readonly string[] AvailableVersions; + public string Source + { + get { return this.source; } + } /// - /// Initializes a new instance of the class. + /// Gets a list of strings representing the available versions. /// - /// The catalog package COM object. - public FoundCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + public string[] AvailableVersions { - this.Id = catalogPackage.Id; - this.Name = catalogPackage.Name; - this.IsUpdateAvailable = catalogPackage.IsUpdateAvailable; - this.Version = catalogPackage.DefaultInstallVersion.Version; - this.Source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; - - //if (this.IsUpdateAvailable) - //{ - // this.AvailableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); - //} + get { return this.availableVersions; } } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs index 2c89634cdb..38c477d92d 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs @@ -14,42 +14,63 @@ namespace Microsoft.WinGet.Client.PSObjects /// public class InstallResult { + private readonly string correlationData; + private readonly Exception extendedErrorCode; + private readonly bool rebootRequired; + private readonly uint installerErrorCode; + private readonly InstallResultStatus status; + /// - /// The correlation data of the install result. + /// Initializes a new instance of the class. /// - public readonly string CorrelationData; + /// The install result COM object. + public InstallResult(Management.Deployment.InstallResult installResult) + { + this.correlationData = installResult.CorrelationData; + this.extendedErrorCode = installResult.ExtendedErrorCode; + this.rebootRequired = installResult.RebootRequired; + this.installerErrorCode = installResult.InstallerErrorCode; + this.status = installResult.Status; + } /// - /// The extended error code exception of the failed install result. + /// Gets the correlation data of the install result. /// - public readonly Exception ExtendedErrorCode; + public string CorrelationData + { + get { return this.correlationData; } + } /// - /// A boolean value indicating whether a reboot is required. + /// Gets the extended error code exception of the failed install result. /// - public readonly bool RebootRequired; + public Exception ExtendedErrorCode + { + get { return this.extendedErrorCode; } + } /// - /// The error code of an install. + /// Gets a value indicating whether a reboot is required. /// - public readonly uint InstallerErrorCode; + public bool RebootRequired + { + get { return this.rebootRequired; } + } /// - /// The status of the install. + /// Gets the error code of an install. /// - public readonly InstallResultStatus Status; + public uint InstallerErrorCode + { + get { return this.installerErrorCode; } + } /// - /// Initializes a new instance of the class. + /// Gets the status of the install. /// - /// The install result COM object. - public InstallResult(Management.Deployment.InstallResult installResult) + public InstallResultStatus Status { - this.CorrelationData = installResult.CorrelationData; - this.ExtendedErrorCode = installResult.ExtendedErrorCode; - this.RebootRequired = installResult.RebootRequired; - this.InstallerErrorCode = installResult.InstallerErrorCode; - this.Status = installResult.Status; + get { return this.status; } } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs index d36dca1d33..b77da9d869 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs @@ -6,7 +6,6 @@ namespace Microsoft.WinGet.Client.PSObjects { - using System; using System.Linq; /// @@ -14,52 +13,77 @@ namespace Microsoft.WinGet.Client.PSObjects /// public class InstalledCatalogPackage { + private readonly string id; + private readonly string name; + private readonly string version; + private readonly bool isUpdateAvailable; + private readonly string source; + private readonly string[] availableVersions; + /// - /// The id of the catalog package. + /// Initializes a new instance of the class. /// - public readonly string Id; + /// The catalog package COM object. + public InstalledCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + { + this.id = catalogPackage.Id; + this.name = catalogPackage.Name; + this.isUpdateAvailable = catalogPackage.IsUpdateAvailable; + this.version = catalogPackage.InstalledVersion.Version; + this.source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + + if (this.IsUpdateAvailable) + { + this.availableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); + } + } /// - /// The name of the catalog package. + /// Gets the id of the catalog package. /// - public readonly string Name; + public string Id + { + get { return this.id; } + } /// - /// The version of the catalog package. + /// Gets the name of the catalog package. /// - public readonly string Version; + public string Name + { + get { return this.name; } + } /// - /// A boolean value indicating whether an update is available. + /// Gets the version of the catalog package. /// - public readonly bool IsUpdateAvailable; + public string Version + { + get { return this.version; } + } /// - /// The source of the catalog package. + /// Gets a value indicating whether an update is available. /// - public readonly string Source; + public bool IsUpdateAvailable + { + get { return this.isUpdateAvailable; } + } /// - /// A list of strings representing the available versions. + /// Gets the source of the catalog package. /// - public readonly string[] AvailableVersions; + public string Source + { + get { return this.source; } + } /// - /// Initializes a new instance of the class. + /// Gets a list of strings representing the available versions. /// - /// The catalog package COM object. - public InstalledCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + public string[] AvailableVersions { - this.Id = catalogPackage.Id; - this.Name = catalogPackage.Name; - this.IsUpdateAvailable = catalogPackage.IsUpdateAvailable; - this.Version = catalogPackage.InstalledVersion.Version; - this.Source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; - - if (this.IsUpdateAvailable) - { - this.AvailableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); - } + get { return this.availableVersions; } } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs index 954600c22b..0ba6abe1b2 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs @@ -11,31 +11,44 @@ namespace Microsoft.WinGet.Client.PSObjects /// public class SourceResult { + private readonly string name; + private readonly string argument; + private readonly string type; + /// - /// The name of the source. + /// Initializes a new instance of the class. /// - public readonly string Name; + /// The PackageCatalogReference COM object. + public SourceResult(Management.Deployment.PackageCatalogReference catalogReference) + { + var info = catalogReference.Info; + this.name = info.Name; + this.argument = info.Argument; + this.type = info.Type; + } /// - /// The argument of the source. + /// Gets the name of the source. /// - public readonly string Argument; + public string Name + { + get { return this.name; } + } /// - /// The type of the source. + /// Gets the argument of the source. /// - public readonly string Type; + public string Argument + { + get { return this.argument; } + } /// - /// Initializes a new instance of the class. + /// Gets the type of the source. /// - /// The PackageCatalogReference COM object. - public SourceResult(Management.Deployment.PackageCatalogReference catalogReference) + public string Type { - var info = catalogReference.Info; - this.Name = info.Name; - this.Argument = info.Argument; - this.Type = info.Type; + get { return this.type; } } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs index 9a344521a5..d2573cf4b4 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs @@ -14,42 +14,63 @@ namespace Microsoft.WinGet.Client.PSObjects /// public class UninstallResult { + private readonly string correlationData; + private readonly Exception extendedErrorCode; + private readonly bool rebootRequired; + private readonly uint uninstallerErrorCode; + private readonly UninstallResultStatus status; + /// - /// The correlation data of the install result. + /// Initializes a new instance of the class. /// - public readonly string CorrelationData; + /// The uninstalll result COM object. + public UninstallResult(Management.Deployment.UninstallResult uninstallResult) + { + this.correlationData = uninstallResult.CorrelationData; + this.extendedErrorCode = uninstallResult.ExtendedErrorCode; + this.rebootRequired = uninstallResult.RebootRequired; + this.uninstallerErrorCode = uninstallResult.UninstallerErrorCode; + this.status = uninstallResult.Status; + } /// - /// The extended error code exception of the failed install result. + /// Gets the correlation data of the install result. /// - public readonly Exception ExtendedErrorCode; + public string CorrelationData + { + get { return this.correlationData; } + } /// - /// A boolean value indicating whether a reboot is required. + /// Gets the extended error code exception of the failed install result. /// - public readonly bool RebootRequired; + public Exception ExtendedErrorCode + { + get { return this.extendedErrorCode; } + } /// - /// The error code of the uninstall. + /// Gets a value indicating whether a reboot is required. /// - public readonly uint UninstallerErrorCode; + public bool RebootRequired + { + get { return this.rebootRequired; } + } /// - /// The status of the uninstall. + /// Gets the error code of an install. /// - public readonly UninstallResultStatus Status; + public uint UninstallerErrorCode + { + get { return this.uninstallerErrorCode; } + } /// - /// Initializes a new instance of the class. + /// Gets the status of the install. /// - /// The uninstalll result COM object. - public UninstallResult(Management.Deployment.UninstallResult uninstallResult) + public UninstallResultStatus Status { - this.CorrelationData = uninstallResult.CorrelationData; - this.ExtendedErrorCode = uninstallResult.ExtendedErrorCode; - this.RebootRequired = uninstallResult.RebootRequired; - this.UninstallerErrorCode = uninstallResult.UninstallerErrorCode; - this.Status = uninstallResult.Status; + get { return this.status; } } } } diff --git a/src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.ps1 b/src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.Tests.ps1 similarity index 100% rename from src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.ps1 rename to src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.Tests.ps1 diff --git a/src/PowerShell/tests/Setup.Tests.ps1 b/src/PowerShell/tests/Setup.Tests.ps1 index e69de29bb2..1c6682ed04 100644 --- a/src/PowerShell/tests/Setup.Tests.ps1 +++ b/src/PowerShell/tests/Setup.Tests.ps1 @@ -0,0 +1,12 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Setup file for all Pester tests related to the Microsoft.WinGet.Client PowerShell module. +#> + +BeforeAll { + # this calls REST API and takes roughly 1 second + wingetdev source add 'TestSource' 'https://localhost:5001/TestKit/' +} \ No newline at end of file From 46158cc7ecbb2acc565638e7aec7d9a00e6199ec Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 18 Jan 2023 23:14:30 -0800 Subject: [PATCH 05/18] fix pester configuration --- azure-pipelines.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6880257fdb..78dad66ee6 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -302,19 +302,33 @@ jobs: - task: PowerShell@2 displayName: 'Run Pester Tests for PowerShell Module' + condition: eq($(buildPlatform), 'x64') inputs: targetType: 'inline' script: | Import-Module Pester -PassThru Import-Module '$(buildOutDir)\PowerShell\Microsoft.WinGet.Client\Microsoft.WinGet.Client.psd1' - Invoke-Pester -Path 'src\PowerShell\tests\' -CI -Output Detailed -OutputFile '$(buildOutDir)\Microsoft.WinGet.Client.Tests.xml' + $config = [PesterConfiguration]@{ + Run = @{ + Path = 'src\PowerShell\tests' + } + Output = @{ + Verbosity = 'Detailed' + } + TestResult = @{ + Enabled = $true + OutputPath = '$(buildOutDir)\Microsoft.WinGet.Client.TestResults.xml' + } + } + Invoke-Pester -Configuration $config pwsh: true - task: PublishTestResults@2 displayName: 'Publish Pester Tests' + condition: eq($(buildPlatform), 'x64') inputs: testResultsFormat: 'NUnit' - testResultsFiles: '$(buildOutDir)\Microsoft.WinGet.Client.Tests.xml' + testResultsFiles: '$(buildOutDir)\Microsoft.WinGet.Client.TestResults.xml' mergeTestResults: true failTaskOnFailedTests: true From b40488a21a42c0c1acac071cbaf1ae78a89a2f2b Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 18 Jan 2023 23:29:39 -0800 Subject: [PATCH 06/18] fix variables --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 78dad66ee6..b606765813 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -302,7 +302,7 @@ jobs: - task: PowerShell@2 displayName: 'Run Pester Tests for PowerShell Module' - condition: eq($(buildPlatform), 'x64') + condition: eq(variables['buildPlatform], 'x64') inputs: targetType: 'inline' script: | @@ -325,7 +325,7 @@ jobs: - task: PublishTestResults@2 displayName: 'Publish Pester Tests' - condition: eq($(buildPlatform), 'x64') + condition: eq(variables['buildPlatform], 'x64') inputs: testResultsFormat: 'NUnit' testResultsFiles: '$(buildOutDir)\Microsoft.WinGet.Client.TestResults.xml' From 24e93c5d9cffffc37267631f0b8ee8404be1090d Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 18 Jan 2023 23:30:43 -0800 Subject: [PATCH 07/18] fix variables again --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b606765813..c973302567 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -302,7 +302,7 @@ jobs: - task: PowerShell@2 displayName: 'Run Pester Tests for PowerShell Module' - condition: eq(variables['buildPlatform], 'x64') + condition: eq(variables[buildPlatform], 'x64') inputs: targetType: 'inline' script: | @@ -325,7 +325,7 @@ jobs: - task: PublishTestResults@2 displayName: 'Publish Pester Tests' - condition: eq(variables['buildPlatform], 'x64') + condition: eq(variables[buildPlatform], 'x64') inputs: testResultsFormat: 'NUnit' testResultsFiles: '$(buildOutDir)\Microsoft.WinGet.Client.TestResults.xml' From deff6f635421fad39b9bbdbd15065f99b781f647 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 18 Jan 2023 23:42:03 -0800 Subject: [PATCH 08/18] try with quotes --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c973302567..7e3cc96573 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -302,7 +302,7 @@ jobs: - task: PowerShell@2 displayName: 'Run Pester Tests for PowerShell Module' - condition: eq(variables[buildPlatform], 'x64') + condition: eq(variables['buildPlatform'], 'x64') inputs: targetType: 'inline' script: | @@ -325,7 +325,7 @@ jobs: - task: PublishTestResults@2 displayName: 'Publish Pester Tests' - condition: eq(variables[buildPlatform], 'x64') + condition: eq(variables['buildPlatform'], 'x64') inputs: testResultsFormat: 'NUnit' testResultsFiles: '$(buildOutDir)\Microsoft.WinGet.Client.TestResults.xml' From 29e3a67c647512afc07c5a6b9d5b4be887bb00fa Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Thu, 19 Jan 2023 09:48:22 -0800 Subject: [PATCH 09/18] reset pipeline changes --- azure-pipelines.yml | 142 +++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 87 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7e3cc96573..ec5edba4d8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -146,28 +146,28 @@ jobs: inputs: secureFile: 'PsExec.exe' - # - task: CmdLine@2 - # displayName: Run Unit Tests Unpackaged Under System Context - # inputs: - # script: | - # $(PsExec.secureFilePath) -accepteula -s -i $(buildOutDir)\AppInstallerCLITests\AppInstallerCLITests.exe -logto $(artifactsDir)\AICLI-Unpackaged-System.log -s -r junit -o $(artifactsDir)\TEST-AppInstallerCLI-Unpackaged-System.xml - # workingDirectory: '$(buildOutDir)\AppInstallerCLITests' - # continueOnError: true - - # - task: PowerShell@2 - # displayName: Run Unit Tests Packaged - # inputs: - # filePath: 'src\AppInstallerCLITests\Run-TestsInPackage.ps1' - # arguments: '-Args "~[pips]" -BuildRoot $(buildOutDir) -PackageRoot AppInstallerCLIPackage\bin\$(buildPlatform)\$(buildConfiguration) -LogTarget $(artifactsDir)\AICLI-Packaged.log -TestResultsTarget $(artifactsDir)\TEST-AppInstallerCLI-Packaged.xml -ScriptWait' - # workingDirectory: 'src' - # continueOnError: true - - # - task: PublishTestResults@2 - # displayName: Publish Unit Test Results - # inputs: - # testResultsFormat: 'JUnit' - # testResultsFiles: '$(artifactsDir)\TEST-*.xml' - # failTaskOnFailedTests: true + - task: CmdLine@2 + displayName: Run Unit Tests Unpackaged Under System Context + inputs: + script: | + $(PsExec.secureFilePath) -accepteula -s -i $(buildOutDir)\AppInstallerCLITests\AppInstallerCLITests.exe -logto $(artifactsDir)\AICLI-Unpackaged-System.log -s -r junit -o $(artifactsDir)\TEST-AppInstallerCLI-Unpackaged-System.xml + workingDirectory: '$(buildOutDir)\AppInstallerCLITests' + continueOnError: true + + - task: PowerShell@2 + displayName: Run Unit Tests Packaged + inputs: + filePath: 'src\AppInstallerCLITests\Run-TestsInPackage.ps1' + arguments: '-Args "~[pips]" -BuildRoot $(buildOutDir) -PackageRoot AppInstallerCLIPackage\bin\$(buildPlatform)\$(buildConfiguration) -LogTarget $(artifactsDir)\AICLI-Packaged.log -TestResultsTarget $(artifactsDir)\TEST-AppInstallerCLI-Packaged.xml -ScriptWait' + workingDirectory: 'src' + continueOnError: true + + - task: PublishTestResults@2 + displayName: Publish Unit Test Results + inputs: + testResultsFormat: 'JUnit' + testResultsFiles: '$(artifactsDir)\TEST-*.xml' + failTaskOnFailedTests: true - task: DownloadSecureFile@1 name: AppInstallerTest @@ -248,30 +248,30 @@ jobs: TargetFolder: 'src\AppInstallerCLIPackage\bin\$(buildPlatform)\$(buildConfiguration)' Contents: Microsoft.Management.Deployment.winmd - # - template: templates/e2e-test.template.yml - # parameters: - # title: "E2E Tests Packaged" - # isPackaged: true - # filter: "TestCategory!=InProcess&TestCategory!=OutOfProcess" - - # - template: templates/e2e-test.template.yml - # parameters: - # title: "COM API E2E Tests (In-process)" - # isPackaged: false - # filter: "TestCategory=InProcess" - - # - template: templates/e2e-test.template.yml - # parameters: - # title: "COM API E2E Tests (Out-of-process)" - # isPackaged: true - # filter: "TestCategory=OutOfProcess" - - # - task: CopyFiles@2 - # displayName: 'Copy E2E Tests Package Log to artifacts folder' - # inputs: - # SourceFolder: '$(temp)\E2ETestLogs' - # TargetFolder: '$(artifactsDir)\E2ETestsPackagedLog' - # condition: succeededOrFailed() + - template: templates/e2e-test.template.yml + parameters: + title: "E2E Tests Packaged" + isPackaged: true + filter: "TestCategory!=InProcess&TestCategory!=OutOfProcess" + + - template: templates/e2e-test.template.yml + parameters: + title: "COM API E2E Tests (In-process)" + isPackaged: false + filter: "TestCategory=InProcess" + + - template: templates/e2e-test.template.yml + parameters: + title: "COM API E2E Tests (Out-of-process)" + isPackaged: true + filter: "TestCategory=OutOfProcess" + + - task: CopyFiles@2 + displayName: 'Copy E2E Tests Package Log to artifacts folder' + inputs: + SourceFolder: '$(temp)\E2ETestLogs' + TargetFolder: '$(artifactsDir)\E2ETestsPackagedLog' + condition: succeededOrFailed() - task: CopyFiles@2 displayName: 'Copy Files: WinGetUtilInterop.UnitTests' @@ -281,15 +281,15 @@ jobs: CleanTargetFolder: true OverWrite: true - # - task: VSTest@2 - # displayName: 'Run tests: WinGetUtilInterop.UnitTests' - # inputs: - # testSelector: 'testAssemblies' - # testAssemblyVer2: 'WinGetUtilInterop.UnitTests.dll' - # searchFolder: '$(Build.ArtifactStagingDirectory)\WinGetUtilInterop.UnitTests' - # codeCoverageEnabled: true - # platform: 'Any CPU' - # configuration: '$(BuildConfiguration)' + - task: VSTest@2 + displayName: 'Run tests: WinGetUtilInterop.UnitTests' + inputs: + testSelector: 'testAssemblies' + testAssemblyVer2: 'WinGetUtilInterop.UnitTests.dll' + searchFolder: '$(Build.ArtifactStagingDirectory)\WinGetUtilInterop.UnitTests' + codeCoverageEnabled: true + platform: 'Any CPU' + configuration: '$(BuildConfiguration)' - task: CopyFiles@2 displayName: 'Copy Util to artifacts folder' @@ -300,38 +300,6 @@ jobs: TargetFolder: '$(artifactsDir)' condition: succeededOrFailed() - - task: PowerShell@2 - displayName: 'Run Pester Tests for PowerShell Module' - condition: eq(variables['buildPlatform'], 'x64') - inputs: - targetType: 'inline' - script: | - Import-Module Pester -PassThru - Import-Module '$(buildOutDir)\PowerShell\Microsoft.WinGet.Client\Microsoft.WinGet.Client.psd1' - $config = [PesterConfiguration]@{ - Run = @{ - Path = 'src\PowerShell\tests' - } - Output = @{ - Verbosity = 'Detailed' - } - TestResult = @{ - Enabled = $true - OutputPath = '$(buildOutDir)\Microsoft.WinGet.Client.TestResults.xml' - } - } - Invoke-Pester -Configuration $config - pwsh: true - - - task: PublishTestResults@2 - displayName: 'Publish Pester Tests' - condition: eq(variables['buildPlatform'], 'x64') - inputs: - testResultsFormat: 'NUnit' - testResultsFiles: '$(buildOutDir)\Microsoft.WinGet.Client.TestResults.xml' - mergeTestResults: true - failTaskOnFailedTests: true - - task: CopyFiles@2 displayName: 'Copy PowerShell Module Files' inputs: From af91d490a21dc9dbf94917691f52454f42efed18 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Thu, 19 Jan 2023 09:52:44 -0800 Subject: [PATCH 10/18] change output type --- .../Microsoft.WinGet.Client/Commands/FindPackageCommand.cs | 2 +- .../Microsoft.WinGet.Client/Commands/GetPackageCommand.cs | 2 +- .../Microsoft.WinGet.Client/Commands/GetSourceCommand.cs | 3 +-- .../Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs | 2 +- .../Commands/UninstallPackageCommand.cs | 2 +- .../Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/FindPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/FindPackageCommand.cs index f8e0eb21d4..ae8c76c057 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/FindPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/FindPackageCommand.cs @@ -15,7 +15,7 @@ namespace Microsoft.WinGet.Client.Commands /// Searches configured sources for packages. /// [Cmdlet(VerbsCommon.Find, Constants.WinGetNouns.Package)] - [OutputType(typeof(Management.Deployment.CatalogPackage))] + [OutputType(typeof(PSObjects.FoundCatalogPackage))] public sealed class FindPackageCommand : BaseFinderExtendedCommand { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/GetPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/GetPackageCommand.cs index 08629583ae..635cebda86 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/GetPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/GetPackageCommand.cs @@ -15,7 +15,7 @@ namespace Microsoft.WinGet.Client.Commands /// Searches configured sources for packages. /// [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.Package)] - [OutputType(typeof(CatalogPackage))] + [OutputType(typeof(PSObjects.InstalledCatalogPackage))] public sealed class GetPackageCommand : BaseFinderExtendedCommand { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/GetSourceCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/GetSourceCommand.cs index a7575e1bc2..56ebd38387 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/GetSourceCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/GetSourceCommand.cs @@ -7,7 +7,6 @@ namespace Microsoft.WinGet.Client.Commands { using System.Management.Automation; - using Microsoft.Management.Deployment; using Microsoft.WinGet.Client.Commands.Common; using Microsoft.WinGet.Client.Common; @@ -15,7 +14,7 @@ namespace Microsoft.WinGet.Client.Commands /// Retrieves the list of configured sources. /// [Cmdlet(VerbsCommon.Get, Constants.WinGetNouns.Source)] - [OutputType(typeof(PackageCatalogReference))] + [OutputType(typeof(PSObjects.SourceResult))] public sealed class GetSourceCommand : BaseClientCommand { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs index b02ce4789d..73dc11b003 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/InstallPackageCommand.cs @@ -21,7 +21,7 @@ namespace Microsoft.WinGet.Client.Commands Constants.WinGetNouns.Package, DefaultParameterSetName = Constants.FoundSet, SupportsShouldProcess = true)] - [OutputType(typeof(InstallResult))] + [OutputType(typeof(PSObjects.InstallResult))] public sealed class InstallPackageCommand : BaseInstallCommand { private ProcessorArchitecture architecture; diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/UninstallPackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/UninstallPackageCommand.cs index 9e4951d86f..63e80e1bc0 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/UninstallPackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/UninstallPackageCommand.cs @@ -22,7 +22,7 @@ namespace Microsoft.WinGet.Client.Commands Constants.WinGetNouns.Package, DefaultParameterSetName = Constants.FoundSet, SupportsShouldProcess = true)] - [OutputType(typeof(UninstallResult))] + [OutputType(typeof(PSObjects.UninstallResult))] public sealed class UninstallPackageCommand : BasePackageCommand { /// diff --git a/src/PowerShell/Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs b/src/PowerShell/Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs index fd7c462587..892c216f3b 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/Commands/UpdatePackageCommand.cs @@ -20,7 +20,7 @@ namespace Microsoft.WinGet.Client.Commands Constants.WinGetNouns.Package, DefaultParameterSetName = Constants.FoundSet, SupportsShouldProcess = true)] - [OutputType(typeof(InstallResult))] + [OutputType(typeof(PSObjects.InstallResult))] public sealed class UpdatePackageCommand : BaseInstallCommand { /// From 6aa9ed96930c720d40048cd1f7a09bc25bce7e32 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Thu, 19 Jan 2023 10:06:00 -0800 Subject: [PATCH 11/18] fix spelling --- .../PSObjects/UninstallResult.cs | 10 +++++----- src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs index d2573cf4b4..d7f1e0a9e9 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs @@ -23,7 +23,7 @@ public class UninstallResult /// /// Initializes a new instance of the class. /// - /// The uninstalll result COM object. + /// The uninstall result COM object. public UninstallResult(Management.Deployment.UninstallResult uninstallResult) { this.correlationData = uninstallResult.CorrelationData; @@ -34,7 +34,7 @@ public UninstallResult(Management.Deployment.UninstallResult uninstallResult) } /// - /// Gets the correlation data of the install result. + /// Gets the correlation data of the uninstall result. /// public string CorrelationData { @@ -42,7 +42,7 @@ public string CorrelationData } /// - /// Gets the extended error code exception of the failed install result. + /// Gets the extended error code exception of the failed uninstall result. /// public Exception ExtendedErrorCode { @@ -58,7 +58,7 @@ public bool RebootRequired } /// - /// Gets the error code of an install. + /// Gets the error code of an uninstall. /// public uint UninstallerErrorCode { @@ -66,7 +66,7 @@ public uint UninstallerErrorCode } /// - /// Gets the status of the install. + /// Gets the status of the uninstall. /// public UninstallResultStatus Status { diff --git a/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 b/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 index cce4063ed2..1c57ef8394 100644 --- a/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 +++ b/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 @@ -6,7 +6,7 @@ Tests for the Get-WinGetPackage cmdlet in the Microsoft.WinGet.Client PowerShell module. #> -Describe 'Install-WinGetPackage' { +Describe 'Get-WinGetPackage' { It 'Install by Id' { $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' From 8e3bc25cd0b5e224627bb1e15c412bcf7e5e9965 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Thu, 19 Jan 2023 14:37:11 -0800 Subject: [PATCH 12/18] address PR feedback --- .../PSObjects/CatalogPackage.cs | 44 ++++++++++++ .../PSObjects/FoundCatalogPackage.cs | 71 +++---------------- .../PSObjects/InstallResult.cs | 41 +++-------- .../PSObjects/InstalledCatalogPackage.cs | 69 ++---------------- .../PSObjects/SourceResult.cs | 25 ++----- .../PSObjects/UninstallResult.cs | 41 +++-------- src/PowerShell/tests/Setup.Tests.ps1 | 10 ++- 7 files changed, 94 insertions(+), 207 deletions(-) create mode 100644 src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs new file mode 100644 index 0000000000..bc23fa80b2 --- /dev/null +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.PSObjects +{ + /// + /// CatalogPackage wrapper object for displaying to PowerShell. + /// + public class CatalogPackage + { + /// + /// Gets or sets the name of the catalog package. + /// + public string Name { get; protected set; } + + /// + /// Gets or sets the id of the catalog package. + /// + public string Id { get; protected set; } + + /// + /// Gets or sets the version of the catalog package. + /// + public string Version { get; protected set; } + + /// + /// Gets or sets a value indicating whether an update is available. + /// + public bool IsUpdateAvailable { get; protected set; } + + /// + /// Gets or sets the source name of the catalog package. + /// + public string Source { get; protected set; } + + /// + /// Gets or sets a list of strings representing the available versions. + /// + public string[] AvailableVersions { get; protected set; } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs index 9f0c0f8e2d..0cf32a90be 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs @@ -11,79 +11,24 @@ namespace Microsoft.WinGet.Client.PSObjects /// /// FoundCatalogPackage wrapper object for displaying to PowerShell. /// - public class FoundCatalogPackage + public class FoundCatalogPackage : CatalogPackage { - private readonly string id; - private readonly string name; - private readonly string version; - private readonly bool isUpdateAvailable; - private readonly string source; - private readonly string[] availableVersions; - /// /// Initializes a new instance of the class. /// /// The catalog package COM object. public FoundCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) { - this.id = catalogPackage.Id; - this.name = catalogPackage.Name; - this.isUpdateAvailable = catalogPackage.IsUpdateAvailable; - this.version = catalogPackage.DefaultInstallVersion.Version; - this.source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + this.Id = catalogPackage.Id; + this.Name = catalogPackage.Name; + this.IsUpdateAvailable = catalogPackage.IsUpdateAvailable; + this.Version = catalogPackage.DefaultInstallVersion.Version; + this.Source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; - if (this.isUpdateAvailable) + if (this.IsUpdateAvailable) { - this.availableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); + this.AvailableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); } } - - /// - /// Gets the id of the catalog package. - /// - public string Id - { - get { return this.id; } - } - - /// - /// Gets the name of the catalog package. - /// - public string Name - { - get { return this.name; } - } - - /// - /// Gets the version of the catalog package. - /// - public string Version - { - get { return this.version; } - } - - /// - /// Gets a value indicating whether an update is available. - /// - public bool IsUpdateAvailable - { - get { return this.isUpdateAvailable; } - } - - /// - /// Gets the source of the catalog package. - /// - public string Source - { - get { return this.source; } - } - - /// - /// Gets a list of strings representing the available versions. - /// - public string[] AvailableVersions - { - get { return this.availableVersions; } - } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs index 38c477d92d..4b303b7417 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs @@ -14,63 +14,42 @@ namespace Microsoft.WinGet.Client.PSObjects /// public class InstallResult { - private readonly string correlationData; - private readonly Exception extendedErrorCode; - private readonly bool rebootRequired; - private readonly uint installerErrorCode; - private readonly InstallResultStatus status; - /// /// Initializes a new instance of the class. /// /// The install result COM object. public InstallResult(Management.Deployment.InstallResult installResult) { - this.correlationData = installResult.CorrelationData; - this.extendedErrorCode = installResult.ExtendedErrorCode; - this.rebootRequired = installResult.RebootRequired; - this.installerErrorCode = installResult.InstallerErrorCode; - this.status = installResult.Status; + this.CorrelationData = installResult.CorrelationData; + this.ExtendedErrorCode = installResult.ExtendedErrorCode; + this.RebootRequired = installResult.RebootRequired; + this.InstallerErrorCode = installResult.InstallerErrorCode; + this.Status = installResult.Status; } /// /// Gets the correlation data of the install result. /// - public string CorrelationData - { - get { return this.correlationData; } - } + public string CorrelationData { get; private set; } /// /// Gets the extended error code exception of the failed install result. /// - public Exception ExtendedErrorCode - { - get { return this.extendedErrorCode; } - } + public Exception ExtendedErrorCode { get; private set; } /// /// Gets a value indicating whether a reboot is required. /// - public bool RebootRequired - { - get { return this.rebootRequired; } - } + public bool RebootRequired { get; private set; } /// /// Gets the error code of an install. /// - public uint InstallerErrorCode - { - get { return this.installerErrorCode; } - } + public uint InstallerErrorCode { get; private set; } /// /// Gets the status of the install. /// - public InstallResultStatus Status - { - get { return this.status; } - } + public InstallResultStatus Status { get; private set; } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs index b77da9d869..2d810b67cf 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs @@ -11,79 +11,24 @@ namespace Microsoft.WinGet.Client.PSObjects /// /// CatalogPackage wrapper object for displaying to PowerShell. /// - public class InstalledCatalogPackage + public class InstalledCatalogPackage : CatalogPackage { - private readonly string id; - private readonly string name; - private readonly string version; - private readonly bool isUpdateAvailable; - private readonly string source; - private readonly string[] availableVersions; - /// /// Initializes a new instance of the class. /// /// The catalog package COM object. public InstalledCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) { - this.id = catalogPackage.Id; - this.name = catalogPackage.Name; - this.isUpdateAvailable = catalogPackage.IsUpdateAvailable; - this.version = catalogPackage.InstalledVersion.Version; - this.source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + this.Id = catalogPackage.Id; + this.Name = catalogPackage.Name; + this.IsUpdateAvailable = catalogPackage.IsUpdateAvailable; + this.Version = catalogPackage.InstalledVersion.Version; + this.Source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; if (this.IsUpdateAvailable) { - this.availableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); + this.AvailableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); } } - - /// - /// Gets the id of the catalog package. - /// - public string Id - { - get { return this.id; } - } - - /// - /// Gets the name of the catalog package. - /// - public string Name - { - get { return this.name; } - } - - /// - /// Gets the version of the catalog package. - /// - public string Version - { - get { return this.version; } - } - - /// - /// Gets a value indicating whether an update is available. - /// - public bool IsUpdateAvailable - { - get { return this.isUpdateAvailable; } - } - - /// - /// Gets the source of the catalog package. - /// - public string Source - { - get { return this.source; } - } - - /// - /// Gets a list of strings representing the available versions. - /// - public string[] AvailableVersions - { - get { return this.availableVersions; } - } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs index 0ba6abe1b2..3c97347487 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/SourceResult.cs @@ -11,10 +11,6 @@ namespace Microsoft.WinGet.Client.PSObjects /// public class SourceResult { - private readonly string name; - private readonly string argument; - private readonly string type; - /// /// Initializes a new instance of the class. /// @@ -22,33 +18,24 @@ public class SourceResult public SourceResult(Management.Deployment.PackageCatalogReference catalogReference) { var info = catalogReference.Info; - this.name = info.Name; - this.argument = info.Argument; - this.type = info.Type; + this.Name = info.Name; + this.Argument = info.Argument; + this.Type = info.Type; } /// /// Gets the name of the source. /// - public string Name - { - get { return this.name; } - } + public string Name { get; private set; } /// /// Gets the argument of the source. /// - public string Argument - { - get { return this.argument; } - } + public string Argument { get; private set; } /// /// Gets the type of the source. /// - public string Type - { - get { return this.type; } - } + public string Type { get; private set; } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs index d7f1e0a9e9..4745538b0a 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs @@ -14,63 +14,42 @@ namespace Microsoft.WinGet.Client.PSObjects /// public class UninstallResult { - private readonly string correlationData; - private readonly Exception extendedErrorCode; - private readonly bool rebootRequired; - private readonly uint uninstallerErrorCode; - private readonly UninstallResultStatus status; - /// /// Initializes a new instance of the class. /// /// The uninstall result COM object. public UninstallResult(Management.Deployment.UninstallResult uninstallResult) { - this.correlationData = uninstallResult.CorrelationData; - this.extendedErrorCode = uninstallResult.ExtendedErrorCode; - this.rebootRequired = uninstallResult.RebootRequired; - this.uninstallerErrorCode = uninstallResult.UninstallerErrorCode; - this.status = uninstallResult.Status; + this.CorrelationData = uninstallResult.CorrelationData; + this.ExtendedErrorCode = uninstallResult.ExtendedErrorCode; + this.RebootRequired = uninstallResult.RebootRequired; + this.UninstallerErrorCode = uninstallResult.UninstallerErrorCode; + this.Status = uninstallResult.Status; } /// /// Gets the correlation data of the uninstall result. /// - public string CorrelationData - { - get { return this.correlationData; } - } + public string CorrelationData { get; private set; } /// /// Gets the extended error code exception of the failed uninstall result. /// - public Exception ExtendedErrorCode - { - get { return this.extendedErrorCode; } - } + public Exception ExtendedErrorCode { get; private set; } /// /// Gets a value indicating whether a reboot is required. /// - public bool RebootRequired - { - get { return this.rebootRequired; } - } + public bool RebootRequired { get; private set; } /// /// Gets the error code of an uninstall. /// - public uint UninstallerErrorCode - { - get { return this.uninstallerErrorCode; } - } + public uint UninstallerErrorCode { get; private set; } /// /// Gets the status of the uninstall. /// - public UninstallResultStatus Status - { - get { return this.status; } - } + public UninstallResultStatus Status { get; private set; } } } diff --git a/src/PowerShell/tests/Setup.Tests.ps1 b/src/PowerShell/tests/Setup.Tests.ps1 index 1c6682ed04..a4920fdde2 100644 --- a/src/PowerShell/tests/Setup.Tests.ps1 +++ b/src/PowerShell/tests/Setup.Tests.ps1 @@ -7,6 +7,14 @@ #> BeforeAll { - # this calls REST API and takes roughly 1 second wingetdev source add 'TestSource' 'https://localhost:5001/TestKit/' +} + +AfterAll { + # Uninstall all test packages for proper cleanup. + Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller + Uninstall-WinGetPackage -Id AppInstallerTest.TestPortableExe + + # Removal of source requires administrator. + wingetdev source remove 'TestSource' } \ No newline at end of file From 43fdff34ae24ed85550899eb667e390feca7f7d6 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Thu, 19 Jan 2023 14:41:03 -0800 Subject: [PATCH 13/18] remove correlation data --- .../Microsoft.WinGet.Client/Module/Format.ps1xml | 12 ------------ .../PSObjects/InstallResult.cs | 6 ------ .../PSObjects/UninstallResult.cs | 6 ------ 3 files changed, 24 deletions(-) diff --git a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml index fcc317d4fc..0e3fa9e369 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml +++ b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml @@ -110,9 +110,6 @@ - - - @@ -129,9 +126,6 @@ $_.ExtendedErrorCode - - $_.CorrelationData - @@ -156,9 +150,6 @@ - - - @@ -175,9 +166,6 @@ $_.ExtendedErrorCode - - $_.CorrelationData - diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs index 4b303b7417..632a889598 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs @@ -20,18 +20,12 @@ public class InstallResult /// The install result COM object. public InstallResult(Management.Deployment.InstallResult installResult) { - this.CorrelationData = installResult.CorrelationData; this.ExtendedErrorCode = installResult.ExtendedErrorCode; this.RebootRequired = installResult.RebootRequired; this.InstallerErrorCode = installResult.InstallerErrorCode; this.Status = installResult.Status; } - /// - /// Gets the correlation data of the install result. - /// - public string CorrelationData { get; private set; } - /// /// Gets the extended error code exception of the failed install result. /// diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs index 4745538b0a..2bc125b24c 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs @@ -20,18 +20,12 @@ public class UninstallResult /// The uninstall result COM object. public UninstallResult(Management.Deployment.UninstallResult uninstallResult) { - this.CorrelationData = uninstallResult.CorrelationData; this.ExtendedErrorCode = uninstallResult.ExtendedErrorCode; this.RebootRequired = uninstallResult.RebootRequired; this.UninstallerErrorCode = uninstallResult.UninstallerErrorCode; this.Status = uninstallResult.Status; } - /// - /// Gets the correlation data of the uninstall result. - /// - public string CorrelationData { get; private set; } - /// /// Gets the extended error code exception of the failed uninstall result. /// From 7cee6afe127d2435c04c5d0086abdc53c1758467 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Wed, 1 Feb 2023 17:13:26 -0800 Subject: [PATCH 14/18] add support packageversioninfo and compareVersion --- .../Module/Format.ps1xml | 64 +++++++++++ .../PSObjects/CatalogPackage.cs | 105 ++++++++++++++++-- .../PSObjects/FoundCatalogPackage.cs | 12 +- .../PSObjects/InstallResult.cs | 58 ++++++++-- .../PSObjects/InstalledCatalogPackage.cs | 12 +- .../PSObjects/PackageVersionInfo.cs | 103 +++++++++++++++++ .../PSObjects/UninstallResult.cs | 55 +++++++-- 7 files changed, 354 insertions(+), 55 deletions(-) create mode 100644 src/PowerShell/Microsoft.WinGet.Client/PSObjects/PackageVersionInfo.cs diff --git a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml index 0e3fa9e369..b07288d898 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml +++ b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml @@ -110,6 +110,9 @@ + + + @@ -126,6 +129,9 @@ $_.ExtendedErrorCode + + $_.CorrelationData + @@ -150,6 +156,9 @@ + + + @@ -166,6 +175,9 @@ $_.ExtendedErrorCode + + $_.CorrelationData + @@ -206,5 +218,57 @@ + + Microsoft.WinGet.Client.PSObjects.PackageVersionInfo + + Microsoft.WinGet.Client.PSObjects.PackageVersionInfo + + + + + + + + + + + + + + + + + + + + + + + + + + + $_.DisplayName + + + $_.Id + + + $_.Publisher + + + $_.Channel + + + $_.PackageFamilyNames + + + $_.ProductCodes + + + + + + \ No newline at end of file diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs index bc23fa80b2..0e1b464b63 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs @@ -6,20 +6,47 @@ namespace Microsoft.WinGet.Client.PSObjects { + using System.Linq; + using Microsoft.Management.Deployment; + using Microsoft.WinGet.Client.Exceptions; + /// /// CatalogPackage wrapper object for displaying to PowerShell. /// public class CatalogPackage { + private Management.Deployment.CatalogPackage catalogPackage; + /// - /// Gets or sets the name of the catalog package. + /// Initializes a new instance of the class. /// - public string Name { get; protected set; } + /// CatalogPackage COM object. + public CatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + { + this.catalogPackage = catalogPackage; + } /// - /// Gets or sets the id of the catalog package. + /// Gets the name of the catalog package. /// - public string Id { get; protected set; } + public string Name + { + get + { + return this.catalogPackage.Name; + } + } + + /// + /// Gets the id of the catalog package. + /// + public string Id + { + get + { + return this.catalogPackage.Id; + } + } /// /// Gets or sets the version of the catalog package. @@ -27,18 +54,76 @@ public class CatalogPackage public string Version { get; protected set; } /// - /// Gets or sets a value indicating whether an update is available. + /// Gets a value indicating whether an update is available. + /// + public bool IsUpdateAvailable + { + get + { + return this.catalogPackage.IsUpdateAvailable; + } + } + + /// + /// Gets the source name of the catalog package. + /// + public string Source + { + get + { + return this.catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + } + } + + /// + /// Gets list of strings representing the available versions. + /// + public string[] AvailableVersions + { + get + { + return this.AvailablePackageVersionIds.Select(i => i.Version).ToArray(); + } + } + + /// + /// Gets a list of available package version ids for the package. /// - public bool IsUpdateAvailable { get; protected set; } + private PackageVersionId[] AvailablePackageVersionIds + { + get + { + return this.catalogPackage.AvailableVersions.ToArray(); + } + } /// - /// Gets or sets the source name of the catalog package. + /// Checks the installed status of the catalog package. /// - public string Source { get; protected set; } + /// CheckInstalledStatus string. + public string CheckInstalledStatus() + { + return this.catalogPackage.CheckInstalledStatus().Status.ToString(); + } /// - /// Gets or sets a list of strings representing the available versions. + /// Gets the PackageVersionInfo PSObject that corresponds with the version string. /// - public string[] AvailableVersions { get; protected set; } + /// Version string. + /// PackageVersionInfo PSObject. + /// Throws an exception if no package is found. + public PackageVersionInfo GetPackageVersionInfo(string version) + { + // get specific version that matches + PackageVersionId packageVersionId = this.AvailablePackageVersionIds.FirstOrDefault(x => x.Version == version); + if (packageVersionId != null) + { + return new PackageVersionInfo(this.catalogPackage.GetPackageVersionInfo(packageVersionId)); + } + else + { + throw new NoPackageFoundException(); + } + } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs index 0cf32a90be..35c017e87f 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs @@ -6,8 +6,6 @@ namespace Microsoft.WinGet.Client.PSObjects { - using System.Linq; - /// /// FoundCatalogPackage wrapper object for displaying to PowerShell. /// @@ -18,17 +16,9 @@ public class FoundCatalogPackage : CatalogPackage /// /// The catalog package COM object. public FoundCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + : base(catalogPackage) { - this.Id = catalogPackage.Id; - this.Name = catalogPackage.Name; - this.IsUpdateAvailable = catalogPackage.IsUpdateAvailable; this.Version = catalogPackage.DefaultInstallVersion.Version; - this.Source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; - - if (this.IsUpdateAvailable) - { - this.AvailableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); - } } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs index 632a889598..987ec5ea82 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs @@ -7,43 +7,77 @@ namespace Microsoft.WinGet.Client.PSObjects { using System; - using Microsoft.Management.Deployment; /// /// InstallResult wrapper object for displaying to PowerShell. /// public class InstallResult { + private Management.Deployment.InstallResult installResult; + /// /// Initializes a new instance of the class. /// /// The install result COM object. public InstallResult(Management.Deployment.InstallResult installResult) { - this.ExtendedErrorCode = installResult.ExtendedErrorCode; - this.RebootRequired = installResult.RebootRequired; - this.InstallerErrorCode = installResult.InstallerErrorCode; - this.Status = installResult.Status; + this.installResult = installResult; } /// - /// Gets the extended error code exception of the failed install result. + /// Gets the correlation data of the install result. /// - public Exception ExtendedErrorCode { get; private set; } + public string CorrelationData + { + get + { + return this.installResult.CorrelationData; + } + } /// - /// Gets a value indicating whether a reboot is required. + /// Gets the error code of an install. /// - public bool RebootRequired { get; private set; } + public uint InstallerErrorCode + { + get + { + return this.installResult.InstallerErrorCode; + } + } /// - /// Gets the error code of an install. + /// Gets the extended error code exception of the failed install result. /// - public uint InstallerErrorCode { get; private set; } + public Exception ExtendedErrorCode + { + get + { + return this.installResult.ExtendedErrorCode; + } + } + + /// + /// Gets a value indicating whether a reboot is required. + /// + public bool RebootRequired + { + get + { + return this.installResult.RebootRequired; + } + } /// /// Gets the status of the install. /// - public InstallResultStatus Status { get; private set; } + public string Status + { + get + { + return this.installResult.Status.ToString(); + } + } + } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs index 2d810b67cf..0454620c8e 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs @@ -6,8 +6,6 @@ namespace Microsoft.WinGet.Client.PSObjects { - using System.Linq; - /// /// CatalogPackage wrapper object for displaying to PowerShell. /// @@ -18,17 +16,9 @@ public class InstalledCatalogPackage : CatalogPackage /// /// The catalog package COM object. public InstalledCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) + : base(catalogPackage) { - this.Id = catalogPackage.Id; - this.Name = catalogPackage.Name; - this.IsUpdateAvailable = catalogPackage.IsUpdateAvailable; this.Version = catalogPackage.InstalledVersion.Version; - this.Source = catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; - - if (this.IsUpdateAvailable) - { - this.AvailableVersions = catalogPackage.AvailableVersions.Select(i => i.Version).ToArray(); - } } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/PackageVersionInfo.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/PackageVersionInfo.cs new file mode 100644 index 0000000000..55faef8d3f --- /dev/null +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/PackageVersionInfo.cs @@ -0,0 +1,103 @@ +// ----------------------------------------------------------------------------- +// +// Copyright (c) Microsoft Corporation. Licensed under the MIT License. +// +// ----------------------------------------------------------------------------- + +namespace Microsoft.WinGet.Client.PSObjects +{ + using System.Linq; + + /// + /// CatalogPackage wrapper object for displaying to PowerShell. + /// + public class PackageVersionInfo + { + private Management.Deployment.PackageVersionInfo packageVersionInfo; + + /// + /// Initializes a new instance of the class. + /// + /// PackageVersionInfo COM object. + public PackageVersionInfo(Management.Deployment.PackageVersionInfo packageVersionInfo) + { + this.packageVersionInfo = packageVersionInfo; + } + + /// + /// Gets the name of the package version info. + /// + public string DisplayName + { + get + { + return this.packageVersionInfo.DisplayName; + } + } + + /// + /// Gets the id of the package version info. + /// + public string Id + { + get + { + return this.packageVersionInfo.Id; + } + } + + /// + /// Gets the publisher of the package version info. + /// + public string Publisher + { + get + { + return this.packageVersionInfo.Publisher; + } + } + + /// + /// Gets the channel of the package version info. + /// + public string Channel + { + get + { + return this.packageVersionInfo.Channel; + } + } + + /// + /// Gets the list of package family names of the package version info. + /// + public string[] PackageFamilyNames + { + get + { + return this.packageVersionInfo.PackageFamilyNames.ToArray(); + } + } + + /// + /// Gets the list of product codes of the package version info. + /// + public string[] ProductCodes + { + get + { + return this.packageVersionInfo.ProductCodes.ToArray(); + } + } + + /// + /// Compares the version string with the package version info and returns the CompareResult. + /// + /// Version string. + /// CompareResult string. + public string CompareToVersion(string version) + { + return this.packageVersionInfo.CompareToVersion(version).ToString(); + } + } +} diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs index 2bc125b24c..679a385b5b 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/UninstallResult.cs @@ -7,43 +7,76 @@ namespace Microsoft.WinGet.Client.PSObjects { using System; - using Microsoft.Management.Deployment; /// /// UninstallResult wrapper object for displaying to PowerShell. /// public class UninstallResult { + private Management.Deployment.UninstallResult uninstallResult; + /// /// Initializes a new instance of the class. /// /// The uninstall result COM object. public UninstallResult(Management.Deployment.UninstallResult uninstallResult) { - this.ExtendedErrorCode = uninstallResult.ExtendedErrorCode; - this.RebootRequired = uninstallResult.RebootRequired; - this.UninstallerErrorCode = uninstallResult.UninstallerErrorCode; - this.Status = uninstallResult.Status; + this.uninstallResult = uninstallResult; + } + + /// + /// Gets the correlation data of the uninstall result. + /// + public string CorrelationData + { + get + { + return this.uninstallResult.CorrelationData; + } } /// /// Gets the extended error code exception of the failed uninstall result. /// - public Exception ExtendedErrorCode { get; private set; } + public Exception ExtendedErrorCode + { + get + { + return this.uninstallResult.ExtendedErrorCode; + } + } /// /// Gets a value indicating whether a reboot is required. /// - public bool RebootRequired { get; private set; } + public bool RebootRequired + { + get + { + return this.uninstallResult.RebootRequired; + } + } /// - /// Gets the error code of an uninstall. + /// Gets the status of the uninstall. /// - public uint UninstallerErrorCode { get; private set; } + public string Status + { + get + { + return this.uninstallResult.Status.ToString(); + } + } /// - /// Gets the status of the uninstall. + /// Gets the error code of an uninstall. /// - public UninstallResultStatus Status { get; private set; } + public uint UninstallerErrorCode + { + get + { + return this.uninstallResult.UninstallerErrorCode; + } + } } } From 9032db122d737d8c0b1584aee3c2700b85f22f16 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Thu, 2 Feb 2023 11:56:11 -0800 Subject: [PATCH 15/18] consolidate tests into single file --- .../PSObjects/InstallResult.cs | 1 - .../tests/Find-WinGetPackage.Tests.ps1 | 34 ---- .../tests/Get-WinGetPackage.Tests.ps1 | 35 ---- .../tests/Get-WinGetSource.Tests.ps1 | 17 -- ...l-Update-Uninstall-WinGetPackage.Tests.ps1 | 58 ------- .../tests/Microsoft.WinGet.Client.Tests.ps1 | 164 ++++++++++++++++++ src/PowerShell/tests/Setup.Tests.ps1 | 20 --- 7 files changed, 164 insertions(+), 165 deletions(-) delete mode 100644 src/PowerShell/tests/Find-WinGetPackage.Tests.ps1 delete mode 100644 src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 delete mode 100644 src/PowerShell/tests/Get-WinGetSource.Tests.ps1 delete mode 100644 src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.Tests.ps1 create mode 100644 src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 delete mode 100644 src/PowerShell/tests/Setup.Tests.ps1 diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs index 987ec5ea82..e68f0f53eb 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstallResult.cs @@ -78,6 +78,5 @@ public string Status return this.installResult.Status.ToString(); } } - } } diff --git a/src/PowerShell/tests/Find-WinGetPackage.Tests.ps1 b/src/PowerShell/tests/Find-WinGetPackage.Tests.ps1 deleted file mode 100644 index 38682eee8a..0000000000 --- a/src/PowerShell/tests/Find-WinGetPackage.Tests.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -<# -.Synopsis - Tests for the Find-WinGetPackage cmdlet in the Microsoft.WinGet.Client PowerShell module. -#> - -Describe 'Find-WinGetPackage' { - It 'Given no parameters, lists all available packages' { - $allPackages = Find-WinGetPackage -Source TestSource - $allPackages.Count | Should -BeGreaterThan 0 - } - - It 'Find by Id' { - $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestExeInstaller' - $package.Name | Should -Be 'TestExeInstaller' - $package.Id | Should -Be 'AppInstallerTest.TestExeInstaller' - $package.Version | Should -Be '2.0.0.0' - $package.Source | Should -Be 'TestSource' - } - - It 'Find by Name' { - $package = Find-WinGetPackage -Source 'TestSource' -Name 'TestPortableExe' - $package[0].Name | Should -Be 'TestPortableExe' - $package[1].Name | Should -Be 'TestPortableExeWithCommand' - } - - It 'Find by Name sort by Version' { - $package = Find-WinGetPackage -Source 'TestSource' -Name 'TestPortableExe' | Sort-Object 'Version' - $package[0].Name | Should -Be 'TestPortableExeWithCommand' - $package[1].Name | Should -Be 'TestPortableExe' - } -} \ No newline at end of file diff --git a/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 b/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 deleted file mode 100644 index 1c57ef8394..0000000000 --- a/src/PowerShell/tests/Get-WinGetPackage.Tests.ps1 +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -<# -.Synopsis - Tests for the Get-WinGetPackage cmdlet in the Microsoft.WinGet.Client PowerShell module. -#> - -Describe 'Get-WinGetPackage' { - - It 'Install by Id' { - $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' - $result.InstallerErrorCode | Should -Be 0 - $result.Status | Should -Be 'Ok' - $result.RebootRequired | Should -Be 'False' - } - - It 'Get package by Id' { - $result = Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller - $result.Name | Should -Be 'TestExeInstaller' - $result.Id | Should -Be 'AppInstallerTest.TestExeInstaller' - $result.Version | Should -Be '1.0.0.0' - $result.AvailableVersions[0] | Should -Be '2.0.0.0' - $result.Source | Should -Be 'TestSource' - } - - It 'Get package by Name' { - $result = Get-WinGetPackage -Name TestExeInstaller - $result.Name | Should -Be 'TestExeInstaller' - $result.Id | Should -Be 'AppInstallerTest.TestExeInstaller' - $result.Version | Should -Be '1.0.0.0' - $result.AvailableVersions[0] | Should -Be '2.0.0.0' - $result.Source | Should -Be 'TestSource' - } -} \ No newline at end of file diff --git a/src/PowerShell/tests/Get-WinGetSource.Tests.ps1 b/src/PowerShell/tests/Get-WinGetSource.Tests.ps1 deleted file mode 100644 index 45d16a633a..0000000000 --- a/src/PowerShell/tests/Get-WinGetSource.Tests.ps1 +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -<# -.Synopsis - Tests for the Get-WinGetSource cmdlet in the Microsoft.WinGet.Client PowerShell module. -#> - -Describe 'Get-WinGetSource' { - - It 'Get Test Source' { - $source = Get-WinGetSource -Name TestSource - $source.Name | Should -Be 'TestSource' - $source.Argument | Should -Be 'https://localhost:5001/TestKit/' - $source.Type | Should -Be 'Microsoft.PreIndexed.Package' - } -} \ No newline at end of file diff --git a/src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.Tests.ps1 b/src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.Tests.ps1 deleted file mode 100644 index d727fff34d..0000000000 --- a/src/PowerShell/tests/Install-Update-Uninstall-WinGetPackage.Tests.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -<# -.Synopsis - Tests for the Install-WinGetPackage cmdlet in the Microsoft.WinGet.Client PowerShell module. -#> - -Describe 'Install-WinGetPackage' { - - It 'Install by Id' { - $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' - $result.InstallerErrorCode | Should -Be 0 - $result.Status | Should -Be 'Ok' - $result.RebootRequired | Should -Be 'False' - } - - It 'Install by exact Name and Version' { - $result = Install-WinGetPackage -Name TestPortableExe -Version '2.0.0.0' -Exact - $result.InstallerErrorCode | Should -Be 0 - $result.Status | Should -Be 'Ok' - $result.RebootRequired | Should -Be 'False' - } -} - -Describe 'Update-WinGetPackage' { - - It 'Update by Id' { - $result = Update-WinGetPackage -Id AppInstallerTest.TestExeInstaller - $result.InstallerErrorCode | Should -Be 0 - $result.Status | Should -Be 'Ok' - $result.RebootRequired | Should -Be 'False' - } - - It 'Update by Name and Version' { - $result = Update-WinGetPackage -Name TestPortableExe - $result.InstallerErrorCode | Should -Be 0 - $result.Status | Should -Be 'Ok' - $result.RebootRequired | Should -Be 'False' - } -} - -Describe 'Uninstall-WinGetPackage' { - - It 'Uninstall by Id' { - $result = Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller - $result.UninstallerErrorCode | Should -Be 0 - $result.Status | Should -Be 'Ok' - $result.RebootRequired | Should -Be 'False' - } - - It 'Uninstall by Name' { - $result = Uninstall-WinGetPackage -Name TestPortableExe - $result.UninstallerErrorCode | Should -Be 0 - $result.Status | Should -Be 'Ok' - $result.RebootRequired | Should -Be 'False' - } -} \ No newline at end of file diff --git a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 new file mode 100644 index 0000000000..6bd9a5491f --- /dev/null +++ b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 @@ -0,0 +1,164 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +<# +.Synopsis + Pester tests related to the Microsoft.WinGet.Client PowerShell module. The tests require the + localhostwebserver to be running. 'Invoke-Pester' should be called in an admin powershell window with the + PowerShell module already imported. 'Import-Module ' +#> + +BeforeAll { + wingetdev source add 'TestSource' 'https://localhost:5001/TestKit/' +} + +Describe 'Get-WinGetSource' { + + It 'Get Test Source' { + $source = Get-WinGetSource -Name TestSource + $source.Name | Should -Be 'TestSource' + $source.Argument | Should -Be 'https://localhost:5001/TestKit/' + $source.Type | Should -Be 'Microsoft.PreIndexed.Package' + } +} + +Describe 'Find-WinGetPackage' { + It 'Given no parameters, lists all available packages' { + $allPackages = Find-WinGetPackage -Source TestSource + $allPackages.Count | Should -BeGreaterThan 0 + } + + It 'Find by Id' { + $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestExeInstaller' + $package.Name | Should -Be 'TestExeInstaller' + $package.Id | Should -Be 'AppInstallerTest.TestExeInstaller' + $package.Version | Should -Be '2.0.0.0' + $package.Source | Should -Be 'TestSource' + } + + It 'Find by Name' { + $package = Find-WinGetPackage -Source 'TestSource' -Name 'TestPortableExe' + $package[0].Name | Should -Be 'TestPortableExe' + $package[1].Name | Should -Be 'TestPortableExeWithCommand' + } + + It 'Find by Name sort by Version' { + $package = Find-WinGetPackage -Source 'TestSource' -Name 'TestPortableExe' | Sort-Object 'Version' + $package[0].Name | Should -Be 'TestPortableExeWithCommand' + $package[1].Name | Should -Be 'TestPortableExe' + } + + It 'Find package and verify PackageVersionInfo' { + $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestPortableExe' -Exact + $package.AvailableVersions[0] | Should -Be '3.0.0.0' + $package.AvailableVersions[1] | Should -Be '2.0.0.0' + $package.AvailableVersions.Count | Should -Be 4 + $packageVersionInfo = $package.GetPackageVersionInfo("3.0.0.0") + $packageVersionInfo.DisplayName | Should -Be 'TestPortableExe' + $packageVersionInfo.Id | Should -Be 'AppInstallerTest.TestPortableExe' + $packageVersionInfo.CompareToVersion("2.0.0.0") | Should -Be 'Greater' + $packageVersionInfo.CompareToVersion("4.0.0.0") | Should -Be 'Lesser' + } +} + +Describe 'Install|Update|Uninstall-WinGetPackage' { + + It 'Install by Id' { + $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Install by exact Name and Version' { + $result = Install-WinGetPackage -Name TestPortableExe -Version '2.0.0.0' -Exact + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Update by Id' { + $result = Update-WinGetPackage -Id AppInstallerTest.TestExeInstaller + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Update by Name and Version' { + $result = Update-WinGetPackage -Name TestPortableExe + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Uninstall by Id' { + $result = Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller + $result.UninstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Uninstall by Name' { + $result = Uninstall-WinGetPackage -Name TestPortableExe + $result.UninstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + AfterAll { + # Uninstall all test packages after each for proper cleanup. + $testExe = Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller + if ($testExe.Count -gt 0) + { + Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller + } + + $testPortable = Get-WinGetPackage -Id AppInstallerTest.TestPortableExe + if ($testPortable.Count -gt 0) + { + Uninstall-WinGetPackage -Id AppInstallerTest.TestPortableExe + } + } +} + +Describe 'Get-WinGetPackage' { + + It 'Install by Id' { + $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' + $result.InstallerErrorCode | Should -Be 0 + $result.Status | Should -Be 'Ok' + $result.RebootRequired | Should -Be 'False' + } + + It 'Get package by Id' { + $result = Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller + $result.Name | Should -Be 'TestExeInstaller' + $result.Id | Should -Be 'AppInstallerTest.TestExeInstaller' + $result.Version | Should -Be '1.0.0.0' + $result.AvailableVersions[0] | Should -Be '2.0.0.0' + $result.Source | Should -Be 'TestSource' + } + + It 'Get package by Name' { + $result = Get-WinGetPackage -Name TestExeInstaller + $result.Name | Should -Be 'TestExeInstaller' + $result.Id | Should -Be 'AppInstallerTest.TestExeInstaller' + $result.Version | Should -Be '1.0.0.0' + $result.AvailableVersions[0] | Should -Be '2.0.0.0' + $result.Source | Should -Be 'TestSource' + } + + AfterAll { + # Uninstall all test packages after each for proper cleanup. + $testExe = Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller + if ($testExe.Count -gt 0) + { + Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller + } + } +} + +AfterAll { + # Removal of source requires administrator. + wingetdev source remove 'TestSource' +} \ No newline at end of file diff --git a/src/PowerShell/tests/Setup.Tests.ps1 b/src/PowerShell/tests/Setup.Tests.ps1 deleted file mode 100644 index a4920fdde2..0000000000 --- a/src/PowerShell/tests/Setup.Tests.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -<# -.Synopsis - Setup file for all Pester tests related to the Microsoft.WinGet.Client PowerShell module. -#> - -BeforeAll { - wingetdev source add 'TestSource' 'https://localhost:5001/TestKit/' -} - -AfterAll { - # Uninstall all test packages for proper cleanup. - Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller - Uninstall-WinGetPackage -Id AppInstallerTest.TestPortableExe - - # Removal of source requires administrator. - wingetdev source remove 'TestSource' -} \ No newline at end of file From 851cd80b6424a81de964f18bd5179cb5293f23d0 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Thu, 2 Feb 2023 22:28:01 -0800 Subject: [PATCH 16/18] cleanup spelling --- .../tests/Microsoft.WinGet.Client.Tests.ps1 | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 index 6bd9a5491f..2d4b229015 100644 --- a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 +++ b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 @@ -3,19 +3,20 @@ <# .Synopsis - Pester tests related to the Microsoft.WinGet.Client PowerShell module. The tests require the - localhostwebserver to be running. 'Invoke-Pester' should be called in an admin powershell window with the - PowerShell module already imported. 'Import-Module ' + Pester tests related to the Microsoft.WinGet.Client PowerShell module. + The tests require the localhost web server to be running and serving the test data. + 'Invoke-Pester' should be called in an admin powershell window with the 'Microsoft.WinGet.Client' PowerShell module already imported. #> BeforeAll { + # Source Add requires admin privileges, this will only execute successfully in an elevated PowerShell. wingetdev source add 'TestSource' 'https://localhost:5001/TestKit/' } Describe 'Get-WinGetSource' { It 'Get Test Source' { - $source = Get-WinGetSource -Name TestSource + $source = Get-WinGetSource -Name 'TestSource' $source.Name | Should -Be 'TestSource' $source.Argument | Should -Be 'https://localhost:5001/TestKit/' $source.Type | Should -Be 'Microsoft.PreIndexed.Package' @@ -29,7 +30,9 @@ Describe 'Find-WinGetPackage' { } It 'Find by Id' { - $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestExeInstaller' + $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestExeInstallerasdfasdfasdf' + + $package | Should -Not -BeNullOrEmpty -ErrorAction Stop $package.Name | Should -Be 'TestExeInstaller' $package.Id | Should -Be 'AppInstallerTest.TestExeInstaller' $package.Version | Should -Be '2.0.0.0' @@ -38,21 +41,28 @@ Describe 'Find-WinGetPackage' { It 'Find by Name' { $package = Find-WinGetPackage -Source 'TestSource' -Name 'TestPortableExe' + + $package | Should -Not -BeNullOrEmpty -ErrorAction Stop $package[0].Name | Should -Be 'TestPortableExe' $package[1].Name | Should -Be 'TestPortableExeWithCommand' } It 'Find by Name sort by Version' { $package = Find-WinGetPackage -Source 'TestSource' -Name 'TestPortableExe' | Sort-Object 'Version' + + $package | Should -Not -BeNullOrEmpty -ErrorAction Stop $package[0].Name | Should -Be 'TestPortableExeWithCommand' $package[1].Name | Should -Be 'TestPortableExe' } It 'Find package and verify PackageVersionInfo' { $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestPortableExe' -Exact + + $package | Should -Not -BeNullOrEmpty -ErrorAction Stop $package.AvailableVersions[0] | Should -Be '3.0.0.0' $package.AvailableVersions[1] | Should -Be '2.0.0.0' $package.AvailableVersions.Count | Should -Be 4 + $packageVersionInfo = $package.GetPackageVersionInfo("3.0.0.0") $packageVersionInfo.DisplayName | Should -Be 'TestPortableExe' $packageVersionInfo.Id | Should -Be 'AppInstallerTest.TestPortableExe' @@ -64,7 +74,8 @@ Describe 'Find-WinGetPackage' { Describe 'Install|Update|Uninstall-WinGetPackage' { It 'Install by Id' { - $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' + $result = Install-WinGetPackage -Id AppInstallasdfasdfasdfstaller -Version '1.0.0.0' + $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -72,6 +83,7 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { It 'Install by exact Name and Version' { $result = Install-WinGetPackage -Name TestPortableExe -Version '2.0.0.0' -Exact + $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -79,6 +91,7 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { It 'Update by Id' { $result = Update-WinGetPackage -Id AppInstallerTest.TestExeInstaller + $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -86,6 +99,7 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { It 'Update by Name and Version' { $result = Update-WinGetPackage -Name TestPortableExe + $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -93,6 +107,7 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { It 'Uninstall by Id' { $result = Uninstall-WinGetPackage -Id AppInstallerTest.TestExeInstaller + $result.UninstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -100,6 +115,7 @@ Describe 'Install|Update|Uninstall-WinGetPackage' { It 'Uninstall by Name' { $result = Uninstall-WinGetPackage -Name TestPortableExe + $result.UninstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -125,6 +141,7 @@ Describe 'Get-WinGetPackage' { It 'Install by Id' { $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' + $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' $result.RebootRequired | Should -Be 'False' @@ -132,20 +149,24 @@ Describe 'Get-WinGetPackage' { It 'Get package by Id' { $result = Get-WinGetPackage -Id AppInstallerTest.TestExeInstaller + + $result | Should -Not -BeNullOrEmpty -ErrorAction Stop $result.Name | Should -Be 'TestExeInstaller' $result.Id | Should -Be 'AppInstallerTest.TestExeInstaller' $result.Version | Should -Be '1.0.0.0' - $result.AvailableVersions[0] | Should -Be '2.0.0.0' $result.Source | Should -Be 'TestSource' + $result.AvailableVersions[0] | Should -Be '2.0.0.0' } It 'Get package by Name' { $result = Get-WinGetPackage -Name TestExeInstaller + + $result | Should -Not -BeNullOrEmpty -ErrorAction Stop $result.Name | Should -Be 'TestExeInstaller' $result.Id | Should -Be 'AppInstallerTest.TestExeInstaller' $result.Version | Should -Be '1.0.0.0' - $result.AvailableVersions[0] | Should -Be '2.0.0.0' $result.Source | Should -Be 'TestSource' + $result.AvailableVersions[0] | Should -Be '2.0.0.0' } AfterAll { @@ -159,6 +180,6 @@ Describe 'Get-WinGetPackage' { } AfterAll { - # Removal of source requires administrator. + # Source Remove requires admin privileges, this will only execute successfully in an elevated PowerShell. wingetdev source remove 'TestSource' } \ No newline at end of file From 3ddea4d0cf5e2e63dc00066472f882f5af24c0d4 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Thu, 2 Feb 2023 22:31:30 -0800 Subject: [PATCH 17/18] fix typos --- src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 index 2d4b229015..00faba7012 100644 --- a/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 +++ b/src/PowerShell/tests/Microsoft.WinGet.Client.Tests.ps1 @@ -30,7 +30,7 @@ Describe 'Find-WinGetPackage' { } It 'Find by Id' { - $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestExeInstallerasdfasdfasdf' + $package = Find-WinGetPackage -Source 'TestSource' -Id 'AppInstallerTest.TestExeInstaller' $package | Should -Not -BeNullOrEmpty -ErrorAction Stop $package.Name | Should -Be 'TestExeInstaller' @@ -74,7 +74,7 @@ Describe 'Find-WinGetPackage' { Describe 'Install|Update|Uninstall-WinGetPackage' { It 'Install by Id' { - $result = Install-WinGetPackage -Id AppInstallasdfasdfasdfstaller -Version '1.0.0.0' + $result = Install-WinGetPackage -Id AppInstallerTest.TestExeInstaller -Version '1.0.0.0' $result.InstallerErrorCode | Should -Be 0 $result.Status | Should -Be 'Ok' From 8d16d00b79c2640550bc577b1949efdc441d1191 Mon Sep 17 00:00:00 2001 From: Ryan Fu Date: Mon, 6 Feb 2023 15:18:14 -0800 Subject: [PATCH 18/18] make catalog package abstract --- .../Module/Format.ps1xml | 5 --- .../PSObjects/CatalogPackage.cs | 35 ++++++++++--------- .../PSObjects/FoundCatalogPackage.cs | 7 +++- .../PSObjects/InstalledCatalogPackage.cs | 7 +++- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml index b07288d898..bb349cd965 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml +++ b/src/PowerShell/Microsoft.WinGet.Client/Module/Format.ps1xml @@ -9,11 +9,9 @@ - 32 - 32 @@ -51,11 +49,9 @@ - 32 - 32 @@ -191,7 +187,6 @@ - 32 diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs index 0e1b464b63..2a821196c1 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/CatalogPackage.cs @@ -13,17 +13,15 @@ namespace Microsoft.WinGet.Client.PSObjects /// /// CatalogPackage wrapper object for displaying to PowerShell. /// - public class CatalogPackage + public abstract class CatalogPackage { - private Management.Deployment.CatalogPackage catalogPackage; - /// /// Initializes a new instance of the class. /// /// CatalogPackage COM object. public CatalogPackage(Management.Deployment.CatalogPackage catalogPackage) { - this.catalogPackage = catalogPackage; + this.CatalogPackageCOM = catalogPackage; } /// @@ -33,7 +31,7 @@ public string Name { get { - return this.catalogPackage.Name; + return this.CatalogPackageCOM.Name; } } @@ -44,15 +42,10 @@ public string Id { get { - return this.catalogPackage.Id; + return this.CatalogPackageCOM.Id; } } - /// - /// Gets or sets the version of the catalog package. - /// - public string Version { get; protected set; } - /// /// Gets a value indicating whether an update is available. /// @@ -60,7 +53,7 @@ public bool IsUpdateAvailable { get { - return this.catalogPackage.IsUpdateAvailable; + return this.CatalogPackageCOM.IsUpdateAvailable; } } @@ -71,7 +64,7 @@ public string Source { get { - return this.catalogPackage.DefaultInstallVersion.PackageCatalog.Info.Name; + return this.CatalogPackageCOM.DefaultInstallVersion.PackageCatalog.Info.Name; } } @@ -86,6 +79,16 @@ public string[] AvailableVersions } } + /// + /// Gets the version of the catalog package. + /// + public abstract string Version { get; } + + /// + /// Gets the catalog package COM object. + /// + protected Management.Deployment.CatalogPackage CatalogPackageCOM { get; } + /// /// Gets a list of available package version ids for the package. /// @@ -93,7 +96,7 @@ private PackageVersionId[] AvailablePackageVersionIds { get { - return this.catalogPackage.AvailableVersions.ToArray(); + return this.CatalogPackageCOM.AvailableVersions.ToArray(); } } @@ -103,7 +106,7 @@ private PackageVersionId[] AvailablePackageVersionIds /// CheckInstalledStatus string. public string CheckInstalledStatus() { - return this.catalogPackage.CheckInstalledStatus().Status.ToString(); + return this.CatalogPackageCOM.CheckInstalledStatus().Status.ToString(); } /// @@ -118,7 +121,7 @@ public PackageVersionInfo GetPackageVersionInfo(string version) PackageVersionId packageVersionId = this.AvailablePackageVersionIds.FirstOrDefault(x => x.Version == version); if (packageVersionId != null) { - return new PackageVersionInfo(this.catalogPackage.GetPackageVersionInfo(packageVersionId)); + return new PackageVersionInfo(this.CatalogPackageCOM.GetPackageVersionInfo(packageVersionId)); } else { diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs index 35c017e87f..59378883f8 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/FoundCatalogPackage.cs @@ -18,7 +18,12 @@ public class FoundCatalogPackage : CatalogPackage public FoundCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) : base(catalogPackage) { - this.Version = catalogPackage.DefaultInstallVersion.Version; + } + + /// + public override string Version + { + get { return this.CatalogPackageCOM.DefaultInstallVersion.Version; } } } } diff --git a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs index 0454620c8e..8815ee6488 100644 --- a/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs +++ b/src/PowerShell/Microsoft.WinGet.Client/PSObjects/InstalledCatalogPackage.cs @@ -18,7 +18,12 @@ public class InstalledCatalogPackage : CatalogPackage public InstalledCatalogPackage(Management.Deployment.CatalogPackage catalogPackage) : base(catalogPackage) { - this.Version = catalogPackage.InstalledVersion.Version; + } + + /// + public override string Version + { + get { return this.CatalogPackageCOM.InstalledVersion.Version; } } } }