From 55b8cd1da6e22e9980906bab5d1d14a01753eb1f Mon Sep 17 00:00:00 2001 From: PowerShell Team Date: Thu, 7 Jul 2016 13:39:15 -0700 Subject: [PATCH] Import source-depot tests for PackageManagement --- .../Find-PackageProvider.Tests.ps1 | 287 +++ .../PackageManagement/Get-Package.Tests.ps1 | 93 + .../Get-PackageProvider.Tests.ps1 | 121 ++ .../Import-PackageProvider.Tests.ps1 | 415 ++++ .../Install-PackageProvider.Tests.ps1 | 812 ++++++++ .../Modules/PackageManagement/Nuget.Tests.ps1 | 1677 +++++++++++++++++ 6 files changed, 3405 insertions(+) create mode 100644 test/powershell/Modules/PackageManagement/Find-PackageProvider.Tests.ps1 create mode 100644 test/powershell/Modules/PackageManagement/Get-Package.Tests.ps1 create mode 100644 test/powershell/Modules/PackageManagement/Get-PackageProvider.Tests.ps1 create mode 100644 test/powershell/Modules/PackageManagement/Import-PackageProvider.Tests.ps1 create mode 100644 test/powershell/Modules/PackageManagement/Install-PackageProvider.Tests.ps1 create mode 100644 test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 diff --git a/test/powershell/Modules/PackageManagement/Find-PackageProvider.Tests.ps1 b/test/powershell/Modules/PackageManagement/Find-PackageProvider.Tests.ps1 new file mode 100644 index 000000000..80c788a4e --- /dev/null +++ b/test/powershell/Modules/PackageManagement/Find-PackageProvider.Tests.ps1 @@ -0,0 +1,287 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------ PackageManagement Test ----------------------------------- +ipmo "$PSScriptRoot\utility.psm1" +$InternalGallery = "https://dtlgalleryint.cloudapp.net/api/v2/" + +# ------------------------------------------------------------------------------ +# Actual Tests: + +Describe "find-packageprovider" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + BeforeAll{ + #make sure we are using the latest Nuget provider + install-PackageProvider -name nuget -force + } + AfterAll{ + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + + #make sure the package repository exists + $a=Get-PackageSource -force| select Location, ProviderName + + $found = $false + foreach ($item in $a) + { + #name contains "." foo.bar for example for the registered sources internally + if(($item.ProviderName -eq "PowerShellGet") -and ($item.Location -eq $InternalGallery)) + { + $found = $true + break + } + } + + if(-not $found) + { + Register-PackageSource -Name 'OneGetTestSource' -Location $InternalGallery -ProviderName 'PowerShellGet' -ForceBootstrap -ErrorAction SilentlyContinue + } + + It "find-packageprovider without any parameters, Expect succeed" { + $a = (Find-PackageProvider -force).name + $a -contains "TSDProvider" | should be $true + $a -contains "nuget" | should be $true + } + + It "find-packageprovider -name, Expect succeed" { + $a = (Find-PackageProvider -name nuget).name + $a -contains "GistProvider" | should be $false + $a -contains "nuget" | should be $true + } + + It "find-packageprovider -name with wildcards, Expect succeed" { + $a = (Find-PackageProvider -name gist*).name + $a -contains "GistProvider" | should be $true + $a -contains "nuget" | should be $false + } + + It "find-packageprovider -name with wildcards, Expect succeed" { + $a = (Find-PackageProvider -name nu*).name + $a -contains "GistProvider" | should be $false + $a -contains "nuget" | should be $true + } + + It "find-packageprovider -name array, Expect succeed" { + $names=@("gistprovider", "TSD*") + + $a = (Find-PackageProvider -name $names).name + $a -contains "GistProvider" | should be $true + $a -contains "TSDProvider" | should be $true + } + + It "find-packageprovider -allversions, Expect succeed" { + $a = (Find-PackageProvider -allversions) + + $a.Name -contains "TSDProvider" | should be $true + $a.Name -contains "nuget" | should be $true + $a.Count -gt 1 | should be $true + } + + It "find-packageprovider -name -allversions, Expect succeed" { + $a = (Find-PackageProvider -name TSDProvider -AllVersions).name + $a -contains "TSDProvider" | should be $true + + $b = (Find-PackageProvider -name TSDP* -AllVersions).name + $b.Count -ge $a.Count | should be $true + } + + + It "EXPECTED: success 'find-packageprovider nuget -allVersions'" { + $a = find-packageprovider -name nuget -allVersions + $a.Count -ge 5| should be $true + + $b = find-packageprovider -allVersions + $b.Count -gt $a.Count| should be $true + } + + It "find-packageprovider -Source, Expect succeed" { + $a = (Find-PackageProvider -source $InternalGallery).name + $a -contains "TSDProvider" | should be $true + $a -contains "nuget" | should be $false + } + + It "find-packageprovider -Source -Name, Expect succeed" { + $a = (Find-PackageProvider -name gistprovider -source $InternalGallery).name + $a -contains "gistprovider" | should be $true + $a -contains "nuget" | should be $false + } + It "find-packageprovider -Name with dependencies, Expect succeed" { + # gistprovider 1.5 depends on tsdprovider 0.2 + $a = (Find-PackageProvider -name gistprovider -RequiredVersion 1.5 -source $InternalGallery -IncludeDependencies) + $a.Name -contains "gistprovider" | should be $true + $a.Name -contains "tsdprovider" | should be $true + } + + It "find-install-packageprovider with PowerShell provider, Expect succeed" { + $provider= find-packageprovider -name TSDProvider -MinimumVersion 0.1 -MaximumVersion 0.2 -Source $InternalGallery + $provider | ?{ $_.Version -eq "0.2" } | should not BeNullOrEmpty + + $a=install-packageprovider -name TSDProvider -MinimumVersion 0.1 -MaximumVersion 0.2 -Force -Source $InternalGallery + $a.Name | should match "TSDProvider" + $a.Version | should match "0.2" + } + + It "find-install-packageprovider nuget, Expect succeed" { + $provider= find-packageprovider -name nuget -MinimumVersion 2.8.5.1 -MaximumVersion 2.8.5.123 + + $provider | ?{ $_.Version -eq "2.8.5.122" } | should not BeNullOrEmpty + $provider.Count -eq 1 | should be $true + + $a=install-packageprovider -name nuget -MinimumVersion 2.8.5.1 -MaximumVersion 2.8.5.123 -Force + $a.Name | should match "nuget" + $a.Version | should match "2.8.5.122" + + $b= Get-PackageProvider -ListAvailable + $b | ?{ $_.Version -eq "2.8.5.122" } | should not BeNullOrEmpty + } + + } + +Describe "Find-Package With FilterOnTag" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + BeforeAll{ + #make sure we are using the latest Nuget provider + install-PackageProvider -name nuget -force + } + AfterAll{ + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + + it "EXPECTED: Find a package with FilterOnTag" { + + $a=find-package -ProviderName nuget -source $InternalGallery -Name gistprovider -FilterOnTag Provider + $a.name | should match "GistProvider" + } + + it "EXPECTED: Find a package with array of FilterOnTags" { + + $a=find-package -ProviderName nuget -source $InternalGallery -Name gistprovider -FilterOnTag @('Provider','PackageManagement') + $a.name | should match "GistProvider" + + } + + it "EXPECTED: Find a package with a bad tag" { + $Error.Clear() + find-package -ProviderName nuget -source $InternalGallery -Name gistprovider -FilterOnTag Pro -ErrorAction SilentlyContinue -ErrorVariable ev + $ev.FullyQualifiedErrorId | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } + + it "EXPECTED: Find a package with a bad tag" { + $Error.Clear() + find-package -ProviderName nuget -source $InternalGallery -Name gistprovider -FilterOnTag Providerrrrrr -ErrorAction SilentlyContinue -ErrorVariable ev + $ev.FullyQualifiedErrorId | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } +} + +Describe "Find-PackageProvider with Versions" -Tags @('BVT', 'DRT') { + # make sure that packagemanagement is loaded + import-packagemanagement + <# Nuget + 2.8.5.127 + 2.8.5.122 + 2.8.5.120 + 2.8.5.101 + 2.8.5.24#> + + It "EXPECTED: success 'Find a provider -requiredVersion 3.5'" { + (find-packageprovider -name Nuget -RequiredVersion 2.8.5.122).Version.ToString() | should match "2.8.5.122" + } + + + It "EXPECTED: success 'find a provider with MinimumVersion and MaximumVersion'" { + (find-packageprovider -name nuget -MinimumVersion 2.8.5.105 -MaximumVersion 2.8.5.123).Version.ToString() | should match "2.8.5.122" + } + + It "EXPECTED: success 'find a provider with MaximumVersion'" { + (find-packageprovider -name nuget -MaximumVersion 2.8.5.122).Version -contains "2.8.5.122" | should be $true + } +} + + + +Describe "find-packageprovider Error Cases" -Tags @('BVT', 'DRT') { + # make sure that packagemanagement is loaded + import-packagemanagement + + AfterAll { + $x =Get-PackageSource -Name OneGetTestSource -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if($x) + { + Unregister-PackageSource -Name OneGetTestSource + } + } + + It "EXPECTED: returns an error when inputing a bad version format" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name Gistprovider -RequiredVersion BOGUSVERSION -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "InvalidVersion,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } + + + It "EXPECTED: returns an error when asking for a provider that does not exist" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name NOT_EXISTS -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } + + + It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MinimumVersion" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name NOT_EXISTS -RequiredVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MaximumVersion" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name NOT_EXISTS -RequiredVersion 1.0 -MaximumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with a MinimumVersion greater than MaximumVersion" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name nuget -MaximumVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with MinimumVersion that does not exist" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name gistprovider -MinimumVersion 20.2 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with MaximumVersion that does not exist" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name gistprovider -MaximumVersion 0.1 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider that has name with wildcard and version" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name "AnyName*" -RequiredVersion 4.5 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "MultipleNamesWithVersionNotAllowed,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider that has name with wildcard and version" { + $Error.Clear() + $msg = powershell 'find-packageprovider -name "AnyName" -RequiredVersion 4.5 -allVersions -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "AllVersionsCannotBeUsedWithOtherVersionParameters,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider" + } +} + + diff --git a/test/powershell/Modules/PackageManagement/Get-Package.Tests.ps1 b/test/powershell/Modules/PackageManagement/Get-Package.Tests.ps1 new file mode 100644 index 000000000..177f0ab63 --- /dev/null +++ b/test/powershell/Modules/PackageManagement/Get-Package.Tests.ps1 @@ -0,0 +1,93 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------ PackageManagement Test ---------------------------------------------- +ipmo "$PSScriptRoot\utility.psm1" + +$nuget = "nuget" +$source = "http://www.nuget.org/api/v2/" +$destination = "$env:tmp\GetPackageTests" + +# Bootstrap the provider +Get-PackageProvider -Name $nuget -Force +# ------------------------------------------------------------------------------ + +# Actual Tests: + +Describe "Get-package" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "EXPECTED: Get-package accepts array of strings for -providername parameter" { + $x = (get-package -providername Programs,Msi) + } +} + +Describe "Get-package with version parameter - valid scenarios" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "Get-package supports -AllVersions parameter" { + $outputWithAllVersions = (Get-Package -providername Programs,Msi -AllVersions) + $outputWithoutAllVersions = (Get-Package -providername Programs,Msi) + $outputWithAllVersions.count -ge $outputWithoutAllVersions.count | should be $true + + } + + It "E2E: Get-package supports -AllVersions parameter for a specific package - with multiple versions from Nuget" { + ($foundPackages = Find-Package -Name "adept.nugetrunner" -Provider $nuget -Source $source -AllVersions) + + foreach ($package in $foundPackages) + { + ($package | Install-Package -Destination $destination -Force) + } + + $installedPackages = (Get-Package -Name "adept.nugetrunner" -Provider $nuget -Destination $destination -AllVersions) + $installedPackages.Name | should be "adept.nugetrunner" + $installedPackages.Count -eq $foundPackages.Count | should be $true + + # check that getting attributes from meta is not case sensitive + $packageToInspect = $installedPackages[0] + + $firstDescr = $packageToInspect.Meta.Attributes["Description"] + # the description should not be null + [string]::IsNullOrWhiteSpace($firstDescr) | should be $false + $secondDescr = $packageToInspect.Meta.Attributes["dEsCriPtIoN"] + + # the 2 descriptions should be the same + $firstDescr -eq $secondDescr | should be $true + + if (Test-Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } +} + +Describe "Get-package with version parameter - Error scenarios" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "Get-package -AllVersions -- Cannot be used with other version parameters" { + $Error.Clear() + $msg = powershell 'Get-Package -AllVersions -RequiredVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "AllVersionsCannotBeUsedWithOtherVersionParameters,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage" + + } + + It "Get-package -RequiredVersion -- Cannot be used with Min/Max version parameters" { + $Error.Clear() + $msg = powershell 'Get-Package -RequiredVersion 1.0 -MinimumVersion 2.0 -MaximumVersion 3.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage" + + } +} \ No newline at end of file diff --git a/test/powershell/Modules/PackageManagement/Get-PackageProvider.Tests.ps1 b/test/powershell/Modules/PackageManagement/Get-PackageProvider.Tests.ps1 new file mode 100644 index 000000000..360332446 --- /dev/null +++ b/test/powershell/Modules/PackageManagement/Get-PackageProvider.Tests.ps1 @@ -0,0 +1,121 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------ PackageManagement Test ---------------------------------------------- +ipmo "$PSScriptRoot\utility.psm1" + + +# ------------------------------------------------------------------------------ +# Actual Tests: + +Describe "get-packageprovider" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "lists package providers installed" { + $x = (get-packageprovider -name "nuget" -ForceBootstrap).name | should match "nuget" + } + + It "lists package providers installed" { + $x = (get-packageprovider -name "nuget" -verbose -Force).name | should match "nuget" + } + + It "EXPECTED: Gets The 'Programs' Package Provider" { + $x = (get-packageprovider -name "Programs").name | should match "Programs" + } + + It "EXPECTED: Gets The 'P*' Package Provider" { + $x = (get-packageprovider -name "P*").name.Contains('PowerShellGet')| should be $true + } + + It "EXPECTED: returns an error when asking for a provider that does not exist" { + $Error.Clear() + $msg = powershell 'get-packageprovider -name NOT_EXISTS -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider" + } + + It "EXPECTED: returns an error when asking for multiple providers that do not exist" { + $Error.Clear() + $msg = powershell 'get-packageprovider -name NOT_EXISTS,NOT_EXISTS2 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider" + } + + It "EXPECTED: returns an error when asking for multiple providers that do not exist -list" { + $Error.Clear() + $msg = powershell 'get-packageprovider -name NOT_EXISTS,NOT_EXISTS2 -ListAvailable -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider" + } + + It "EXPECTED: returns swidtag conformed object for powershell-based provider" { + $onegettest = (Get-PackageProvider OneGetTest -ListAvailable | Where-Object {$_.Version.ToString() -eq "9.9.0.0"} | Select -First 1) + + $onegettest.Links.Count | should be 3 + + $found = $false + + foreach ($link in $onegettest.Links) + { + if ($link.HRef.ToString() -match "http://oneget.org/icon" -and $link.Relationship -match "icon") + { + $found = $true + } + } + + $found | should be $true + } +} + + + +Describe "happy" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "looks for packages in bootstrap" { + (find-package -provider bootstrap).Length | write-host + } + + It "does something else" { + $false | should be $false + } +} + + +Describe "Get-PackageProvider with list" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "lists package providers installed" { + $x = (Get-PackageProvider).Count -gt 1 | should be $true + $y = (Get-PackageProvider -ListAvailable).Count -gt $x | should be $true + } + + It "List two providers" { + (get-packageprovider -name "OneGetTest" -ListAvailable).name | should match "OneGetTest" + (get-packageprovider -name "PowerShellGet" -ListAvailable).name | should match "PowerShellGet" + + $providers = get-packageprovider -Name OneGetTest, PowerShellGet -ListAvailable + + $providers | ?{ $_.name -eq "OneGetTest" } | should not BeNullOrEmpty + + $providers | ?{ $_.name -eq "PowerShellGet" } | should not BeNullOrEmpty + } + + It "List two providers with wildcard chars" { + $providers = get-packageprovider -Name OneGetTest* -ListAvailable + + $providers | ?{ $_.name -eq "OneGetTest" } | should not BeNullOrEmpty + #all versions of the OneGetTest provider should be displayed + $providers.Count -ge 3 | should be $true + } +} diff --git a/test/powershell/Modules/PackageManagement/Import-PackageProvider.Tests.ps1 b/test/powershell/Modules/PackageManagement/Import-PackageProvider.Tests.ps1 new file mode 100644 index 000000000..60b7f5cd2 --- /dev/null +++ b/test/powershell/Modules/PackageManagement/Import-PackageProvider.Tests.ps1 @@ -0,0 +1,415 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------ PackageManagement Test ---------------------------------------------- +ipmo "$PSScriptRoot\utility.psm1" + +$ProgramProviderInstalledPath = "$Env:ProgramFiles\PackageManagement\ProviderAssemblies" + +$LocalAppData = [Environment]::GetFolderPath("LocalApplicationData") +$UserProviderInstalledPath = "$($LocalAppData)\PackageManagement\ProviderAssemblies" + +$ProgramModulePath = "$Env:ProgramFiles\WindowsPowerShell\Modules" + +$mydocument = [Environment]::GetFolderPath("MyDocuments") +$UserModuleFolder = "$($mydocument)\WindowsPowerShell\Modules" + +$InternalGallery = "https://dtlgalleryint.cloudapp.net/api/v2/" +$InternalSource = 'OneGetTestSource' + +#make sure the package repository exists +$a=Get-PackageSource -ForceBootstrap| select Name, Location, ProviderName + +$found = $false +foreach ($item in $a) +{ + #name contains "." foo.bar for example for the registered sources internally + if($item.ProviderName -eq "PowerShellGet") + { + if ($item.Location -eq $InternalGallery) { + Unregister-PackageSource $item.Name -Provider "PowerShellGet" -ErrorAction SilentlyContinue + } + } +} + +Register-PackageSource -Name $InternalSource -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ForceBootstrap -ErrorAction SilentlyContinue + +# ------------------------------------------------------------------------------ +# Actual Tests: + +Describe "import-packageprovider" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "Import -force 'PowerShellGet', a builtin package provider, Expect succeed" { + #avoid popup for installing nuget-any.exe + Find-PackageProvider -force + (Import-PackageProvider 'PowerShellGet' -verbose -force).name | should match "PowerShellGet" + } + + + It "Import a PowerShell package provider Expect succeed" { + (get-packageprovider -name "OneGetTest" -list).name | should match "OneGetTest" + $x = PowerShell '(Import-PackageProvider OneGetTest -WarningAction SilentlyContinue).Name' + $x | should match "OneGetTest" + + $x = PowerShell '(Import-PackageProvider OneGetTest -WarningAction SilentlyContinue -force).Name' + $x | should match "OneGetTest" + } + + It "Import 'OneGetTestProvider' CSharp package provider with filePath from programs folder, Expect succeed" { + + $path = "$($ProgramProviderInstalledPath)\Microsoft.PackageManagement.OneGetTestProvider.dll" + $path | should Exist + + $job=Start-Job -ScriptBlock { + param($path) import-packageprovider -name $path; + } -ArgumentList @($path) + + $a= $job | Receive-Job -Wait + $a.Name | should match "OneGetTestProvider" + + } + + It "Import 'PSChained1Provider' PowerShell package provider with filePath from programfiles folder, Expect succeed" { + + $path = "$($ProgramModulePath)\PSChained1Provider.psm1" + $path | should Exist + + $job=Start-Job -ScriptBlock { + param($path) import-packageprovider -name $path; + } -ArgumentList @($path) + + $a= $job | Receive-Job -Wait + $a.Name | should match "PSChained1Provider" + } + + + It "Import a CSharp package provider with filePath from user folder -force, Expect succeed" { + $path = "$($UserProviderInstalledPath)\Microsoft.PackageManagement.OneGetTestProvider.dll" + $path | should Exist + + $job=Start-Job -ScriptBlock { + param($path) import-packageprovider -name $path; + } -ArgumentList @($path) + + $a= $job | Receive-Job -Wait + $a.Name | should match "OneGetTestProvider" + } + + It "Import a PowerShell package provider with filePath from user folder -force, Expect succeed" { + + $path = "$($UserModuleFolder)\PSChained1Provider.psm1" + $path | should Exist + + $job=Start-Job -ScriptBlock { + param($path) import-packageprovider -name $path; + } -ArgumentList @($path) + + $a= $job | Receive-Job -Wait + $a.Name | should match "PSChained1Provider" + } + + It "Import a PowerShell package provider with -force, Expect succeed" { + + $path = "$($UserModuleFolder)\PSChained1Provider.psm1" + $path | should Exist + + $newPath = "$($UserModuleFolder)\MyTest.psm1" + Copy-Item -Path $path -Destination $newPath -Force + + + $job=Start-Job -ScriptBlock { + param($newPath) import-packageprovider -name $newPath -Force; + } -ArgumentList @($newPath) + + $a= $job | Receive-Job -Wait + $a.Name | should match "PSChained1Provider" + + $job=Start-Job -ScriptBlock { + + param($newPath) + + import-packageprovider -name $newPath -Force + Set-Content -Path $newPath -Value "#test" -force + import-packageprovider -name $newPath -Force + + } -ArgumentList @($newPath) + + + Receive-Job -Wait -Job $job -ErrorVariable theError 2>&1 + $theError.FullyQualifiedErrorId | should be "FailedToImportProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "Import 'OneGetTest' PowerShell package provider that has multiple versions, Expect succeed" { + #check all version of OneGetTest is listed + $x = get-packageprovider "OneGetTest" -ListAvailable + + + $x | ?{ $_.Version.ToString() -eq "9.9.0.0" } | should not BeNullOrEmpty + $x | ?{ $_.Version.ToString() -eq "3.5.0.0" } | should not BeNullOrEmpty + $x | ?{ $_.Version.ToString() -eq "1.1.0.0" } | should not BeNullOrEmpty + + #latest one is imported + $y = powershell '(import-packageprovider -name "OneGetTest").Version.Tostring()' + $y | should match "9.9.0.0" + } +} + + + +Describe "import-packageprovider Error Cases" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "Expected error when importing wildcard chars 'OneGetTest*" { + $Error.Clear() + $msg = powershell 'import-packageprovider -name OneGetTest* -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "InvalidParameter,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "EXPECTED: returns an error when inputing a bad version format" { + $Error.Clear() + $msg = powershell 'import-packageprovider -name Gistprovider -RequiredVersion BOGUSVERSION -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "InvalidVersion,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider that does not exist" { + $Error.Clear() + $msg = powershell 'import-packageprovider -name NOT_EXISTS -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with file full path and version" { + $Error.Clear() + $msg = powershell {import-packageprovider -name "$($ProgramModulePath)\PSChained1Provider.psm1" -RequiredVersion 9.9.9 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId} + $msg | should be "FullProviderFilePathVersionNotAllowed,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + + It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MinimumVersion" { + $Error.Clear() + $msg = powershell 'import-packageprovider -name PowerShellGet -RequiredVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MaximumVersion" { + $Error.Clear() + $msg = powershell 'import-packageprovider -name PowerShellGet -RequiredVersion 1.0 -MaximumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with a MinimumVersion greater than MaximumVersion" { + $Error.Clear() + $msg = powershell 'import-packageprovider -name PowerShellGet -MaximumVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "MinimumVersionMustBeLessThanMaximumVersion,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with MinimumVersion that does not exist" { + $Error.Clear() + $msg = powershell 'Import-packageprovider -name OneGetTest -MinimumVersion 20.2 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with MaximumVersion that does not exist" { + $Error.Clear() + $msg = powershell 'Import-packageprovider -name OneGetTest -MaximumVersion 0.2 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider that has name with wildcard and version" { + $Error.Clear() + $msg = powershell 'Import-packageprovider -name "OneGetTest*" -RequiredVersion 4.5 -force -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "MultipleNamesWithVersionNotAllowed,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider" + } + +} + + +Describe "Import-PackageProvider with OneGetTest that has 3 versions: 1.1, 3.5, and 9.9." -Tags @('BVT', 'DRT') { + # make sure that packagemanagement is loaded + import-packagemanagement + + It "EXPECTED: success 'import OneGetTest -requiredVersion 3.5'" { + powershell '(Import-packageprovider -name OneGetTest -requiredVersion 3.5 -WarningAction SilentlyContinue).Version.ToString()' | should match "3.5.0.0" + + # test that if we call a function with error, powershell does not hang for the provider + $warningMsg = powershell '(Import-packageprovider -name OneGetTest -requiredVersion 3.5) | Out-Null; Get-Package -ProviderName OneGetTest 3>&1' + $result = $warningMsg[0] + + if ($PSCulture -eq "en-US") { + foreach($w in $warningMsg) + { + if($w -match 'WARNING: Cannot bind parameter') + { + $result = $w + } + + } + $result.StartsWith('WARNING: Cannot bind parameter') | should be $true + } + } + + It "EXPECTED: success 'Import OneGetTest -requiredVersion 3.5 and then 9.9 -force'" { + $a = powershell {(Import-packageprovider -name OneGetTest -RequiredVersion 3.5) > $null; (Import-packageprovider -name OneGetTest -requiredVersion 9.9 -force)} + $a.Version.ToString()| should match "9.9.0.0" + } + + It "EXPECTED: success 'import OneGetTest with MinimumVersion and MaximumVersion'" { + powershell '(Import-packageprovider -name OneGetTest -MinimumVersion 1.2 -MaximumVersion 5.0 -WarningAction SilentlyContinue).Version.ToString()' | should match "3.5.0.0" + } + + It "EXPECTED: success 'OneGetTest with MaximumVersion'" { + powershell '(Import-packageprovider -name OneGetTest -MaximumVersion 3.5 -WarningAction SilentlyContinue).Version.ToString()' | should match "3.5.0.0" + } + + It "EXPECTED: success 'OneGetTest with MinimumVersion'" { + powershell '(Import-packageprovider -name OneGetTest -MinimumVersion 2.2 -WarningAction SilentlyContinue).Version.ToString()' | should match "9.9.0.0" + } + + It "EXPECTED: success 'OneGetTest Find-Package with Progress'" { + $ps = [PowerShell]::Create() + $ps.AddScript("Import-PackageProvider -Name OneGetTest -RequiredVersion 9.9; Find-Package -ProviderName OneGetTest") + $ps.Invoke() + + $ps.Streams.Progress.Count | Should be 29 + + $culture = (Get-Culture).Name + + if ($culture -eq "en-us") { + $ps.Streams.Progress[1].Activity | Should match "Starting some progress" + $ps.Streams.Progress[1].StatusDescription | should match "Processing" + $ps.Streams.Progress[1].CurrentOperation | should match "Starting" + + $ps.Streams.Progress[5].Activity | should match "Updating" + $ps.Streams.Progress[5].StatusDescription | should match "Finding packages" + + $ps.Streams.Progress[6].Activity | should match "Updating Inner" + $ps.Streams.Progress[6].StatusDescription | should match "Finding inner packages" + + $ps.Streams.Progress[7].Activity | should match "Updating Inner" + + } + + $ps.Streams.Progress[1].ActivityId | Should Be 0 + $ps.Streams.Progress[1].ParentActivityId | should be -1 + $ps.Streams.Progress[1].SecondsRemaining | should match 10 + $ps.Streams.Progress[1].RecordType -eq [System.Management.Automation.ProgressRecordType]::Processing | should be true + $ps.Streams.Progress[1].PercentComplete | should be 22 + + $ps.Streams.Progress[2].SecondsRemaining | should be 5 + + $ps.Streams.Progress[4].PercentComplete | should be 100 + $ps.Streams.Progress[4].RecordType -eq [System.Management.Automation.ProgressRecordType]::Completed | should be true + + $ps.Streams.Progress[5].PercentComplete | should be 0 + + $ps.Streams.Progress[6].PercentComplete | should be 0 + + $ps.Streams.Progress[7].PercentComplete | should be 25 + } + + It "EXPECTED: success 'OneGetTest Find-Package returns correct TagId'" { + $ps = [PowerShell]::Create() + $ps.AddScript("Import-PackageProvider -Name OneGetTest -RequiredVersion 9.9; Find-Package -ProviderName OneGetTest") + $result = $ps.Invoke() | Select -First 1 + + $result.TagId | should match "MyVeryUniqueTagId" + } + + It "EXPECTED: success 'OneGetTest Get-Package returns correct package object using swidtag'" { + $ps = [PowerShell]::Create() + $null = $ps.AddScript("`$null = Import-PackageProvider -Name OneGetTest -RequiredVersion 9.9; Get-Package -ProviderName OneGetTest") + $result = $ps.Invoke() + + $result.Count | should Be 2 + + ($result | Select -Last 1).TagId | should match "jWhat-jWhere-jWho-jQuery" + } + + It "EXPECTED: success 'OneGetTest Get-Package returns correct progress message'" { + $ps = [PowerShell]::Create() + $null = $ps.AddScript("`$null = Import-PackageProvider -Name OneGetTest -RequiredVersion 9.9; Get-Package -ProviderName OneGetTest") + $result = $ps.Invoke() + + $ps.Streams.Progress[1].PercentComplete | should be 0 + $ps.Streams.Progress[1].Activity | should match "Updating" + $ps.Streams.Progress[1].ActivityId | should be 10 + + $ps.Streams.Progress[2].PercentComplete | should be 0 + $ps.Streams.Progress[2].Activity | should match "Updating Inner" + $ps.Streams.Progress[2].ParentActivityId | should be 10 + + $ps.Streams.Progress[3].PercentComplete | should be 25 + $ps.Streams.Progress[3].Activity | should match "Updating Inner" + $ps.Streams.Progress[3].ParentActivityId | should be 10 + + } +} + +Describe "Import-PackageProvider with OneGetTestProvider that has 2 versions: 4.5, 6.1" -Tags @('BVT', 'DRT') { + # make sure that packagemanagement is loaded + import-packagemanagement + + # install onegettestprovider + Install-PackageProvider -Name OneGetTestProvider -RequiredVersion 4.5.0.0 -Source $InternalGallery + Install-PackageProvider -Name OneGetTestProvider -RequiredVersion 6.1.0.0 -Source $InternalGallery + + It "EXPECTED: Get-PackageProvider -ListAvailable succeeds" { + $providers = Get-PackageProvider -ListAvailable + ($providers | Where-Object {$_.Name -eq 'OneGetTest'}).Count | should match 3 + ($providers | Where-Object {$_.Name -eq 'OneGetTestProvider'}).Count -ge 2 | should be $true + } + + It "EXPECTED: Get-PackageProvider -ListAvailable succeeds even after importing gist provider" { + Install-PackageProvider GistProvider -Source $InternalGallery + Import-PackageProvider Gist + $providers = Get-PackageProvider -ListAvailable + ($providers | Where-Object {$_.Name -eq 'OneGetTest'}).Count | should match 3 + ($providers | Where-Object {$_.Name -eq 'OneGetTestProvider'}).Count -ge 2 | should be $true + } + + It "EXPECTED: success 'import OneGetTestProvider -requiredVersion 4.5'" { + Import-PackageProvider -Name OneGetTestProvider -RequiredVersion 4.5 -Force + (Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '4.5.0.0' + } + + It "EXPECTED: success 'import OneGetTestProvider with MinimumVersion and MaximumVersion'" { + Import-packageprovider -name OneGetTestProvider -MinimumVersion 4.6 -MaximumVersion 6.2 -Force + (Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '6.1.0.0' + } + + It "EXPECTED: success 'import OneGetTestProvider with MaximumVersion'" { + Import-packageprovider -name OneGetTestProvider -MaximumVersion 4.6 -Force + (Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '4.5.0.0' + } + + It "EXPECTED: success 'OneGetTestProvider with MinimumVersion'" { + Import-packageprovider -name OneGetTestProvider -MinimumVersion 6.0.5 -Force + + (Get-PackageProvider OneGetTestProvider).Version -ge [version]'6.1.0.0' | should be $true + } + + It "EXPECTED: success 'Import OneGetTestProvider -requiredVersion 4.5 and then 6.1 -force'" { + Import-PackageProvider -Name OneGetTestProvider -RequiredVersion 4.5 -Force; + Import-PackageProvider -Name OneGetTestProvider -RequiredVersion 6.1 -Force; + (Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '6.1.0.0' + } + + It "EXPECTED: success 'Import OneGetTestProvider -MinimumVersion 4.5 and then MaximumVersion 5.0 -force'" { + Import-PackageProvider -Name OneGetTestProvider -MinimumVersion 4.5 -Force; + (Get-PackageProvider OneGetTestProvider).Version -ge [version]'6.1.0.0' | should be $true + Import-PackageProvider -Name OneGetTestProvider -MaximumVersion 5.0 -Force; + (Get-PackageProvider OneGetTestProvider).Version.ToString() | should match '4.5.0.0' + } +} \ No newline at end of file diff --git a/test/powershell/Modules/PackageManagement/Install-PackageProvider.Tests.ps1 b/test/powershell/Modules/PackageManagement/Install-PackageProvider.Tests.ps1 new file mode 100644 index 000000000..784db936c --- /dev/null +++ b/test/powershell/Modules/PackageManagement/Install-PackageProvider.Tests.ps1 @@ -0,0 +1,812 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------ PackageManagement Test ----------------------------------- +ipmo "$PSScriptRoot\utility.psm1" +$InternalGallery = "https://dtlgalleryint.cloudapp.net/api/v2/" +$InternalGallery2 = "http://dtlgalleryint.cloudapp.net/api/v2/" +$InternalSource = 'OneGetTestSource' +$InternalSource2 = 'OneGetTestSource2' +$ProviderFolder = "$env:ProgramFiles\PackageManagement\ProviderAssemblies" +$destination = "$env:tmp\installpp" + +#make sure the package repository exists +$a=Get-PackageSource -ForceBootstrap| select Name, Location, ProviderName + +$found = $false +foreach ($item in $a) +{ + #name contains "." foo.bar for example for the registered sources internally + if($item.ProviderName -eq "PowerShellGet") + { + if (($item.Location -eq $InternalGallery) -or ($item.Location -eq $InternalGallery2)) { + Unregister-PackageSource $item.Name -Provider "PowerShellGet" -ErrorAction SilentlyContinue + } + } +} + +Register-PackageSource -Name $InternalSource -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ForceBootstrap -ErrorAction SilentlyContinue +Register-PackageSource -Name $InternalSource2 -Location $InternalGallery2 -ProviderName 'PowerShellGet' -ForceBootstrap -ErrorAction SilentlyContinue + +# ------------------------------------------------------------------------------ +# Actual Tests: + +Describe "install-packageprovider" -Tags @('BVT', 'DRT') { + # make sure that packagemanagement is loaded + import-packagemanagement + BeforeEach { + + $m= Get-InstalledModule -Name myalbum -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if($m -and $m.InstalledLocation) + { + Remove-Item -Path $m.InstalledLocation -Recurse -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Verbose + } + } + + AfterAll { + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + + It "install-packageprovider, Expect succeed" { + #avoid popup for installing nuget-any.exe + Find-PackageProvider -force + $a = (install-PackageProvider -name gistprovider -force -source $InternalSource).name + $a -contains "gistprovider" | should be $true "gistprovider" + + # check for swidtag field + $gist = (Get-PackageProvider gist -ListAvailable | Select -First 1) + + $gist.Entities.Count | should be 2 + + $found = $false + + foreach ($entity in $gist.Entities) + { + if ($entity.Name -match "Doug Finke" -and $entity.Role -match "author") + { + $found = $true + } + } + + $found | should be $true + + $gist.VersionScheme | should match "MultiPartNumeric" + } + + + It "install-packageprovider from bootstrap web site, Expect succeed" { + $a = (Install-PackageProvider -Name nuget -RequiredVersion 2.8.5.127 -Force).name + $a | should match "nuget" + + # check for swidtag field + $nugetBootstrapped = (Get-PackageProvider -Name nuget -ListAvailable | Where-Object {$_.Version.ToString() -eq "2.8.5.127"} | Select-Object -First 1) + + $nugetBootstrapped.Links[0].HRef.ToString() | should match "https://oneget.org/nuget-anycpu-2.8.5.127.exe" + $nugetBootstrapped.Links[0].Relationship | should match "installationmedia" + } + + It "find | install-packageprovider -name array, Expect succeed" { + $names=@("gistprovider", "TSDProvider") + + # + $a = (find-PackageProvider -name $names -Source $InternalSource | Install-PackageProvider -force).name + $a -contains "GistProvider" | should be $true + $a -contains "TSDProvider" | should be $true + } + + It "find | install-packageprovider nuget should imported and installed, Expect succeed" { + + $a = Find-PackageProvider -name NuGet -RequiredVersion 2.8.5.202 | install-PackageProvider -force + $a.Name | Should match "NuGet" + $a.Version | Should match "2.8.5.202" + + } + + It "find | install-packageprovider nuget should imported and installed, Expect succeed" { + + $a = install-PackageProvider -name NuGet -force + $a | ?{ $_.name -eq "NuGet" } | should not BeNullOrEmpty + $a | ?{ $_.Version -gt "2.8.5.202" } | should not BeNullOrEmpty + } + + It "find | install-packageprovider myalbum should imported and installed, Expect succeed" { + + $a = Install-PackageProvider -name MyAlbum -Source $InternalSource -force + $a | ?{ $_.name -eq "MyAlbum" } | should not BeNullOrEmpty + } + + It "find | install-packageprovider myalbum should imported and installed, Expect succeed" { + + $a = Find-PackageProvider -name MyAlbum -Source $InternalSource -RequiredVersion 0.1.2 | install-PackageProvider -force + $a | ?{ $_.name -eq "MyAlbum" } | should not BeNullOrEmpty + $a | ?{ $_.Version -eq "0.1.2" } | should not BeNullOrEmpty + } + } + + + +Describe "install-packageprovider with local source" -Tags @('BVT', 'DRT') { + # make sure that packagemanagement is loaded + import-packagemanagement + + BeforeAll{ + if( test-path $destination ) { + rmdir -recurse -force $destination -ea silentlycontinue + } + mkdir $destination -ea silentlycontinue + + $nugetprovider = (install-PackageProvider -name nuget -force -RequiredVersion 2.8.5.201).name + $nugetprovider -contains "nuget" | should be $true "nuget" + + $nugetprovider = (install-PackageProvider -name nuget -force -RequiredVersion 2.8.5.202).name + $nugetprovider -contains "nuget" | should be $true "nuget" + + # setup the test folder + + mkdir $destination\2.8.5.202 -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + mkdir $destination\2.8.5.201 -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + Get-ChildItem "$ProviderFolder\Nuget\2.8.5.202" -Recurse | Copy-Item -Destination $destination\2.8.5.202\Microsoft.PackageManagement.NuGetProvider.dll -Force -Verbose + Get-ChildItem "$ProviderFolder\Nuget\2.8.5.201" -Recurse | Copy-Item -Destination $destination\2.8.5.201\Microsoft.PackageManagement.NuGetProvider.dll -Force -Verbose + Get-ChildItem "$Env:ProgramFiles\WindowsPowerShell\Modules\Microsoft.PackageManagement.Test.dll" | Copy-Item -Destination $destination -Force -verbose + + } + + AfterAll{ + + if( test-path $destination ) { + rmdir -recurse -force $destination -ea silentlycontinue + } + + $testprovider = "$ProviderFolder\Test Providers for OneGet" + if( test-path $testprovider ) { + rmdir -recurse -force $testprovider -ea silentlycontinue + } + + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + + + + It "Find-packageprovider -source filefolder, Expect succeed" { + + $a= (Find-PackageProvider -source $destination).Name + + $a -like "nuget*" | should be $true + $a -like "Test Providers for OneGet" | should be $true + + } + + It "Find-packageprovider -source filefolder -name, Expect the latest version returned" { + + $a= Find-PackageProvider -source $destination -name nuget* + + $a.Name -like "nuget*" | should match $true + $a.Version | should match "2.8.5.202" + } + + It "Find-packageprovider -source filefolder -name -allversions, Expect All versions returned" { + + $a= Find-PackageProvider -source $destination -name nuget* -AllVersions + + # all versions returned + $a | ?{$_.version -eq "2.8.5.202" } | should not BeNullOrEmpty + $a | ?{$_.version -eq "2.8.5.201" } | should not BeNullOrEmpty + + } + + It "Find-packageprovider -source file, Expect succeed" { + $a= (Find-PackageProvider -source "$destination\Microsoft.PackageManagement.Test.dll").Name + + $a -like "nuget" | should not be $true + $a -contains "Test Providers for OneGet" | should be $true + + } + + + It "Install-packageprovider -source file, Expect succeed" { + + $a= (Install-PackageProvider -source "$destination\Microsoft.PackageManagement.Test.dll" -name "Test Providers for OneGet" -force).Name + + $a -eq "Test Providers for OneGet" | should be $true + + } + + It "install-PackageProvider -source folder, Expect succeed" { + + $a= (Install-PackageProvider -force -source $destination -name "Test Providers for OneGet") + + + $a.Name -eq "Test Providers for OneGet" | should be $true + + } + + It "Find-packageprovider and install-PackageProvider, Expect succeed" { + + $a= (find-PackageProvider -Name "Test Providers for OneGet" -Source $destination | Install-PackageProvider -force) + + $a.Name -contains "Test Providers for OneGet" | should be $true + + } + + It "Find and Install PackageProvider with version, Expect succeed" { + + $a= install-PackageProvider -Name nugetprovider -Source $destination -RequiredVersion 2.8.5.201 -verbose -force + + $a.Name -like "nuget*" | should be $true + $a.Version | should match "2.8.5.201" + + } + } + +Describe "Install-Save-Package with multiple sources" -Tags @('BVT', 'DRT'){ + # make sure packagemanagement is loaded + import-packagemanagement + BeforeAll{ + #make sure we are using the latest Nuget provider + install-PackageProvider -name nuget -force + } + AfterAll{ + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + + It "install-package with array of registered sources with a single provider, Expect succeed" { + + #powershellget is the provider selected + $x= install-package TSDProvider -force -Source @($InternalSource, $InternalSource2) + + $x | ?{ $_.name -eq "TSDProvider" } | should not BeNullOrEmpty + + $y= install-package TSDProvider -force -Source @($InternalGallery, $InternalGallery2) -ProviderName nuget + + $y | ?{ $_.name -eq "TSDProvider" } | should not BeNullOrEmpty + + } + + It "install-package with array of sources, Expect succeed" { + + $x= install-package jquery -force -Source @('foooobarrrr', 'https://www.nuget.org/api/v2') -ProviderName @('PowershellGet', 'NuGet') + + $x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty + $x | ?{ $_.Source -eq "https://www.nuget.org/api/v2" } | should not BeNullOrEmpty + } + + It "install-save-package matches with multiple providers with single source, Expect succeed" { + + try + { + Register-PackageSource -Name foo -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue + Register-PackageSource -Name bar -Location $InternalGallery -ProviderName 'NuGet' -ErrorAction SilentlyContinue + if (test-path "$destination") { + rm $destination -force -Recurse + } + + + $x= install-package tsdprovider -force -Source $InternalGallery -ProviderName @('NuGet', 'PowershellGet') + + $x | ?{ $_.name -eq "tsdprovider" } | should not BeNullOrEmpty + $x | ?{ $_.Source -eq "bar" } | should not BeNullOrEmpty + $x | ?{ $_.Providername -eq "NuGet" } | should not BeNullOrEmpty + + $y= save-package tsdprovider -force -Source $InternalGallery -ProviderName @('NuGet', 'PowershellGet') -path $destination + + $y | ?{ $_.name -eq "tsdprovider" } | should not BeNullOrEmpty + $y | ?{ $_.Source -eq "bar" } | should not BeNullOrEmpty + $y | ?{ $_.Providername -eq "NuGet" } | should not BeNullOrEmpty + + (test-path "$destination\TSDProvider*") | should be $true + if (test-path "$destination\TSDProvider*") { + rm $destination\TSDProvider* -force -Recurse + } + } + finally + { + UnRegister-PackageSource -Name foo -ErrorAction SilentlyContinue + UnRegister-PackageSource -Name bar -ErrorAction SilentlyContinue + + } + } + + It "install-save-package does not match with any providers with single source, Expect fail" { + + try + { + Register-PackageSource -Name foo -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue + Register-PackageSource -Name bar -Location $InternalGallery -ProviderName 'NuGet' -ErrorAction SilentlyContinue + + + $Error.Clear() + $x= install-package jquery -force -Source $InternalGallery -ProviderName @('NuGet', 'PowershellGet') -ErrorVariable theError -ErrorAction SilentlyContinue + $theError.FullyQualifiedErrorId | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + + + $Error.Clear() + $y= save-package jquery -force -Source $InternalGallery -ProviderName @('NuGet', 'PowershellGet') -path $destination -ErrorVariable theError -ErrorAction SilentlyContinue + $theError.FullyQualifiedErrorId | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage" + + } + finally + { + UnRegister-PackageSource -Name foo -ErrorAction SilentlyContinue + UnRegister-PackageSource -Name bar -ErrorAction SilentlyContinue + + } + } + + It "install-save-package when the multiple providers find a package but no providers specified, Expect fail" { + + try + { + Register-PackageSource -Name foo -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ErrorAction SilentlyContinue + Register-PackageSource -Name bar -Location $InternalGallery -ProviderName 'NuGet' -ErrorAction SilentlyContinue + + + $Error.Clear() + $x= install-package tsdprovider -force -Source @($InternalGallery) -ErrorVariable theError -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + $theError.FullyQualifiedErrorId | should be "DisambiguateForInstall,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + + + $Error.Clear() + $y= save-package tsdprovider -force -Source @($InternalGallery) -path $destination -ErrorVariable theError -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + $theError.FullyQualifiedErrorId | should be "DisambiguateForInstall,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage" + + } + finally + { + UnRegister-PackageSource -Name foo -ErrorAction SilentlyContinue + UnRegister-PackageSource -Name bar -ErrorAction SilentlyContinue + + } + } + + It "install-save-package with multiple names, providers, Expect succeed" { + + try { + + Register-PackageSource -Name foobar -Location http://www.nuget.org/api/v2 -ProviderName 'NuGet' -ErrorAction SilentlyContinue + + if (test-path "$destination") { + rm $destination -force -Recurse + } + + + $x= install-package -name @('Bootstrap', 'jquery') -force -ProviderName @('NuGet', 'Chocolatey') + + $x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty + $x | ?{ $_.name -eq "Bootstrap" } | should not BeNullOrEmpty + + + $y= save-package -name 'jquery' -force -ProviderName @('NuGet', 'Chocolatey') -path $destination + + $x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty + + + (test-path "$destination\jquery*") | should be $true + if (test-path "$destination\jquery*") { + rm $destination\jquery* -force -Recurse + } + } + finally + { + UnRegister-PackageSource -Name foobar -ErrorAction SilentlyContinue + } + + } + + It "install-save-package with multiple names, providers and sources, Expect succeed" { + + + # Contoso and Contososerver can be found from $InternalGallery - No ambiguity. + # Jquery can be found by the NuGet from both source locations provided. + + + if (test-path "$destination") { + rm $destination -force -Recurse + } + + + $x= install-package -name @('Contoso', 'jquery', 'ContosoServer') -force -Source @($InternalGallery, 'http://www.nuget.org/api/v2', 'https://www.nuget.org/api/v2') -ProviderName @('NuGet', 'Chocolatey') + + $x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty + $x | ?{ $_.name -eq "Contoso" } | should not BeNullOrEmpty + $x | ?{ $_.name -eq "ContosoServer" } | should not BeNullOrEmpty + + + $y= save-package -name @('Contoso', 'jquery', 'ContosoServer') -force -Source @($InternalGallery,'http://www.nuget.org/api/v2','https://www.nuget.org/api/v2') -ProviderName @('NuGet', 'Chocolatey') -path $destination + + $x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty + $x | ?{ $_.name -eq "Contoso" } | should not BeNullOrEmpty + $x | ?{ $_.name -eq "ContosoServer" } | should not BeNullOrEmpty + + (test-path "$destination\Contoso*") | should be $true + if (test-path "$destination\Contoso*") { + rm $destination\Contoso* -force -Recurse + } + + } + + It "save-package with array of registered sources, Expect succeed" { + if (test-path "$destination") { + rm $destination -force -Recurse + } + + $x= save-package TSDProvider -force -Source @($InternalSource, $InternalSource2) -path $destination -ProviderName @('PowershellGet', 'NuGet') + + $x | ?{ $_.name -eq "TSDProvider" } | should not BeNullOrEmpty + + (test-path "$destination\TSDProvider*") | should be $true + if (test-path "$destination\TSDProvider*") { + rm $destination\TSDProvider* -force -Recurse + } + } + + It "save-package with array of sources, Expect succeed" { + if (test-path "$destination") { + rm $destination -force -Recurse + } + + $x= save-package jquery -force -Source @('fffffbbbbb', 'https://www.nuget.org/api/v2') -path $destination -ProviderName @('Nuget', 'Chocolatey') + + $x | ?{ $_.name -eq "jquery" } | should not BeNullOrEmpty + $x | ?{ $_.Source -eq "https://www.nuget.org/api/v2" } | should not BeNullOrEmpty + + (test-path "$destination\jquery*") | should be $true + if (test-path "$destination\jquery*") { + rm $destination\jquery* -force -Recurse + } + } +} + Describe "install-packageprovider with Whatif" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + #import-packagemanagement + + BeforeEach{ + $tempFile = [System.IO.Path]::GetTempFileName() + $whatif = "What if: Performing the operation"; + } + + AfterEach { + if(Test-Path $tempFile) + { + Remove-Item $tempFile -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + } + AfterAll{ + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + + It "install-packageprovider -name nuget with whatif, Expect succeed" { + + if($PSCulture -eq 'en-US'){ + + # Start Transcript + Start-Transcript -Path $tempFile + + install-PackageProvider -name nuget -force -warningaction:silentlycontinue -ErrorAction SilentlyContinue -whatif + + # Stop Transcript and get content of transcript file + Stop-Transcript + $transcriptContent = Get-Content $tempFile + + $transcriptContent | where { $_.Contains( $whatif ) } | should be $true + + + Remove-Item $whatif -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + } + + It "install-packageprovider -name gistprovider with whatif, Expect succeed" { + + if($PSCulture -eq 'en-US'){ + # Start Transcript + Start-Transcript -Path $tempFile + + install-PackageProvider -name gistprovider -force -source $InternalGallery -warningaction:silentlycontinue -ErrorAction SilentlyContinue -whatif + + # Stop Transcript and get content of transcript file + Stop-Transcript + $transcriptContent = Get-Content $tempFile + + $transcriptContent | where { $_.Contains( $whatif ) } | should be $true + + + Remove-Item $whatif -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + } +} + +Describe "install-packageprovider with Scope" -Tags @('BVT', 'DRT'){ + BeforeAll { + import-packagemanagement + $userName = "smartguy" + $password = "password%1" + #net user $userName /delete | Out-Null + net user $userName $password /add + $secesurestring = ConvertTo-SecureString $password -AsPlainText -Force + $credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $secesurestring + } + + AfterAll { + # Delete the user profile + net user $userName /delete | Out-Null + <#$userProfilePath = (Get-WmiObject -Class Win32_UserProfile | Where-Object {$_.LocalPath -match $userName}) + + if($path -and (Test-Path $userProfilePath.LocalPath)) { + Remove-Item $path -Force -Recurse -ErrorAction SilentlyContinue -verbose + }#> + + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + + AfterEach { + + $m= Get-InstalledModule -Name tsdprovider -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if($m -and $m.InstalledLocation) + { + Remove-Item -Path $m.InstalledLocation -Recurse -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Verbose + } + } + It "install-packageprovider without scope in a non-admin console, expect fail" { + + $Error.Clear() + + $job=Start-Job -ScriptBlock { Install-PackageProvider -Name nuget -force -requiredVersion 2.8.5.127} -Credential $credential + + Receive-Job -Wait -Job $job -ErrorVariable theError 2>&1 + $theError.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + It "install-packageprovider without scope in a non-admin console, expect fail" { + + $Error.Clear() + + $job=Start-Job -ScriptBlock { Install-PackageProvider -Name gistprovider -force } -Credential $credential + + Receive-Job -Wait -Job $job -ErrorVariable theError 2>&1 + $theError.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + It "install-packageprovider with AllUsers scope in a non-admin console, expect fail" { + $Error.Clear() + + $job=Start-Job -ScriptBlock { Install-PackageProvider -Name gistprovider -force -scope AllUsers} -Credential $credential + + Receive-Job -Wait -Job $job -ErrorVariable theError2 2>&1 + $theError2.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + + } + + It "install-packageprovider CurrentUser scope in a non-admin console, expect succeed" { + $Error.Clear() + + $job=Start-Job -ScriptBlock { + + $source="testsource" + $x =Get-PackageSource -Name $source -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if ($x) + { + Write-Verbose "exist $source" + } + else + { + Write-Verbose "'$source' does not exist. Registering it" + $InternalGallery = "https://dtlgalleryint.cloudapp.net/api/v2/" + Register-PackageSource -Name $source -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ForceBootstrap -ErrorAction SilentlyContinue + } + + Install-PackageProvider -Name tsdprovider -force -scope CurrentUser -source $source + } -Credential $credential + + + $a= Receive-Job -Wait -Job $job + $a | ?{ $_.name -eq "tsdprovider" } | should not BeNullOrEmpty + } + + It "find and install-packageprovider without scope in a non-admin console, expect fail" { + $Error.Clear() + + $job=Start-Job -ScriptBlock { Find-PackageProvider -Name gistprovider | Install-PackageProvider -force} -Credential $credential + + Receive-Job -Wait -Job $job -ErrorVariable theError3 2>&1 + $theError3.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + + } + + It "find and install-packageprovider CurrentUser scope in a non-admin console, expect succeed" { + $Error.Clear() + + $job=Start-Job -ScriptBlock { Find-PackageProvider -Name tsdprovider | Install-PackageProvider -force -scope CurrentUser} -Credential $credential + + $a= Receive-Job -Wait -Job $job + $a | ?{ $_.name -eq "tsdprovider" } | should not BeNullOrEmpty + } +} +Describe "install-PackageProvider with Versions" -Tags @('BVT', 'DRT') { + # make sure that packagemanagement is loaded + import-packagemanagement + <# Nuget + 2.8.5.127 + 2.8.5.122 + 2.8.5.120 + 2.8.5.101 + 2.8.5.24#> + + AfterAll{ + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + It "EXPECTED: success 'install, import, and get nuget package provider'" { + (install-packageprovider -name Nuget -requiredVersion 2.8.5.122 -force).Version.ToString() | should match "2.8.5.122" + + $x = powershell {(import-packageprovider -name nuget -requiredVersion 2.8.5.122 -force > $null); get-packageprovider -name nuget} + $x.Name | should match "Nuget" + $x | ?{ $_.Version.ToString() -eq "2.8.5.122" } | should not BeNullOrEmpty + } + + It "Install, import, and get a powershell package provider-required version" { + $a = (install-PackageProvider -name gistprovider -force -requiredversion 1.5 -source $InternalSource) + $a.Name -contains "gistprovider" | should be $true + $a.Version -contains "1.5" | should be $true + + $x = powershell {(import-packageprovider -name gist -requiredVersion 1.5 -force > $null); get-packageprovider -name gist -list} + + $x | ?{ $_.name -eq "Gist" } | should not BeNullOrEmpty + $x | ?{ $_.Version.ToString() -eq "1.5.0.0" } | should not BeNullOrEmpty + } + + It "EXPECTED: success 'install a provider with MinimumVersion and MaximumVersion'" { + (install-packageprovider -name nuget -MinimumVersion 2.8.5.101 -MaximumVersion 2.8.5.123 -force).Version.ToString() | should match "2.8.5.122" + } + + It "EXPECTED: success 'install a provider with MaximumVersion'" { + (install-packageprovider -name nuget -MaximumVersion 2.8.5.122 -force).Version.ToString() | should match "2.8.5.122" + } + + It "EXPECTED: success 'install a provider with MaximumVersion'" { + $a = (install-packageprovider -name gistprovider -force -Source $InternalGallery).Version.ToString() + $b = (install-packageprovider -name gistprovider -MinimumVersion 0.6 -force -Source $InternalSource).Version.ToString() + + $a -eq $b | should be $true + } +} + + +Describe "Get-package with mulitiple providers" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + It "Get-package with multiple providers" { + + $a = Install-package -Name TSDProvider -Source $InternalSource -ProviderName PowerShellGet -Force + $b = install-package -name TSDProvider -Source $InternalGallery -ProviderName NuGet -Force + + + $a.Name | should be "TSDProvider" + $b.Name | should be "TSDProvider" + + $c = Get-Package -name TSDProvider + + $c.Count -ge 2 | should be $true + $c | ?{ $_.ProviderName -eq "PowerShellGet" } | should not BeNullOrEmpty + $c | ?{ $_.ProviderName -eq "NuGet" } | should not BeNullOrEmpty + + } + +} + +Describe "install-packageprovider Error Cases" -Tags @('BVT', 'DRT') { + # make sure that packagemanagement is loaded + import-packagemanagement + + AfterAll { + Unregister-PackageSource -Name OneGetTestSource -Verbose -ErrorAction SilentlyContinue + Unregister-PackageSource -Name OneGetTestSource2 -Verbose -ErrorAction SilentlyContinue + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + } + BeforeAll { + #make sure we are using the latest Nuget provider + Install-PackageProvider -name nuget -force + Register-PackageSource -Name $InternalSource -Location $InternalGallery -ProviderName 'PowerShellGet' -Trusted -ForceBootstrap -ErrorAction SilentlyContinue + Register-PackageSource -Name $InternalSource2 -Location $InternalGallery2 -ProviderName 'PowerShellGet' -ForceBootstrap -ErrorAction SilentlyContinue + } + + It "install-packageprovider -name with wildcards, Expect error" { + $Error.Clear() + install-PackageProvider -name gist* -force -source $InternalGallery -warningaction:silentlycontinue -ErrorVariable wildcardError -ErrorAction SilentlyContinue + $wildcardError.FullyQualifiedErrorId| should be "WildCardCharsAreNotSupported,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + It "install-packageprovider - EXPECTED: returns an error when multiples sources contain the same package provider" { + $Error.Clear() + $providers = find-packageprovider -name gistprovider + $providers | ?{ $_.Source -match $InternalSource } | should not BeNullOrEmpty + $providers | ?{ $_.Source -match $InternalSource2 } | should not BeNullOrEmpty + + install-packageprovider -name gistprovider -source @($InternalSource, $InternalSource2) -ErrorVariable theError -force + $theError.FullyQualifiedErrorId| should BeNullOrEmpty + } + + It "install-package - EXPECTED: returns an error when multiples sources contain the same package provider" { + $Error.Clear() + $providers = find-package -name gistprovider + $providers | ?{ $_.Source -match $InternalSource } | should not BeNullOrEmpty + $providers | ?{ $_.Source -match $InternalSource2 } | should not BeNullOrEmpty + + install-package -name gistprovider -force -Source @($InternalSource,$InternalSource2) -warningaction:silentlycontinue -ErrorVariable theError2 -ErrorAction SilentlyContinue + $theError2.FullyQualifiedErrorId| should BeNullOrEmpty + } + + It "save-package - EXPECTED: returns an error when multiples sources contain the same package provider" { + $Error.Clear() + $providers = find-package -name gistprovider + $providers | ?{ $_.Source -match $InternalSource } | should not BeNullOrEmpty + $providers | ?{ $_.Source -match $InternalSource2 } | should not BeNullOrEmpty + + if(-not (test-path $destination) ) { + mkdir $destination -ea silentlycontinue + } + + save-package -name gistprovider -Source @($InternalSource,$InternalSource2) -path $destination -warningaction:silentlycontinue -ErrorVariable theError2 -ErrorAction SilentlyContinue + + $theError2.FullyQualifiedErrorId| should BeNullOrEmpty + } + + It "EXPECTED: returns an error when inputing a bad version format" { + $Error.Clear() + $msg = powershell 'install-packageprovider -name nuget -RequiredVersion BOGUSVERSION -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "InvalidVersion,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + + It "EXPECTED: returns an error when asking for a provider that does not exist" { + $Error.Clear() + $msg = powershell 'install-packageprovider -name NOT_EXISTS -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + + It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MinimumVersion" { + $Error.Clear() + $msg = powershell 'install-packageprovider -name NOT_EXISTS -RequiredVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with RequiredVersoin and MaximumVersion" { + $Error.Clear() + $msg = powershell 'install-packageprovider -name NOT_EXISTS -RequiredVersion 1.0 -MaximumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "VersionRangeAndRequiredVersionCannotBeSpecifiedTogether,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with a MinimumVersion greater than MaximumVersion" { + $Error.Clear() + $msg = powershell 'install-packageprovider -name nuget -MaximumVersion 1.0 -MinimumVersion 2.0 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with MinimumVersion that does not exist" { + $Error.Clear() + $msg = powershell 'install-packageprovider -name gistprovider -MinimumVersion 20.2 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } + + It "EXPECTED: returns an error when asking for a provider with MaximumVersion that does not exist" { + $Error.Clear() + $msg = powershell 'install-packageprovider -name gistprovider -MaximumVersion 0.1 -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider" + } +} diff --git a/test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 b/test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 new file mode 100644 index 000000000..66990e595 --- /dev/null +++ b/test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 @@ -0,0 +1,1677 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------ PackageManagement Test ---------------------------------------------- +ipmo "$PSScriptRoot\utility.psm1" + + +# ------------------------------------------------------------------------------ +# Actual Tests: + +$source = "http://www.nuget.org/api/v2/" +$sourceWithoutSlash = "http://www.nuget.org/api/v2" +$fwlink = "http://go.microsoft.com/fwlink/?LinkID=623861&clcid=0x409" +$longName = "THISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERSTHISISOVER255CHARACTERS"; +$workingMaximumVersions = {"2.0", "2.5", "3.0"}; +$packageNames = @("Azurecontrib", "AWSSDK", "TestLib"); +$minimumVersions = @("1.0", "1.3", "1.5"); +$maximumVersions = @("1.8", "2.1", "2.3"); +$destination = "$env:tmp\nugettests" +$relativetestpath = "$env:tmp\relativepathtestnuget" +$dependenciesSource = "$env:temp\PackageManagementDependencies" +$dtlgallery = "https://dtlgalleryint.cloudapp.net/api/v2/" +$providerName ="Microsoft-Windows-PowerShell" +$vstsFeed = "https://powershellgettest.pkgs.visualstudio.com/DefaultCollection/_packaging/psgettestfeed/nuget/v2" +$vstsFeedWithSlash = "https://powershellgettest.pkgs.visualstudio.com/DefaultCollection/_packaging/psgettestfeed/nuget/v2/" +$proxyPath = "$env:tmp\ProxyConsoleProgram\Microsoft.HttpForwarder.Console.exe" +$password = ConvertTo-SecureString "4bwvgxrbzvlxc7xgv22eehlix3enmrdwblrxkirnrc3uak23naoa" -AsPlainText -Force +$vstsCredential = New-Object System.Management.Automation.PSCredential "quoct", $password + +Get-ChildItem -Path $dependenciesSource -Recurse -Include *.nupkg | % { $_.IsReadOnly = $false } +if( test-path $destination ) { + rmdir -recurse -force $destination -ea silentlycontinue +} +mkdir $destination -ea silentlycontinue + +$pkgSources = @("NUGETTEST101", "NUGETTEST202", "NUGETTEST303"); + +$nuget = "nuget" + +# set to this feed to bootstrap the testing version +$env:BootstrapProviderTestfeedUrl = "https://onegetblob.blob.core.windows.net/test/providers.nuget.testfeed.swidtag" + +#bootstrap +Install-PackageProvider -Name $nuget -Force + +$nugetVersion = (Get-PackageProvider $nuget).Version + +"Nuget version is $nugetVersion" + +# returns true if the test for the current nuget version should be skipped or not +# Example: if we want to skip test for any nuget version below 2.8.5.205, we will use +# SkipVersion -maxVersion 2.8.5.205 +function SkipVersion([version]$minVersion,[version]$maxVersion) { + # if min version is not null and the current nuget version is less than that, then no skip + if ($minVersion -ne $null -and $nugetVersion -lt $minVersion) { + return $false + } + + if ($maxVersion -ne $null -and $nugetVersion -gt $maxVersion) { + return $false + } + + return $true +} + +Describe "Installing NuGet packages from the public feed" { + try { + $env:BootstrapProviderTestfeedUrl = [string]::Empty + + $currentPublicFeedVersion = [version]"2.8.5.205" + + $nugetFromPublicFeed = Install-PackageProvider -Name $nuget -Force + ($nugetFromPublicFeed.Version -eq $currentPublicFeedVersion) | should be $true + } + finally { + $env:BootstrapProviderTestfeedUrl = "https://onegetblob.blob.core.windows.net/test/providers.nuget.testfeed.swidtag" + + $currentTestFeedVersion = [version]"2.8.5.206" + + $nugetFromTestFeed = Install-PackageProvider -Name $nuget -Force + ($nugetFromTestFeed.Version -eq $currentTestFeedVersion) | should be $true + } +} + +Describe "Find, Get, Save, and Install-Package with Culture" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + (get-packageprovider -name "OneGetTest" -list).name | should match "OneGetTest" + $x = PowerShell '(Import-PackageProvider -name OneGetTest -RequiredVersion 9.9 -WarningAction SilentlyContinue -force ).Name' + $x | should match "OneGetTest" + + + it "EXPECTED: Find a package should not show Culture" { + + $packages = Find-Package -ProviderName OneGetTest -DisplayCulture + $packages.Culture | Should Not BeNullOrEmpty + $packages.Name | Should Not BeNullOrEmpty + } + + it "EXPECTED: Find a package with a DisplayCulture" { + + $packages = Find-Package -DisplayCulture + $packages.Culture | Should Not BeNullOrEmpty + $packages.Name | Should Not BeNullOrEmpty + } + + it "EXPECTED: Get a package should not show Culture" { + + $packages = Get-Package -DisplayCulture -ProviderName OneGetTest + $packages.Culture | Should Not BeNullOrEmpty + $packages.Name | Should Not BeNullOrEmpty + } + + it "EXPECTED: Install a package with a DisplayCulture" { + + $packages = install-Package -ProviderName OneGetTest -name jquery -force -DisplayCulture + $packages.Culture | Should Not BeNullOrEmpty + $packages.Name | Should Not BeNullOrEmpty + } + + it "EXPECTED: Save a package with a DisplayCulture" { + + $packages = save-Package -ProviderName OneGetTest -name jquery -DisplayCulture -path $destination + $packages.Culture | Should Not BeNullOrEmpty + $packages.Name | Should Not BeNullOrEmpty + } +} + +Describe "Event Test" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: install a package should raise event" { + + Install-Package EntityFramework -ProviderName nuget -requiredVersion 6.1.3 -Destination $env:tmp -source 'http://www.nuget.org/api/v2/' -force + + $retryCount= 5 + while($retryCount -gt 0) + { + $events = @(Get-WinEvent -FilterHashtable @{ ProviderName = $providerName; Id = 4101 } -ErrorAction SilentlyContinue) + + try + { + if($events) + { + $events[0].Message | Should Match "Package=jQuery" + break + } + } + catch + { + } + $retryCount-- + Start-Sleep -Milliseconds 500 + } + + if($events) + { + $event= $events[0] + $event.ProviderName | Should Match "Microsoft-Windows-PowerShell" + $event.Id | Should Match 4101 + $event.Message | Should Match "Installed" + $event.Message | Should Match "Package=EntityFramework" + $event.Message | Should Match "Version=6.1.3" + $event.Message | Should Match "Provider=NuGet" + $event.Message | Should Match "Source=http://www.nuget.org/api/v2/" + #$event.Message | Should Match ([regex]::Escape("DestinationPath=$env:tmp")) + + } + else + { + # this will fail the test + $events | Should Not BeNullOrEmpty + } + + } + + it "EXPECTED: install a package should report destination" { + + Import-PackageProvider OneGetTest -Force + Install-Package Bla -ProviderName OneGetTest -Force + + $retryCount= 5 + while($retryCount -gt 0) + { + $events = @(Get-WinEvent -FilterHashtable @{ ProviderName = $providerName; Id = 4101 } -ErrorAction SilentlyContinue) + + try + { + if($events) + { + $events[0].Message | Should Match "Package=11160201-1500_amd64fre_ServerDatacenterCore_en-us.wim" + break + } + } + catch + { + } + $retryCount-- + Start-Sleep -Milliseconds 500 + } + + if($events) + { + $event= $events[0] + $event.ProviderName | Should Match "Microsoft-Windows-PowerShell" + $event.Id | Should Match 4101 + $event.Message | Should Match "Installed" + $event.Message | Should Match "Package=11160201-1500_amd64fre_ServerDatacenterCore_en-us.wim" + $event.Message | Should Match "Version=1.0.0.0" + $event.Message | Should Match "Provider=OneGetTest" + $event.Message | Should Match "Source=from a funland" + $fullPath = [System.IO.Path]::GetFullPath($env:tmp) + $event.Message | Should Match ([regex]::Escape("DestinationPath=$fullPath\Test")) + + } + else + { + # this will fail the test + $events | Should Not BeNullOrEmpty + } + + } + + it "EXPECTED: uninstall a package should raise event" { + + Install-Package EntityFramework -ProviderName nuget -requiredVersion 6.1.3 -Destination $env:tmp -source 'http://www.nuget.org/api/v2/' -force + UnInstall-Package EntityFramework -ProviderName nuget -Destination $env:tmp + + $retryCount= 5 + while($retryCount -gt 0) + { + $events = @(Get-WinEvent -FilterHashtable @{ ProviderName = $providerName; Id = 4102 } -ErrorAction SilentlyContinue) + + try + { + if($events) + { + $events[0].Message | Should Match "Package=jQuery" + break + } + } + catch + { + } + $retryCount-- + Start-Sleep -Milliseconds 500 + } + + if($events) + { + $event= $events[0] + + $event.ProviderName | Should Match "Microsoft-Windows-PowerShell" + $event.Id | Should Match 4102 + $event.Message | Should Match "Uninstalled" + $event.Message | Should Match "Package=EntityFramework" + $event.Message | Should Match "Version=6.1.3" + $event.Message | Should Match "Provider=NuGet" + $event.Message | Should Match "EntityFramework.6.1.3.nupkg" + + } + else + { + # this will fail the test + $events | Should Not BeNullOrEmpty + } + + } + + it "EXPECTED: save a package should raise event" { + + save-Package EntityFramework -ProviderName nuget -path $env:tmp -requiredVersion 6.1.3 -source 'http://www.nuget.org/api/v2/' -force + + $retryCount= 5 + while($retryCount -gt 0) + { + $events = @(Get-WinEvent -FilterHashtable @{ ProviderName = $providerName; Id = 4103} -ErrorAction SilentlyContinue) + + try + { + if($events) + { + $events[0].Message | Should Match "Package=jQuery" + break + } + } + catch + { + } + $retryCount-- + Start-Sleep -Milliseconds 500 + } + + if($events) + { + $event= $events[0] + + $event.ProviderName | Should Match "Microsoft-Windows-PowerShell" + $event.Id | Should Match 4103 + $event.Message | Should Match "Downloaded" + $event.Message | Should Match "Package=EntityFramework" + $event.Message | Should Match "Version=6.1.3" + $event.Message | Should Match "Provider=NuGet" + $event.Message | Should Match "Source=http://www.nuget.org/api/v2/" + # $event.Message | should Match ([regex]::Escape("DestinationPath=$env:tmp")) + } + else + { + # this will fail the test + $events | Should Not BeNullOrEmpty + } + } +} + +Describe "Find-Package" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: Find a package with a location created via new-psdrive" { + + $Error.Clear() + $msg = powershell 'New-PSDrive -Name xx -PSProvider FileSystem -Root $env:tmp -warningaction:silentlycontinue -ea silentlycontinue > $null; find-package -name "fooobarrr" -provider nuget -source xx:\ -warningaction:silentlycontinue -ea silentlycontinue;$ERROR[0].FullyQualifiedErrorId' + $msg | should Not Be "SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } + + It "EXPECTED: Finds 'Zlib' Package" { + $version = "1.2.8.8" + $expectedDependencies = @("zlib.v120.windesktop.msvcstl.dyn.rt-dyn/[1.2.8.8]", "zlib.v140.windesktop.msvcstl.dyn.rt-dyn/[1.2.8.8]") + $zlib = find-package -name "zlib" -provider $nuget -source $source -RequiredVersion $version -forcebootstrap + $zlib.name | should match "zlib" + $zlib.Dependencies.Count | should be 2 + + $zlib.Meta.Attributes["packageSize"] | should match "2742" + + [long]$zlib.Meta.Attributes["versionDownloadCount"] -ge 4961 | should be $true + $zlib.Meta.Attributes["requireLicenseAcceptance"] | should match "False" + $zlib.TagId | should match "zlib#1.2.8.8" + + foreach ($dep in $zlib.Dependencies) { + $match = $false + foreach ($expectedDependency in $expectedDependencies) { + if ($dep.EndsWith($expectedDependency)) { + $match = $true + break + } + } + + $match | should be $true + } + } + + It "EXPECTED: Finds 100 packages should throw error" { + $packages = Find-Package -Provider $nuget -Source $source | Select -First 100 + + (Find-Package -ProviderName $nuget -Source $source -Name $packages.Name -ErrorAction silentlycontinue) | should throw + } + + + It "EXPECTED: Finds 128 packages should throw error" { + $packages = Find-Package -Provider $nuget -Source $source | Select -First 127 + + (Find-Package -ProviderName $nuget -Source $source -Name $packages.Name -ErrorAction silentlycontinue) | should throw + } + + It "EXPECTED: Finds 'TestPackage' Package using fwlink" { + (find-package -name "TestPackage" -provider $nuget -source $fwlink -forcebootstrap).name | should match "TestPackage" + } + + It "EXPECTED: Finds work with dependencies loop" { + (find-package -name "ModuleWithDependenciesLoop" -provider $nuget -source "$dependenciesSource\SimpleDependenciesLoop").name | should match "ModuleWithDependenciesLoop" + } + + It "EXPECTED: Finds 'Zlib' Package with -IncludeDependencies" { + $version = "1.2.8.8" + $packages = Find-Package -Name "zlib" -ProviderName $nuget -Source $source -RequiredVersion $version -ForceBootstrap -IncludeDependencies + $packages.Count | should match 3 + $expectedPackages = @("zlib", "zlib.v120.windesktop.msvcstl.dyn.rt-dyn", "zlib.v140.windesktop.msvcstl.dyn.rt-dyn") + + foreach ($expectedPackage in $expectedPackages) { + $match = $false + foreach ($package in $packages) { + # All the packages have the same version for zlib + if ($package.Name -match $expectedPackage -and $package.Version -match $version) { + $match = $true + break + } + } + + $match | should be $true + } + + } + + It "EXPECTED: Finds package with Credential" { + $credPackage = Find-Package Contoso -Credential $vstsCredential -Source $vstsFeed -ProviderName $Nuget + $credPackage.Count | should be 1 + $credPackage.Name | should match "Contoso" + + # find all packages should not error out + $packages = Find-Package -Credential $vstsCredential -Source $vstsFeed -ProviderName $Nuget + # should have at least 40 packages + $packages.Count -ge 40 | should be $true + } + + It "EXPECTED: Cannot find unlisted package" { + $msg = powershell "find-package -provider $nuget -source $dtlgallery -name hellops -erroraction silentlycontinue; `$Error[0].FullyQualifiedErrorId" + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } + + It "EXPECTED: Cannot find unlisted package with all versions parameter" { + $packages = find-package -name gistprovider -provider $nuget -source $dtlgallery -AllVersions + # we should still be able to find at least 2 listed package + $packages.Count -gt 1 | should be $true + # this version is unlisted + $packages.Version.Contains("0.6") | should be $false + # this version is listed + $packages.Version.Contains("1.2") | should be $true + } + + It "EXPECTED: Cannot find unlisted package with all versions and maximum versions" { + $packages = find-package -name gistprovider -provider $nuget -source $dtlgallery -AllVersions -MaximumVersion 1.3 + # we should still be able to find 2 listed package (which is version 1.2 and 1.3) + $packages.Count -eq 2 | should be $true + # this version is unlisted + $packages.Version.Contains("0.6") | should be $false + # this version is listed + $packages.Version.Contains("1.2") | should be $true + } + + It "EXPECTED: Cannot find unlisted package with all versions and minimum versions" { + $packages = find-package -name gistprovider -provider $nuget -source $dtlgallery -AllVersions -MinimumVersion 0.5 + # we should still be able to find at least 2 listed package (which is version 1.2 and 1.3) + $packages.Count -gt 2 | should be $true + # this version is unlisted + $packages.Version.Contains("0.6") | should be $false + # this version is listed + $packages.Version.Contains("1.2") | should be $true + } + + It "EXPECTED: Finds unlisted package with required version" { + (find-package -name hellops -provider $nuget -source $dtlgallery -requiredversion 0.1.0).Name | should match "HellOps" + } + + It "EXPECTED: Cannot find unlisted package with maximum versions" { + # error out because all the versions below 0.6 are unlisted + $msg = powershell "find-package -provider $nuget -source $dtlgallery -name gistprovider -maximumversion 0.6 -erroraction silentlycontinue; `$Error[0].FullyQualifiedErrorId" + $msg | should be "NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } + + It "EXPECTED: Cannot find unlisted package with minimum versions" { + $packages = find-package -name gistprovider -provider $nuget -source $dtlgallery -AllVersions -MinimumVersion 0.5 + # we should still be able to find at least 2 listed package (which is version 1.2 and 1.3) + $packages.Count -gt 2 | should be $true + # this version is unlisted + $packages.Version.Contains("0.6") | should be $false + # this version is listed + $packages.Version.Contains("1.2") | should be $true + } + + It "EXPECTED: Finds 'awssdk' package which has more than 200 versions" { + (find-package -name "awssdk" -provider $nuget -source $source -forcebootstrap -AllVersions).Count -gt 200 | should be $true + + # Uncomment this once publish the new version of nuget + $awssdk = Find-Package -Name "awssdk" -Provider $nuget -source $source -forcebootstrap -RequiredVersion 2.3.53 + [long]$awssdk.Meta.Attributes["downloadCount"] -ge 1023357 | should be $true + $awssdk.Meta.Attributes["updated"] | should match "2015-12-15T17:46:22Z" + $awssdk.TagId | should match "AWSSDK#2.3.53.0" + } + + It "EXPECTED: Finds A Combination Of Packages With Various Versions" { + foreach ($x in $packageNames) { + foreach ($y in $minimumVersions) { + foreach ($z in $maximumVersions) { + (find-package -name $x -source $source -provider $nuget -minimumversion $y -maximumversion $z).name | should be $x + } + } + } + } + + It "EXPECTED: Finds 'Zlib' Package After Piping The Provider" { + (get-packageprovider -name $nuget | find-package -name zlib -source $source ).name | should be "zlib" + } + + It "EXPECTED: -FAILS- To Find Package Due To Too Long Of Name" { + (find-package -name $longName -provider $nuget -source $source -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Find Package Due To Invalid Name" { + (find-package -name "1THIS_3SHOULD_5NEVER_7BE_9FOUND_11EVER" -provider $nuget -source $source -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Find Package Due To Negative Maximum Version Parameter" { + (find-package -name "zlib" -provider $nuget -source $source -maximumversion "-1.5" -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Find Package Due To Negative Minimum Version Parameter" { + (find-package -name "zlib" -provider $nuget -source $source -minimumversion "-1.5" -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Find Package Due To Negative Required Version Parameter" { + (find-package -name "zlib" -provider $nuget -source $source -requiredversion "-1.5" -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Find Package Due To Out Of Bounds Required Version Parameter" { + (find-package -name "zlib" -provider $nuget -source $source -minimumversion "1.0" -maximumversion "1.5" -requiredversion "2.0" -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Find Package Due To Minimum Version Parameter Greater Than Maximum Version Parameter" { + (find-package -name "zlib" -provider $nuget -source $source -minimumversion "1.5" -maximumversion "1.0" -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- Find-Package with wrong source should not error out about dynamic parameter" { + $msg = powershell "find-package -source WrongSource -name zlib -erroraction silentlycontinue -Contains PackageManagement; `$Error[0].FullyQualifiedErrorId" + $msg | should be "SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } + + It "EXPECTED: -FAILS- Find-Package with wrong source and wrong dynamic parameter" { + $msg = powershell "find-package -source WrongSource -name zlib -erroraction silentlycontinue -WrongDynamicParameter PackageManagement; `$Error[0].FullyQualifiedErrorId" + $msg | should be "SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } +} + +Describe Save-Package -Tags @('BVT', 'DRT'){ + # make sure packagemanagement is loaded + import-packagemanagement + + + It "EXPECTED success: save-package path should be created with -force " { + $dest = "$destination\NeverEverExists" + $package = save-package -name TSDProvider -path $dest -source $dtlgallery -provider $nuget -force + + $package.Name | should be "TSDProvider" + (test-path "$dest\TSDProvider*") | should be $true + if (test-path "$dest\TSDProvider*") { + rm $dest\TSDProvider* -force + } + if (test-path "$dest") { + rm $dest -force + } + } + + It "EXPECTED success: save-package -LiteralPath" { + + $package = save-package -LiteralPath $destination -ProviderName nuget -Source $dtlgallery -name TSDProvider + + $package.Name | should be "TSDProvider" + (test-path "$destination\TSDProvider*") | should be $true + if (test-path "$destination\TSDProvider*") { + rm $destination\TSDProvider* -force + } + } + + It "EXPECTED success: save-package -LiteralPath" { + $dest = "$destination\NeverEverExists" + $package = save-package -LiteralPath $dest -ProviderName nuget -Source $dtlgallery -name TSDProvider -force + + $package.Name | should be "TSDProvider" + (test-path "$dest\TSDProvider*") | should be $true + if (test-path "$dest\TSDProvider*") { + rm $dest\TSDProvider* -force + } + if (test-path "$dest") { + rm $dest -force + } + } + + It "EXPECTED success: find-package and save-package" { + $package = find-package -name TSDProvider -provider $nuget -source $dtlgallery | save-package -path $destination + + $package.Name | should be "TSDProvider" + (test-path "$destination\TSDProvider*") | should be $true + if (test-path "$destination\TSDProvider*") { + rm $destination\TSDProvider* -force + } + } + + It "save-package -name with wildcards, Expect error" { + $Error.Clear() + $package = save-package -path $destination -name DOESNOTEXIST* -warningaction:silentlycontinue -ErrorVariable wildcardError -ErrorAction SilentlyContinue + $wildcardError.FullyQualifiedErrorId| should be "WildCardCharsAreNotSupported,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage" + } + + it "EXPECTED: Saves 'Zlib' Package To Packages Directory" { + $version = "1.2.8.8" + $expectedPackages = @("zlib", "zlib.v120.windesktop.msvcstl.dyn.rt-dyn", "zlib.v140.windesktop.msvcstl.dyn.rt-dyn") + $newDestination = "$env:tmp\nugetinstallation" + + try { + $packages = Save-Package -Name "zlib" -ProviderName $nuget -Source $source -RequiredVersion $version -ForceBootstrap -Path $destination + $packages.Count | should match 3 + + foreach ($expectedPackage in $expectedPackages) { + #each of the expected package should be there + Test-Path "$destination\$expectedPackage*" | should be $true + + $match = $false + foreach ($package in $packages) { + # All the packages have the same version for zlib + if ($package.Name -match $expectedPackage -and $package.Version -match $version) { + $match = $true + break + } + } + + $match | should be $true + } + + mkdir $newDestination + # make sure we can install the package. To do this, we need to save the dependencies first + (save-package -name "zlib.v120.windesktop.msvcstl.dyn.rt-dyn" -RequiredVersion $version -provider $nuget -source $source -path $destination) + (save-package -name "zlib.v140.windesktop.msvcstl.dyn.rt-dyn" -RequiredVersion $version -provider $nuget -source $source -path $destination) + + (install-package -name "zlib" -provider $nuget -source $destination -destination $newDestination -force -RequiredVersion $version) + (test-path "$newDestination\zlib.1.2*") | should be $true + + # Test that we have the nupkg file + (test-path "$newDestination\zlib.1.2*\zlib*.nupkg") | should be $true + # Test that dependencies are installed + (test-path "$newDestination\zlib.v120*") | should be $true + (test-path "$newDestination\zlib.v120*\zlib.v120*.nupkg") | should be $true + (test-path "$newDestination\zlib.v140*") | should be $true + (test-path "$newDestination\zlib.v140*\zlib.v140*.nupkg") | should be $true + } + finally { + if (Test-Path $newDestination) { + Remove-Item -Recurse -Force -Path $newDestination + } + + if (Test-Path $destination\zlib*) { + rm $destination\zlib* + } + + } + } + + it "EXPECTED: Saves 'Zlib' Package to Packages Directory and install it without dependencies" { + $version = "1.2.8.8" + $newDestination = "$env:tmp\nugetinstallation" + + try { + (save-package -name "zlib" -provider $nuget -source $source -Path $destination -RequiredVersion $version) + (test-path $destination\zlib*) | should be $true + remove-item $destination\zlib.v1* -force -Recurse -ErrorAction SilentlyContinue + + $msg = powershell "install-package -name zlib -provider $nuget -source $destination -destination $newDestination -force -RequiredVersion $version -ErrorAction SilentlyContinue; `$Error[0].FullyQualifiedErrorId" + $msg | should match "UnableToFindDependencyPackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + (Test-Path "$newDestination\zlib*") | should be $false + } + finally { + if (Test-Path $newDestination) { + Remove-Item -Recurse -Force -Path $newDestination + } + + if (Test-Path $destination\zlib*) { + rm $destination\zlib* + } + + } + } + + It "EXPECTED: Saves work with dependencies loop" { + try { + $msg = powershell "save-package -name ModuleWithDependenciesLoop -provider $nuget -source `"$dependenciesSource\SimpleDependenciesLoop`" -path $destination -ErrorAction SilentlyContinue -WarningAction SilentlyContinue; `$Error[0].FullyQualifiedErrorId" + $msg | should match "ProviderFailToDownloadFile,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage" + (Test-Path $destination\ModuleWithDependenciesLoop*) | should be $false + } + finally { + if (Test-Path $destination\ModuleWithDependenciesLoop*) { + rm $destination\ModuleWithDependenciesLoop* + } + } + } + + It "EXPECTED: Saves 'TestPackage' Package using fwlink" { + try { + (save-package -name "TestPackage" -provider $nuget -source $fwlink -Path $Destination) + (Test-Path $destination\TestPackage*) | should be $true + } + finally { + if (Test-Path $destination\TestPackage*) { + rm $destination\TestPackage* + } + } + } + + It "EXPECTED: Saves 'awssdk' package which has more than 200 versions" { + (save-package -name "awssdk" -provider $nuget -source $source -Path $destination) + (test-path $destination\awssdk*) | should be $true + if (Test-Path $destination\awssdk*) { + rm $destination\awssdk* + } + } + + It "EXPECTED: Saves package with Credential" { + Save-Package Contoso -Credential $vstsCredential -Source $vstsFeed -ProviderName $Nuget -Path $destination + (Test-Path $destination\contoso*) | should be $true + + if (Test-Path $destination\contoso*) { + rm $destination\contoso* + } + } + + it "EXPECTED: Saves Various Packages With Various Version Parameters To Packages Directory" { + foreach ($x in $packageNames) { + foreach ($y in $minimumVersions) { + foreach ($z in $maximumVersions) { + save-package -name $x -source $source -provider $nuget -minimumversion $y -maximumversion $z -Path $destination + (Test-Path -Path $destination\$x*) | should be $true + if (Test-Path -Path $destination\$x*) { + rm $destination\$x* + } + } + } + } + } + + It "EXPECTED: Saves 'Zlib' Package After Having The Provider Piped" { + (find-package -name "zlib" -provider $nuget -source $source | save-package -Path $destination) + (Test-Path -Path $destination\zlib*) | should be $true + if (Test-Path -Path $destination\zlib*) { + rm $destination\zlib* + } + } + + It "EXPECTED: -FAILS- To Save Package Due To Too Long Of Name" { + (save-package -name $longName -provider $nuget -source $source -Path $destination -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Save Package Due To Invalid Name" { + (save-package -name "1THIS_3SHOULD_5NEVER_7BE_9FOUND_11EVER" -provider $nuget -source $source -Path $destination -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Save Package without folder pre-created" { + (save-package -name Jquery -provider $nuget -source $source -Path "$destination\SavePackageTest\FolderDoesNotExist" -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Save Package -LiteralPath without folder pre-created" { + (save-package -name Jquery -provider $nuget -source $source -LiteralPath "$destination\SavePackageTest\FolderDoesNotExist" -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Save Package Due To Negative Maximum Version Parameter" { + (save-package -name "zlib" -provider $nuget -source $source -maximumversion "-1.5" -Path $destination -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Save Package Due To Negative Minimum Version Parameter" { + (save-package -name "zlib" -provider $nuget -source $source -minimumversion "-1.5" -Path $destination -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Save Package Due To Negative Required Version Parameter" { + (save-package -name "zlib" -provider $nuget -source $source -requiredversion "-1.5" -Path $destination -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Save Package Due To Out Of Bounds Required Version Parameter" { + (save-package -name "zlib" -provider $nuget -source $source -minimumversion "1.0" -maximumversion "1.5" -requiredversion "2.0" -Path $destination -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Save Package Due To Minimum Version Parameter Greater Than Maximum Version Parameter" { + (save-package -name "zlib" -provider $nuget -source $source -minimumversion "1.5" -maximumversion "1.0" -Path $destination -EA silentlycontinue) | should throw + } +} + +Describe "save-package with Whatif" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + #import-packagemanagement + $tempDir = "$env:temp\nugettesttempfolder" + + BeforeEach{ + $tempFile = [System.IO.Path]::GetTempFileName() + $whatif = "What if: Performing the operation"; + + if (-not (Test-Path $tempDir)) + { + md $tempDir | Out-Null + } + } + + AfterEach { + if(Test-Path $tempFile) + { + Remove-Item $tempFile -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + } + + It "install-package -name nuget with whatif, Expect succeed" { + if($PSCulture -eq 'en-US'){ + # Start Transcript + Start-Transcript -Path $tempFile + + Save-Package -name jquery -force -source $source -ProviderName NuGet -Path $tempDir -warningaction:silentlycontinue -ErrorAction SilentlyContinue -whatif + + # Stop Transcript and get content of transcript file + Stop-Transcript + $transcriptContent = Get-Content $tempFile + + $transcriptContent | where { $_.Contains( $whatif ) } | should be $true + Test-Path C:\foof | should be $false + + + Remove-Item $whatif -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + } + + It "install-package -name nuget with whatif where package has a dependencies, Expect succeed" { + {Save-Package -name zlib -source https://www.nuget.org/api/v2/ ` + -ProviderName NuGet -Path $tempDir -whatif} | should not throw + } +} + + +Describe "install-package with Whatif" -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + #import-packagemanagement + + BeforeEach{ + $tempFile = [System.IO.Path]::GetTempFileName() + $whatif = "What if: Performing the operation"; + Remove-Item c:\foof -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Force + } + + AfterEach { + if(Test-Path $tempFile) + { + Remove-Item $tempFile -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + } + + It "install-package -name nuget with whatif, Expect succeed" { + if($PSCulture -eq 'en-US'){ + # Start Transcript + Start-Transcript -Path $tempFile + + install-Package -name jquery -force -source $source -ProviderName NuGet -destination c:\foof -warningaction:silentlycontinue -ErrorAction SilentlyContinue -whatif + + # Stop Transcript and get content of transcript file + Stop-Transcript + $transcriptContent = Get-Content $tempFile + + $transcriptContent | where { $_.Contains( $whatif ) } | should be $true + Test-Path C:\foof | should be $false + + + Remove-Item $whatif -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + } + + It "install-package -name nuget with whatif where package has a dependencies, Expect succeed" { + {install-Package -name zlib -source https://www.nuget.org/api/v2/ ` + -ProviderName NuGet -destination c:\foof -whatif} | should not throw + } +} + +Describe "install-package with Scope" -Tags @('BVT', 'DRT'){ + BeforeAll { + import-packagemanagement + $userName = "smartguy" + $password = "password%1" + net user $userName $password /add + $secesurestring = ConvertTo-SecureString $password -AsPlainText -Force + $credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $secesurestring + } + + AfterAll { + # Delete the user profile + net user $userName /delete | Out-Null + } + + it "EXPECTED Success: Get and Install-Package without Scope without destination" { + + $ProgramFiles = [Environment]::GetFolderPath("ProgramFiles") + $UserInstalledLocation = "$($ProgramFiles)\Nuget\Packages" + + + if (Test-Path $UserInstalledLocation) { + Remove-Item -Recurse -Force -Path $UserInstalledLocation -ErrorAction SilentlyContinue + } + + $package = install-package -ProviderName nuget -source $dtlgallery -name gistprovider -RequiredVersion 0.6 -force + + $package.Name | Should Match "GistProvider" + + $packages = Get-package -ProviderName nuget + + $packages | ?{ $_.Name -eq "GistProvider" } | should not BeNullOrEmpty + + (Test-Path "$UserInstalledLocation\GistProvider*") | should be $true + } + + it "EXPECTED Success: Get and Install-Package AllUsers Scope Without destination" { + + $ProgramFiles = [Environment]::GetFolderPath("ProgramFiles") + $UserInstalledLocation = "$($ProgramFiles)\Nuget\Packages" + + + if (Test-Path $UserInstalledLocation) { + Remove-Item -Recurse -Force -Path $UserInstalledLocation -ErrorAction SilentlyContinue + } + + $package = install-package -ProviderName nuget -source $dtlgallery -name gistprovider -RequiredVersion 0.6 -scope AllUsers -force + + $package.Name | Should Match "GistProvider" + + $packages = Get-package -ProviderName nuget + + $packages | ?{ $_.Name -eq "GistProvider" } | should not BeNullOrEmpty + + (Test-Path "$UserInstalledLocation\GistProvider*") | should be $true + } + + it "EXPECTED Success: Get and Install-Package -Scope CurrentUser with destination" { + + $userProfile = [Environment]::GetFolderPath("LocalApplicationData") + $UserInstalledLocation = "$($userProfile)\PackageManagement\Nuget\Packages" + + + if (Test-Path $UserInstalledLocation) { + Remove-Item -Recurse -Force -Path $UserInstalledLocation -ErrorAction SilentlyContinue + } + + $package = install-package -ProviderName nuget -source $dtlgallery -name gistprovider -RequiredVersion 0.6 -scope CurrentUser -destination $UserInstalledLocation -force + + $package.Name | Should Match "GistProvider" + + $packages = Get-package -ProviderName nuget + + $packages | ?{ $_.Name -eq "GistProvider" } | should not BeNullOrEmpty + + (Test-Path "$UserInstalledLocation\GistProvider*") | should be $true + } + + It "install-package CurrentUser scope in a non-admin console, expect succeed" { + $Error.Clear() + $job=Start-Job -ScriptBlock {Param ([Parameter(Mandatory = $True)] [string]$dtlgallery) install-package -ProviderName nuget -source $dtlgallery -name gistprovider -RequiredVersion 0.6 -force -scope CurrentUser} -Credential $credential -ArgumentList $dtlgallery + + $a= Receive-Job -Wait -Job $job + $a.Name | should match 'gistprovider' + } + + It "install-package without scope in a non-admin console, expect fail" { + + $Error.Clear() + + $job=Start-Job -ScriptBlock { + install-package -ProviderName nuget -source http://nuget.org/api/v2 -name jquery -force + } -Credential $credential + + Receive-Job -Wait -Job $job -ErrorVariable theError 2>&1 + $theError.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + } + + It "install-package with AllUsers scope in a non-admin console, expect fail" { + $Error.Clear() + + $job=Start-Job -ScriptBlock {install-package -ProviderName nuget -source http://nuget.org/api/v2 -name jquery -force -scope AllUsers} -Credential $credential + + Receive-Job -Wait -Job $job -ErrorVariable theError2 2>&1 + $theError2.FullyQualifiedErrorId | should be "InstallRequiresCurrentUserScopeParameterForNonAdminUser,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + + } +} + +Describe Install-Package -Tags @('BVT', 'DRT'){ + # make sure packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: Installs 'Zlib' Package To Packages Directory" { + $version = "1.2.8.8" + (install-package -name "zlib" -provider $nuget -source $source -destination $destination -force -RequiredVersion $version) + (test-path $destination\zlib.1.2*) | should be $true + # Test that dependencies are installed + (test-path $destination\zlib.v120*) | should be $true + (test-path $destination\zlib.v140*) | should be $true + if (Test-Path $destination\zlib*) { + (Remove-Item -Recurse -Force -Path $destination\zlib*) + } + } + + It "EXPECTED: Install package with credential" { + try { + Install-Package -Name Contoso -Provider $nuget -Source $vstsFeed -Credential $vstsCredential -Destination $destination -Force + Test-Path $destination\Contoso* | should be $true + } + finally { + if (Test-Path $destination\Contoso*) { + Remove-Item -Recurse -Force -Path $destination\Contoso* + } + } + } + + It "install-packageprovider -name with wildcards, Expect error" { + $Error.Clear() + install-Package -name gist* -force -source $source -warningaction:silentlycontinue -ErrorVariable wildcardError -ErrorAction SilentlyContinue + $wildcardError.FullyQualifiedErrorId| should be "WildCardCharsAreNotSupported,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + } + + it "EXPECTED: Installs package should decode percent-encoding string" { + # Tab has a ++ folder + try { + Install-Package -Name Tab -RequiredVersion 1.0 -Source $dtlgallery -ProviderName NuGet -Destination $destination -Force + Test-Path "$destination\Tab.1.0.0.0\New folder ++" | should be $true + } + finally { + if (Test-Path $destination\Tab*) { + Remove-Item -Recurse -Force -Path $destination\Tab* + } + } + } + + it "EXPECTED: Fails to install a module with simple dependencies loop" { + $msg = powershell "Install-Package ModuleWithDependenciesLoop -ProviderName nuget -Source `"$dependenciesSource\SimpleDependenciesLoop`" -Destination $destination -ErrorAction SilentlyContinue; `$Error[0].FullyQualifiedErrorId" + $msg | should be "DependencyLoopDetected,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + + } + + it "EXPECTED: Fails to install a module with a big dependencies loop" { + $msg = powershell "Install-Package ModuleA -ProviderName nuget -source `"$dependenciesSource\BigDependenciesLoop`" -Destination $destination -ErrorAction SilentlyContinue;`$Error[0].FullyQualifiedErrorId" + $msg | should be "DependencyLoopDetected,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + } + + It "EXPECTED: Installs to existing relative path" { + $oldPath = $PSScriptRoot + + try { + if (-not (Test-Path $relativetestpath)) { + md $relativetestpath + } + + cd $relativetestpath + + $subdir = ".\subdir" + + if (-not (Test-Path $subdir)) { + md $subdir + } + + (install-package -Name "TestPackage" -ProviderName $nuget -Source $fwlink -Destination $subdir -Force) + (Test-Path "$subdir\TestPackage*") | should be $true + } + finally { + cd $oldPath + if (Test-Path $relativetestpath) { + Remove-Item -Recurse -Force -Path $relativetestpath -ErrorAction SilentlyContinue + } + } + } + + It "EXPECTED: Installs to non existing relative path" { + $oldPath = $PSScriptRoot + + try { + if (-not (Test-Path $relativetestpath)) { + md $relativetestpath + } + + cd $relativetestpath + + $subdir = ".\subdir\subdir" + + if (Test-Path $subdir) { + Remove-Item -Recurse -Force -Path $subdir + } + + (install-package -Name "TestPackage" -ProviderName $nuget -Source $fwlink -Destination $subdir -Force) + (Test-Path "$subdir\TestPackage*") | should be $true + } + finally { + cd $oldPath + if (Test-Path $relativetestpath) { + Remove-Item -Recurse -Force -Path $relativetestpath -ErrorAction SilentlyContinue + } + } + } + + It "EXPECTED: Installs 'TestPackage' Package using fwlink" { + try { + (install-package -name "TestPackage" -provider $nuget -source $fwlink -Destination $Destination -force) + (Test-Path $destination\TestPackage*) | should be $true + } + finally { + if (Test-Path $destination\TestPackage*) { + Remove-Item -Recurse -Force $destination\TestPackage* + } + } + } + + it "EXPECTED: Installs 'awssdk' Package which has more than 200 versions To Packages Directory" { + (install-package -name "awssdk" -provider $nuget -source $source -destination $destination -maximumversion 2.3 -force) + (test-path $destination\awssdk*) | should be $true + if (Test-Path $destination\awssdk*) { + (Remove-Item -Recurse -Force -Path $destination\awssdk*) + } + } + + it "EXPECTED: Installs Various Packages With Various Version Parameters To Packages Directory" { + foreach ($x in $packageNames) { + foreach ($y in $minimumVersions) { + foreach ($z in $maximumVersions) { + (install-package -name $x -source $source -provider $nuget -minimumversion $y -maximumversion $z -destination $destination -force) + (Test-Path -Path $destination\$x*) | should be $true + if (Test-Path -Path $destination\$x*) { + (Remove-Item -Recurse -Force -Path $destination\$x*) + } + } + } + } + } + + It "EXPECTED: Installs 'Zlib' Package After Having The Provider Piped" { + (find-package -name "zlib" -provider $nuget -source $source | install-package -destination $destination -force) + (Test-Path -Path $destination\zlib*) | should be $true + if (Test-Path -Path $destination\zlib*) { + (Remove-Item -Recurse -Force -Path $destination\zlib*) + } + } + + It "EXPECTED: -FAILS- To Install Package Due To Too Long Of Name" { + (install-package -name $longName -provider $nuget -source $source -destination $destination -force -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Install Package Due To Invalid Name" { + (install-package -name "1THIS_3SHOULD_5NEVER_7BE_9FOUND_11EVER" -provider $nuget -source $source -destination $destination -force -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Install Package Due To Negative Maximum Version Parameter" { + (install-package -name "zlib" -provider $nuget -source $source -maximumversion "-1.5" -destination $destination -force -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Install Package Due To Negative Maximum Version Parameter" { + (install-package -name "zlib" -provider $nuget -source $source -minimumversion "-1.5" -destination $destination -force -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Install Package Due To Negative Maximum Version Parameter" { + (install-package -name "zlib" -provider $nuget -source $source -requiredversion "-1.5" -destination $destination -force -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Install Package Due To Out Of Bounds Required Version Parameter" { + (install-package -name "zlib" -provider $nuget -source $source -minimumversion "1.0" -maximumversion "1.5" -requiredversion "2.0" -destination $destination -force -EA silentlycontinue) | should throw + } + + It "EXPECTED: -FAILS- To Install Package Due To Minimum Version Parameter Greater Than Maximum Version Parameter" { + (install-package -name "zlib" -provider $nuget -source $source -minimumversion "1.5" -maximumversion "1.0" -destination $destination -force -EA silentlycontinue) | should throw + } +} + +Describe Get-Package -Tags @('BVT', 'DRT'){ + # make sure packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: Gets The 'Adept.NugetRunner' Package After Installing" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (get-package -name "adept.nugetrunner" -provider $nuget -destination $destination).name | should be "adept.nugetrunner" + if (Test-Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: Gets The 'Adept.NugetRunner' Package After Installing And After Piping The Provider" { + (install-package -name "adept.nugetrunner" -provider $nuget -destination $destination -source $source -force) + (get-packageprovider -name $nuget | get-package "adept.nugetrunner" -destination $destination).name | should be "adept.nugetrunner" + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Get Package Due To Too Long Of Name" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (get-package -name $longName -provider $nuget -destination $destination -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Get Package Due To Invalid Name" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (get-package -name "1THIS_3SHOULD_5NEVER_7BE_9FOUND_11EVER" -provider $nuget -destination $destination -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Get Package Due To Out Of Bounds Required Version Parameter" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (get-package -name "adept.nugetrunner" -provider $nuget -maximumversion "4.0" -minimumversion "1.0" -requiredversion "5.0" -destination $destination -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Get Package Due To Minimum Version Parameter Greater Than Maximum Version Parameter" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (get-package -name "adept.nugetrunner" -provider $nuget -maximumversion "3.0" -minimumversion "4.0" -destination $destination -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } +} + +Describe Uninstall-Package -Tags @('BVT', 'DRT'){ + # make sure packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: Uninstalls The Right version of 'Jquery'" { + + (install-package -name "Jquery" -provider $nuget -source $source -destination $destination -RequiredVersion 2.1.3 -force).Version | Should match "2.1.3" + (install-package -name "Jquery" -provider $nuget -source $source -destination $destination -RequiredVersion 2.1.4 -force).Version | Should match "2.1.4" + + #uninstall the old version + uninstall-package -name "Jquery" -provider $nuget -destination $destination -RequiredVersion 2.1.3 + + #the old version should be gone but the later should exist + (Get-Package -ProviderName nuget -RequiredVersion 2.1.3 -Name jquery -Destination $destination -EA silentlycontinue) | should throw + (Get-Package -ProviderName nuget -RequiredVersion 2.1.4 -Name jquery -Destination $destination).Version | should be "2.1.4" + + } + + it "EXPECTED: Uninstalls The'Adept.Nugetrunner' Package From The Packages Directory" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (uninstall-package -name "adept.nugetrunner" -provider $nuget -destination $destination -force) + (Test-Path -Path $destination\adept.nugetrunner*) | should be $false + } + + It "EXPECTED: Uninstalls The'Adept.Nugetrunner' Package From The Packages Directory After Having The Package Piped" { + (install-package -name "adept.nugetrunner" -provider $nuget -destination $destination -source $source -force) + (get-package -name "adept.nugetrunner" -provider $nuget -destination $destination | uninstall-package -force) + (Test-Path -Path $destination\adept.nugetrunner*) | should be $false + } + + It "EXPECTED: -FAILS- To Uninstall Package Due To Too Long Of Name" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (uninstall-package -name $longName -provider $nuget -destination $destination -force -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Uninstall Package Due To Invalid Name" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (uninstall-package -name "1THIS_3SHOULD_5NEVER_7BE_9FOUND_11EVER" -provider $nuget -destination $destination -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Uninstall Package Due To Out Of Bounds Required Version Parameter" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (uninstall-package -name "adept.nugetrunner" -provider $nuget -maximumversion "4.0" -minimumversion "1.0" -requiredversion "5.0" -destination $destination -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Uninstall Package Due To Minimum Version Parameter Greater Than Maximum Version Parameter" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (uninstall-package -name "adept.nugetrunner" -provider $nuget -maximumversion "3.0" -minimumversion "4.0" -destination $destination -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Uninstall Package Due To Negative Maximum Version Parameter" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (uninstall-package -name "zlib" -provider $nuget -maximumversion "-1.5" -destination $destination -force -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Uninstall Package Due To Negative Minimum Version Parameter" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (uninstall-package -name "zlib" -provider $nuget -minimumversion "-1.5" -destination $destination -force -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "EXPECTED: -FAILS- To Uninstall Package Due To Negative Required Version Parameter" { + (install-package -name "adept.nugetrunner" -provider $nuget -source $source -destination $destination -force) + (uninstall-package -name "zlib" -provider $nuget -requiredversion "-1.5" -destination $destination -force -EA silentlycontinue) | should throw + if (Test-Path -Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "E2E: Uninstall all versions of a specific package - Nuget Provider" { + $packageName = "adept.nugetrunner" + ($foundPackages = Find-Package -Name $packageName -Provider $nuget -Source $source -AllVersions) + + # Install all versions of the package + foreach ($package in $foundPackages) + { + ($package | Install-Package -Destination $destination -Force) + } + + # Uninstall all versions of the package + Uninstall-Package -Name $packageName -Provider $nuget -AllVersions -Destination $destination + + # Get-Package must not return any packages - since we just uninstalled allversions of the package + $msg = powershell 'Get-Package -Name "adept.nugetrunner" -Provider $nuget -Destination $destination -AllVersions -warningaction:silentlycontinue -ea silentlycontinue; $ERROR[0].FullyQualifiedErrorId' + $msg | should be "NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage" + + if (Test-Path $destination\adept.nugetrunner*) { + (Remove-Item -Recurse -Force -Path $destination\adept.nugetrunner*) + } + } + + It "uninstall-package -name with wildcards, Expect error" { + $Error.Clear() + $package = uninstall-package -name packagemanagement* -warningaction:silentlycontinue -ErrorVariable wildcardError -ErrorAction SilentlyContinue + $wildcardError.FullyQualifiedErrorId| should be "WildCardCharsAreNotSupported,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage" + } + + It "uninstall-package -name with whitespaces only, Expect error" { + $Error.Clear() + $package = uninstall-package -name " " -warningaction:silentlycontinue -ErrorVariable wildcardError -ErrorAction SilentlyContinue + $wildcardError.FullyQualifiedErrorId| should be "WhitespacesAreNotSupported,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage" + } +} + +Describe Get-PackageProvider -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: Gets The 'Nuget' Package Provider" { + (get-packageprovider -name $nuget -force).name | should be $nuget + } + + it "EXPECTED: Should not raise pending reboot operations" { + $count = (get-itemproperty "hklm:\system\currentcontrolset\control\session manager").PendingFileRenameOperations.Count + $providers = powershell "get-packageprovider" + $countAfter = (get-itemproperty "hklm:\system\currentcontrolset\control\session manager").PendingFileRenameOperations.Count + ($count -eq $countAfter) | should be $true + } +} + +Describe Get-PackageSource -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + BeforeAll{ + #make sure the package repository exists + Register-PackageSource -Name 'NugetTemp1' -Location "https://www.PowerShellGallery.com/Api/V2/" -ProviderName 'nuget' -Trusted -ForceBootstrap -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + Register-PackageSource -Name 'NugetTemp2' -Location "https://www.nuget.org/api/v2" -ProviderName 'nuget' -Trusted -ForceBootstrap -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + AfterAll { + UnRegister-PackageSource -Name 'NugetTemp1' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + UnRegister-PackageSource -Name 'NugetTemp2' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } + + It "find-install-get-package Expect succeed" { + + find-package jquery | install-package -destination $destination -force -ForceBootstrap + (Test-Path $destination\jquery*) | should be $true + $a=get-package -Destination $destination -Name jquery + $a | where { $_.Name -eq 'jQuery' } | should be $true + } + + It "get-packageprovider--find-package, Expect succeed" { + + $a=(get-packageprovider -name nuget| find-package -Name jquery ) + $a | where { $_.Name -eq 'jQuery' } | should be $true + } + + It "get-packagesource--find-package, Expect succeed" { + + $a=(get-packagesource | find-package jquery -ForceBootstrap) + $a | where { $_.Name -eq 'jQuery' } | should be $true + } + + it "EXPECTED: Gets The 'Nuget' Package Provider" { + $a = Get-PackageSource -Name *Temp* + $a | ?{ $_.name -eq "NugetTemp1" } + $a | ?{ $_.name -eq "NugetTemp2" } + } + + it "EXPECTED: Gets The 'Nuget' Package Provider" { + $a = Get-PackageSource -Name *Temp* -Location "https://www.nuget.org/api/v2" + $a | ?{ $_.name -eq "NugetTemp2" } + $a | ?{ $_.name -ne "NugetTemp1" } + } +} + +Describe Register-PackageSource -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + + it "EXPECTED: Register a package source with a location created via new-psdrive" { + New-PSDrive -Name xx -PSProvider FileSystem -Root $destination + (register-packagesource -name "psdriveTest" -provider $nuget -location xx:\).name | should be "psdriveTest" + (unregister-packagesource -name "psdriveTest" -provider $nuget) + } + + it "EXPECTED: Registers A New Package Source 'NugetTest.org'" { + (register-packagesource -name "nugettest.org" -provider $nuget -location $source).name | should be "nugettest.org" + try + { + # check that even without slash, source returned is still nugettest.org + (find-package -source $sourceWithoutSlash | Select -First 1).Source | should be "nugettest.org" + } + finally + { + (unregister-packagesource -name "nugettest.org" -provider $nuget) + } + } + + it "EXPECTED: Registers a package source that requires a credential with skipvalidate" { + (register-packagesource -name "psgettestfeed" -provider $nuget -location $vstsFeed -SKipValidate) + try { + (Find-Package -Source "psgettestfeed" -Name ContosoClient -Credential $vstsCredential).Name | should be "ContosoClient" + (Find-Package -Source $vstsFeed -Name ContosoClient -Credential $vstsCredential).Name | should be "ContosoClient" + (Find-Package -Source $vstsFeedWithSlash -Name ContosoClient -Credential $vstsCredential).Name | should be "ContosoClient" + } + finally + { + (Unregister-PackageSource -Name "psgettestfeed") + } + } + + + it "EXPECTED: Registers a package source that requires a credential" { + (register-packagesource -name "psgettestfeed" -provider $nuget -location $vstsFeed -Credential $vstsCredential) + try { + (Find-Package -Source "psgettestfeed" -Name ContosoClient -Credential $vstsCredential).Name | should be "ContosoClient" + (Find-Package -Source $vstsFeed -Name ContosoClient -Credential $vstsCredential).Name | should be "ContosoClient" + (Find-Package -Source $vstsFeedWithSlash -Name ContosoClient -Credential $vstsCredential).Name | should be "ContosoClient" + } + finally + { + (Unregister-PackageSource -Name "psgettestfeed") + } + } + + it "EXPECTED: PackageSource persists" { + $persist = "persistsource" + $pssource = "http://www.powershellgallery.com/api/v2/" + $redirectedOutput = "$env:tmp\nugettests\redirectedOutput.txt" + $redirectedError = "$env:tmp\nugettests\redirectedError.txt" + try { + Start-Process powershell -ArgumentList "register-packagesource -name $persist -location $pssource -provider $nuget" -wait + Start-Process powershell -ArgumentList "get-packagesource -name $persist -provider $nuget" -wait -RedirectStandardOutput $redirectedOutput -RedirectStandardError $redirectedError + (Test-Path $redirectedOutput) | should be $true + (Test-Path $redirectedError) | should be $true + $redirectedOutput | should contain $persist + [string]::IsNullOrWhiteSpace((Get-Content $redirectedError)) | should be $true + } + finally { + if (Test-Path $redirectedOutput) { + Remove-Item -Force $redirectedOutput -ErrorAction SilentlyContinue + } + + if (Test-Path $redirectedError) { + Remove-Item -Force $redirectedError -ErrorAction SilentlyContinue + } + Start-Process powershell -ArgumentList "unregister-packagesource -name $persist -provider $nuget" -Wait + } + } + + it "EXPECTED: Registers a fwlink package source and use it to find-package and install-package" { + try { + (register-packagesource -name "fwlink" -provider $nuget -location $fwlink).name | should be "fwlink" + (find-package -name "TestPackage" -source "fwlink" -provider $nuget).Name | should be "TestPackage" + (install-package -name "TestPackage" -provider $nuget -source $fwlink -Destination $Destination -force) + (Test-Path $destination\TestPackage*) | should be $true + } + finally { + if (Test-Path $destination\TestPackage*) { + Remove-Item -Recurse -Force $destination\TestPackage* + } + Unregister-PackageSource -Name "fwlink" -ProviderName $nuget -Force -ErrorAction SilentlyContinue + } + } + + it "EXPECTED: Registers an invalid package source" { + $msg = powershell "register-packagesource -name `"BingProvider`" -provider $nuget -location `"http://www.example.com/`" -erroraction silentlycontinue; `$Error[0].FullyQualifiedErrorId" + $msg | should be 'SourceLocationNotValid,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource' + } + + it "EXPECTED: Registers Multiple Package Sources" { + foreach ($x in $pkgSources) { + (register-packagesource -name $x -provider $nuget -location $source).name | should be $x + (unregister-packagesource -name $x -provider $nuget) + } + } + + it "EXPECTED: Registers A 'NugetTest' Package Source After Having The Provider Piped" { + (get-packageprovider -name $nuget | register-packagesource -name "nugettest" -location $source).ProviderName | should be $nuget + (unregister-packagesource -name "nugettest" -provider $nuget) + } +} + +Describe Unregister-PackageSource -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: Unregisters The 'NugetTest.org' Package Source" { + (register-packagesource -name "nugettest.org" -provider $nuget -location $source) + (Find-Package -name jquery -Source "nugettest.org").Name | should not BeNullOrEmpty + (unregister-packagesource -name "nugettest.org" -provider $nuget).name | should BeNullOrEmpty + (Find-Package -name jquery -Source "nugettest.org" -ErrorAction SilentlyContinue -WarningAction SilentlyContinue).Name | should BeNullOrEmpty + } + + it "EXPECTED: Unregisters Multiple Package Sources" { + foreach ($x in $pkgSources) { + (register-packagesource -name $x -provider $nuget -location $source) + (unregister-packagesource -name $x -provider $nuget).name | should BeNullOrEmpty + } + } + + it "EXPECTED: Unregisters A 'NugetTest' Package Source After Having The Provider Piped" { + (get-packageprovider -name $nuget | register-packagesource -name "nugettest" -location $source) + (unregister-packagesource -name "nugettest" -provider $nuget).name | should BeNullOrEmpty + } +} + +Describe Set-PackageSource -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: Sets The 'NugetTest' Package Source to 'NugetTest2'" { + (register-packagesource -name "nugettest" -provider $nuget -location "https://www.nuget.org/api/v2") + (set-packagesource -name "nugettest" -provider $nuget -location "https://www.nuget.org/api/v2" -newname "nugettest2" -newlocation "https://www.nuget.org/api/v2").name | should be "nugettest2" + (unregister-packagesource -name "nugettest2" -provider $nuget) + } + + it "EXPECTED: Set a package source that requires a credential" { + (register-packagesource -name "psgettestfeed" -provider $nuget -location $vstsFeed -Credential $vstsCredential) + try { + (Set-PackageSource -Name "psgettestfeed" -provider $nuget -NewName "psgettestfeed2" -Credential $vstsCredential) + (Get-PackageSource -Name "psgettestfeed2").Name | should match "psgettestfeed2" + } + finally + { + (Unregister-PackageSource -Name "psgettestfeed2") + } + } + + it "EXPECTED: Sets The 'NuGetTest' Package Source to 'NugetTest2' After Piping The Provider Then Piping The Entire Source" { + (get-packageprovider -name $nuget | register-packagesource -name "nugettest" -location "https://www.nuget.org/api/v2" | set-packagesource -newname "nugettest2" -newlocation "https://www.nuget.org/api/v2").name | should be "nugettest2" + (unregister-packagesource -name "nugettest2" -provider $nuget) + } + + it "EXPECTED: Sets Multiple Package Sources To New Names" { + (register-packagesource -name "nugettest" -provider $nuget -location "https://www.nuget.org/api/v2") + (set-packagesource -name "nugettest" -provider $nuget -location "https://www.nuget.org/api/v2" -newname "nugettest2" -newlocation "https://www.nuget.org/api/v2").name | should be "nugettest2" + (unregister-packagesource -name "nugettest2" -provider $nuget) + + (register-packagesource -name "nugettest3" -provider $nuget -location "https://www.nuget.org/api/v2") + (set-packagesource -name "nugettest3" -provider $nuget -location "https://www.nuget.org/api/v2" -newname "nugettest4" -newlocation "https://www.nuget.org/api/v2").name | should be "nugettest4" + (unregister-packagesource -name "nugettest4" -provider $nuget) + } + + it "EXPECTED: Sets the location of 'NugetTest' PackageSource from nuget.org to powershellgallery.com" { + (register-packagesource -name "nugettest5" -provider $nuget -location "https://www.nuget.org/api/v2") + (set-packagesource -name "nugettest5" -provider $nuget -newlocation "https://www.powershellgallery.com/api/v2/" -NewName "nugettest6").location | should be "https://www.powershellgallery.com/api/v2/" + (unregister-packagesource -name "nugettest6" -provider $nuget) + } +} + +Describe Check-ForCorrectError -Tags @('BVT', 'DRT'){ + # make sure that packagemanagement is loaded + import-packagemanagement + + it "EXPECTED: returns a correct error for find-package with dynamic parameter when package source is wrong" { + $Error.Clear() + $msg = powershell "find-package -provider $nuget -source http://wrongsource/api/v2 -FilterOnTag tag -ea silentlycontinue; `$Error[0].FullyQualifiedErrorId" + $msg | should be "SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage" + } + + it "EXPECTED: returns a correct error for install-package with dynamic parameter when package source is wrong" { + $Error.Clear() + $msg = powershell "install-package -provider $nuget -source http://wrongsource/api/v2 zlib -Destination C:\destination -ea silentlycontinue; `$Error[0].FullyQualifiedErrorId" + $msg | should be "SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" + } + +} + +Describe Test-Proxy -Tags @('BVT', 'DRT') { + # make sure that packagemanagent is loaded + import-packagemanagement + + It "EXPECTED: Register package source using proxy" { + try { + $processId = (Start-Process $proxyPath -PassThru).Id + (register-packagesource -name "nugettest7" -provider $nuget -location "https://www.nuget.org/api/v2" -Proxy http://localhost:8080).Name | should be "nugettest7" + (find-package -Name jquery -Source "nugettest7" -provider $nuget -Proxy http://localhost:8080).Name | should be "jQuery" + (install-package -Name jquery -Source "nugettest7" -provider $nuget -Proxy http://localhost:8080 -Force).Name | should be "jQuery" + } + finally { + Stop-Process $processId + unregister-packagesource -name "nugettest7" -provider $nuget -ErrorAction SilentlyContinue + } + } + + It "EXPECTED: Cannot register using wrong proxy" { + try { + $processId = (Start-Process $proxyPath -PassThru).Id + $packageSource = register-packagesource -name "nugettest7" -provider $nuget -location "https://www.nuget.org/api/v2" -Proxy http://localhost:8060 -ErrorAction SilentlyContinue + $packageSource | should be $null + } + finally { + Stop-Process $processId + unregister-packagesource -name "nugettest7" -provider $nuget -ErrorAction SilentlyContinue + } + } + + It "EXPECTED: Set package source using proxy" { + try { + $processId = (Start-Process $proxyPath -PassThru).Id + (register-packagesource -name "nugettest7" -provider $nuget -location "https://www.nuget.org/api/v2" -Proxy http://localhost:8080).Name | should be "nugettest7" + (set-packagesource -name "nugettest7" -provider $nuget -newlocation "https://www.powershellgallery.com/api/v2/" -Proxy http://localhost:8080).Location | should be "https://www.powershellgallery.com/api/v2/" + } + finally { + Stop-Process $processId + unregister-packagesource -name "nugettest7" -provider $nuget -ErrorAction SilentlyContinue + } + } + + It "EXPECTED: Cannot set package source using wrong proxy" { + try { + $processId = (Start-Process $proxyPath -PassThru).Id + (register-packagesource -name "nugettest7" -provider $nuget -location "https://www.nuget.org/api/v2" -Proxy http://localhost:8080).Name | should be "nugettest7" + $packageSource = set-packagesource -name "nugettest7" -provider $nuget -newlocation "https://www.powershellgallery.com/api/v2/" -Proxy http://localhost:8060 -ErrorAction SilentlyContinue + $packageSource | should be $null + } + finally { + Stop-Process $processId + unregister-packagesource -name "nugettest7" -provider $nuget -ErrorAction SilentlyContinue + } + } + + It "EXPECTED: cannot connect using the wrong proxy" { + try { + $processId = (Start-Process $proxyPath -PassThru).Id + $packages = Find-Package -Provider NuGet -Proxy http://localhost:8060 -ErrorAction SilentlyContinue + $packages | should be $null + } + finally { + Stop-Process $processId + } + } + + It "EXPECTED: cannot connect if the server is not on the list allowed by proxy" { + try { + $processId = (Start-Process $proxyPath -PassThru).Id + $packages = Find-Package -Provider NuGet -Proxy http://localhost:8080 -Source $dtlgallery -ErrorAction SilentlyContinue + $packages | should be $null + } + finally { + Stop-Process $processId + } + } + + It "EXPECTED: find packages using the correct proxy" { + try { + $processId = (Start-Process $proxyPath -PassThru).Id + $jquery = Find-Package -Provider NuGet -Proxy http://localhost:8080 -Source $source -Name jquery + + $jquery.Name | should match jquery + } + finally { + Stop-Process $processId + } + } + +} \ No newline at end of file