55Import-Module " $PSScriptRoot \PSGetTestUtils.psm1" - WarningAction SilentlyContinue
66
77$RepositoryName = ' PSGallery'
8- $SourceLocation = ' https://www.poshtestgallery.com/api/v2/'
9- $PublishLocation = ' https://www.poshtestgallery.com/api/v2/package/'
10- $ScriptSourceLocation = ' https://www.poshtestgallery.com/api/v2/items/psscript/'
11- $ScriptPublishLocation = ' https://www.poshtestgallery.com/api/v2/package/'
8+ $SourceLocation = ' https://www.poshtestgallery.com/api/v2'
9+ $SourceLocation2 = ' https://www.poshtestgallery.com/api/v2/'
10+ $PublishLocation = ' https://www.poshtestgallery.com/api/v2/package'
11+ $ScriptSourceLocation = ' https://www.poshtestgallery.com/api/v2/items/psscript'
12+ $ScriptPublishLocation = ' https://www.poshtestgallery.com/api/v2/package'
1213$TestRepositoryName = ' PSTestGallery'
1314
1415Describe ' Test Register-PSRepository and Register-PackageSource for PSGallery repository' - tags ' BVT' , ' InnerLoop' {
1516
1617 BeforeAll {
1718 Install-NuGetBinaries
19+ Get-PSRepository |
20+ Where-Object - Property SourceLocation -eq $SourceLocation2 |
21+ Unregister-PSRepository
22+
23+ $nugetCmd = Microsoft.PowerShell.Core\Get-Command - Name ' NuGet.exe' `
24+ - ErrorAction SilentlyContinue - WarningAction SilentlyContinue
1825 }
1926
2027 AfterAll {
@@ -30,6 +37,16 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
3037 Unregister-PSRepository - Name $RepositoryName - ErrorAction SilentlyContinue
3138 }
3239
40+ It ' Should add and remove nuget source when -PackageMangementProvider is set to Nuget' {
41+ Register-PSRepository - Name $TestRepositoryName - SourceLocation $SourceLocation - PackageManagementProvider Nuget
42+ $nugetSourceExists = nuget sources list | where-object { $_.Trim () -in $SourceLocation }
43+ $nugetSourceExists | should be $true
44+
45+ unregister-PSRepository - Name $TestRepositoryName
46+ $nugetSourceExists = nuget sources list | where-object { $_.Trim () -in $SourceLocation }
47+ $nugetSourceExists | should be $null
48+ } - Skip:$ (! $nugetCmd )
49+
3350 It ' Should pipe from Get-PSRepository to Set' {
3451 Register-PSRepository - Default
3552
@@ -72,10 +89,12 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
7289 $repo = Get-PSRepository - Name ' Test Repo'
7390 $repo.Name | should be ' Test Repo'
7491 $repo.SourceLocation | should be $tmpdir
75- } finally {
92+ }
93+ finally {
7694 Unregister-PSRepository - Name ' Test Repo' - ErrorAction SilentlyContinue
7795 }
78- } finally {
96+ }
97+ finally {
7998 Remove-Item - LiteralPath $tmpdir - Force - Recurse
8099 }
81100 }
@@ -99,7 +118,7 @@ Describe 'Test Register-PSRepository and Register-PackageSource for PSGallery re
99118 }
100119
101120 It ' Register-PSRepository -Name PSGallery -SourceLocation $SourceLocation -PublishLocation $PublishLocation : Should fail' {
102- { Register-PSRepository $RepositoryName $SourceLocation - PublishLocation $PublishLocation - ErrorVariable ev - ErrorAction SilentlyContinue } | Should Throw
121+ { Register-PSRepository $RepositoryName $SourceLocation - PublishLocation $PublishLocation - ErrorVariable ev - ErrorAction SilentlyContinue } | Should Throw
103122 }
104123
105124 It ' Register-PSRepository -Name PSGallery -SourceLocation $SourceLocation -ScriptPublishLocation $ScriptPublishLocation : Should fail' {
@@ -256,8 +275,8 @@ Describe 'Test Register-PSRepository for PSTestGallery repository' -tags 'BVT',
256275 BeforeAll {
257276 Install-NuGetBinaries
258277 Get-PSRepository |
259- Where-Object - Property SourceLocation -eq $SourceLocation |
260- Unregister-PSRepository
278+ Where-Object - Property SourceLocation -eq $SourceLocation |
279+ Unregister-PSRepository
261280 }
262281
263282 BeforeEach {
@@ -272,17 +291,17 @@ Describe 'Test Register-PSRepository for PSTestGallery repository' -tags 'BVT',
272291 $paramRegisterPSRepository = @ {
273292 Name = $TestRepositoryName
274293 SourceLocation = $SourceLocation
275- PublishLocation = $SourceLocation
276- ScriptSourceLocation = $SourceLocation
277- ScriptPublishLocation = $SourceLocation
294+ PublishLocation = $PublishLocation
295+ ScriptSourceLocation = $ScriptSourceLocation
296+ ScriptPublishLocation = $ScriptPublishLocation
278297 }
279298
280299 { Register-PSRepository @paramRegisterPSRepository } | Should not Throw
281300 $repo = Get-PSRepository - Name $TestRepositoryName
282301 $repo.SourceLocation | Should be $SourceLocation
283- $repo.ScriptSourceLocation | Should be $SourceLocation
284- $repo.PublishLocation | Should be $SourceLocation
285- $repo.ScriptPublishLocation | Should be $SourceLocation
302+ $repo.ScriptSourceLocation | Should be $ScriptSourceLocation
303+ $repo.PublishLocation | Should be $PublishLocation
304+ $repo.ScriptPublishLocation | Should be $ScriptPublishLocation
286305 }
287306}
288307
@@ -291,8 +310,8 @@ Describe 'Test Set-PSRepository for PSTestGallery repository' -tags 'BVT', 'Inne
291310 BeforeAll {
292311 Install-NuGetBinaries
293312 Get-PSRepository |
294- Where-Object - Property SourceLocation -eq $SourceLocation |
295- Unregister-PSRepository
313+ Where-Object - Property SourceLocation -eq $SourceLocation |
314+ Unregister-PSRepository
296315 }
297316
298317 BeforeEach {
@@ -312,22 +331,22 @@ Describe 'Test Set-PSRepository for PSTestGallery repository' -tags 'BVT', 'Inne
312331 ScriptPublishLocation = $ScriptPublishLocation
313332 }
314333
315- Register-PSRepository @paramRegisterPSRepository
334+ Register-PSRepository @paramRegisterPSRepository - ErrorAction SilentlyContinue
316335
317336 $paramSetPSRepository = @ {
318337 Name = $TestRepositoryName
319338 SourceLocation = $SourceLocation
320- PublishLocation = $SourceLocation
321- ScriptSourceLocation = $SourceLocation
322- ScriptPublishLocation = $SourceLocation
339+ PublishLocation = $PublishLocation
340+ ScriptSourceLocation = $ScriptSourceLocation
341+ ScriptPublishLocation = $ScriptPublishLocation
323342 }
324343
325344 { Set-PSRepository @paramSetPSRepository } | Should not Throw
326345
327346 $repo = Get-PSRepository - Name $TestRepositoryName
328347 $repo.SourceLocation | Should be $SourceLocation
329- $repo.ScriptSourceLocation | Should be $SourceLocation
330- $repo.PublishLocation | Should be $SourceLocation
331- $repo.ScriptPublishLocation | Should be $SourceLocation
348+ $repo.ScriptSourceLocation | Should be $ScriptSourceLocation
349+ $repo.PublishLocation | Should be $PublishLocation
350+ $repo.ScriptPublishLocation | Should be $ScriptPublishLocation
332351 }
333352}
0 commit comments