@@ -221,6 +221,16 @@ Describe "PSResourceList Resource Tests" -Tags 'CI' {
221221 return
222222 }
223223
224+ # Remove test modules installed through DSC so they do not leak into later runs.
225+ foreach ($moduleToRemove in @ ($script :testModuleName , $script :testModuleName2 )) {
226+ $cleanupInput = @ {
227+ repositoryName = $script :localRepo
228+ trustedRepository = $true
229+ resources = @ (@ { name = $moduleToRemove ; _exist = $false })
230+ } | ConvertTo-Json - Depth 5
231+ $null = & $script :dscExe resource set -- resource Microsoft.PowerShell.PSResourceGet/ PSResourceList -- input $cleanupInput - o json 2>&1
232+ }
233+
224234 # Clean up the test repository
225235 Get-RevertPSResourceRepositoryFile
226236 }
@@ -373,9 +383,19 @@ Describe "PSResourceList Resource Tests" -Tags 'CI' {
373383
374384 It ' Get returns actual installed version with _exist false when installed version does not satisfy requested version' {
375385 # Install 1.0.0 but request 5.0.0 - get should report _exist = false (requested version absent)
376- # but still surface the actually installed version (1.0.0)
377- Install-PSResource - Name $script :testModuleName - Version ' 1.0.0' - Repository $script :localRepo - Reinstall - TrustRepository - ErrorAction SilentlyContinue
378- Uninstall-PSResource - Name $script :testModuleName - Version ' 5.0.0' - ErrorAction SilentlyContinue
386+ $removeAllInput = @ {
387+ repositoryName = $script :localRepo
388+ trustedRepository = $true
389+ resources = @ (@ { name = $script :testModuleName ; _exist = $false })
390+ } | ConvertTo-Json - Depth 5
391+ $null = & $script :dscExe resource set -- resource Microsoft.PowerShell.PSResourceGet/ PSResourceList -- input $removeAllInput - o json
392+
393+ $installOldInput = @ {
394+ repositoryName = $script :localRepo
395+ trustedRepository = $true
396+ resources = @ (@ { name = $script :testModuleName ; version = ' 1.0.0' })
397+ } | ConvertTo-Json - Depth 5
398+ $null = & $script :dscExe resource set -- resource Microsoft.PowerShell.PSResourceGet/ PSResourceList -- input $installOldInput - o json
379399
380400 $psResourceListParams = @ {
381401 repositoryName = $script :localRepo
@@ -396,9 +416,16 @@ Describe "PSResourceList Resource Tests" -Tags 'CI' {
396416 }
397417
398418 It ' Get prefers installed version that satisfies requested version range when multiple versions are installed' {
399- # Install both 1.0.0 and 5.0.0 but request 5.0.0 - get should prefer the satisfying version (5.0.0)
400- Install-PSResource - Name $script :testModuleName - Version ' 1.0.0' - Repository $script :localRepo - Reinstall - TrustRepository - ErrorAction SilentlyContinue
401- Install-PSResource - Name $script :testModuleName - Version ' 5.0.0' - Repository $script :localRepo - Reinstall - TrustRepository - ErrorAction SilentlyContinue
419+ # Install both 1.0.0 and 5.0.0 but request 5.0.0 - get should prefer the satisfying version (5.0.0).
420+ # Setup goes through DSC for the same reason as the previous test.
421+ foreach ($setupVersion in @ (' 1.0.0' , ' 5.0.0' )) {
422+ $installInput = @ {
423+ repositoryName = $script :localRepo
424+ trustedRepository = $true
425+ resources = @ (@ { name = $script :testModuleName ; version = $setupVersion })
426+ } | ConvertTo-Json - Depth 5
427+ $null = & $script :dscExe resource set -- resource Microsoft.PowerShell.PSResourceGet/ PSResourceList -- input $installInput - o json
428+ }
402429
403430 $psResourceListParams = @ {
404431 repositoryName = $script :localRepo
0 commit comments