diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index 75f6d54f2..cabfbeae1 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -27,7 +27,7 @@ namespace Microsoft.PowerShell.PowerShellGet.Cmdlets /// /// Install helper class /// - internal class InstallHelper : PSCmdlet + internal class InstallHelper { #region Members @@ -507,7 +507,7 @@ private List InstallPackage( _cmdletPassedIn, out ErrorRecord errorRecord)) { - ThrowTerminatingError(errorRecord); + _cmdletPassedIn.ThrowTerminatingError(errorRecord); } if (isModule) @@ -529,7 +529,7 @@ private List InstallPackage( manifestInfo: out Hashtable parsedMetadataHashtable, error: out Exception manifestReadError)) { - WriteError( + _cmdletPassedIn.WriteError( new ErrorRecord( exception: manifestReadError, errorId: "ManifestFileReadParseError", diff --git a/test/InstallPSResource.Tests.ps1 b/test/InstallPSResource.Tests.ps1 index bef8111ae..b9ab10495 100644 --- a/test/InstallPSResource.Tests.ps1 +++ b/test/InstallPSResource.Tests.ps1 @@ -461,14 +461,13 @@ Describe 'Test Install-PSResource for Module' { # Install module that is not authenticode signed # Should FAIL to install the module It "Install module that is not authenticode signed" -Skip:(!(Get-IsWindows)) { - Install-PSResource -Name $testModuleName -Version "5.0.0" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -ErrorAction SilentlyContinue - $Error[0].FullyQualifiedErrorId | Should -be "InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" + { Install-PSResource -Name $testModuleName -Version "5.0.0" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository } | Should -Throw -ErrorId "GetAuthenticodeSignatureError,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" } + # Install 1.4.4.1 (with incorrect catalog file) # Should FAIL to install the module It "Install module with incorrect catalog file" -Skip:(!(Get-IsWindows)) { - Install-PSResource -Name $PackageManagement -Version "1.4.4.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -ErrorAction SilentlyContinue - $Error[0].FullyQualifiedErrorId | Should -be "InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" + { Install-PSResource -Name $PackageManagement -Version "1.4.4.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository } | Should -Throw -ErrorId "TestFileCatalogError,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" } # Install script that is signed @@ -484,8 +483,7 @@ Describe 'Test Install-PSResource for Module' { # Install script that is not signed # Should throw It "Install script that is not signed" -Skip:(!(Get-IsWindows)) { - Install-PSResource -Name "TestTestScript" -Version "1.3.1.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -ErrorAction SilentlyContinue - $Error[0].FullyQualifiedErrorId | Should -be "InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" + { Install-PSResource -Name "TestTestScript" -Version "1.3.1.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository } | Should -Throw -ErrorId "GetAuthenticodeSignatureError,Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallPSResource" } } diff --git a/test/SavePSResource.Tests.ps1 b/test/SavePSResource.Tests.ps1 index 2d5e2e27f..3366cdec5 100644 --- a/test/SavePSResource.Tests.ps1 +++ b/test/SavePSResource.Tests.ps1 @@ -257,15 +257,13 @@ Describe 'Test Save-PSResource for PSResources' { # Save module that is not authenticode signed # Should FAIL to save the module It "Save module that is not authenticode signed" -Skip:(!(Get-IsWindows)) { - Save-PSResource -Name $testModuleName -Version "5.0.0" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -Path $SaveDir -ErrorAction SilentlyContinue - $Error[0].FullyQualifiedErrorId | Should -be "InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" + { Save-PSResource -Name $testModuleName -Version "5.0.0" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -Path $SaveDir } | Should -Throw -ErrorId "GetAuthenticodeSignatureError,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" } # Save 1.4.4.1 (with incorrect catalog file) # Should FAIL to save the module It "Save module with incorrect catalog file" -Skip:(!(Get-IsWindows)) { - Save-PSResource -Name $PackageManagement -Version "1.4.4.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -Path $SaveDir -ErrorAction SilentlyContinue - $Error[0].FullyQualifiedErrorId | Should -be "InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" + { Save-PSResource -Name $PackageManagement -Version "1.4.4.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -Path $SaveDir } | Should -Throw -ErrorId "TestFileCatalogError,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" } # Save script that is signed @@ -282,8 +280,7 @@ Describe 'Test Save-PSResource for PSResources' { # Save script that is not signed # Should throw It "Save script that is not signed" -Skip:(!(Get-IsWindows)) { - Save-PSResource -Name "TestTestScript" -Version "1.3.1.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -ErrorAction SilentlyContinue - $Error[0].FullyQualifiedErrorId | Should -be "InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" + { Save-PSResource -Name "TestTestScript" -Version "1.3.1.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository } | Should -Throw -ErrorId "GetAuthenticodeSignatureError,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource" } <# diff --git a/test/UpdatePSResource.Tests.ps1 b/test/UpdatePSResource.Tests.ps1 index 901a5a0bc..b0c45c17d 100644 --- a/test/UpdatePSResource.Tests.ps1 +++ b/test/UpdatePSResource.Tests.ps1 @@ -352,8 +352,7 @@ Describe 'Test Update-PSResource' { # Should FAIL to update the module It "Update module with incorrect catalog file" -Skip:(!(Get-IsWindows)) { Install-PSResource -Name $PackageManagement -Version "1.4.2" -Repository $PSGalleryName -TrustRepository - Update-PSResource -Name $PackageManagement -Version "1.4.4.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -ErrorAction SilentlyContinue - $Error[0].FullyQualifiedErrorId | Should -be "InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.UpdatePSResource" + { Update-PSResource -Name $PackageManagement -Version "1.4.4.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository } | Should -Throw -ErrorId "TestFileCatalogError,Microsoft.PowerShell.PowerShellGet.Cmdlets.UpdatePSResource" } # Update script that is signed @@ -371,7 +370,6 @@ Describe 'Test Update-PSResource' { # Should throw It "Update script that is not signed" -Skip:(!(Get-IsWindows)) { Install-PSResource -Name "TestTestScript" -Version "1.0" -Repository $PSGalleryName -TrustRepository - Update-PSResource -Name "TestTestScript" -Version "1.3.1.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository -ErrorAction SilentlyContinue - $Error[0].FullyQualifiedErrorId | Should -be "InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.UpdatePSResource" + { Update-PSResource -Name "TestTestScript" -Version "1.3.1.1" -AuthenticodeCheck -Repository $PSGalleryName -TrustRepository } | Should -Throw -ErrorId "GetAuthenticodeSignatureError,Microsoft.PowerShell.PowerShellGet.Cmdlets.UpdatePSResource" } }