diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Registry.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Registry.Tests.ps1 index 60582002e31..cbcb0f47d40 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Registry.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Registry.Tests.ps1 @@ -13,6 +13,9 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows") $testKey2 = "TestKey2" $testPropertyName = "TestEntry" $testPropertyValue = 1 + $defaultPropertyName = "(Default)" + $defaultPropertyValue = "something" + $otherPropertyValue = "other" } } @@ -44,6 +47,34 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows") } Context "Validate basic registry provider Cmdlets" { + It "Verify Test-Path" { + Test-Path -IsValid Registry::HKCU/Software | Should Be $true + Test-Path -IsValid Registry::foo/Softare | Should Be $false + } + + It "Verify Get-Item" { + $item = Get-Item $testKey + $item.PSChildName | Should BeExactly $testKey + } + + It "Verify Get-Item on inaccessible path" { + { Get-Item HKLM:\SAM\SAM -ErrorAction Stop } | ShouldBeErrorId "System.Security.SecurityException,Microsoft.PowerShell.Commands.GetItemCommand" + } + + It "Verify Get-ChildItem" { + $items = Get-ChildItem + $items.Count | Should BeExactly 2 + $Items.PSChildName -contains $testKey | Should Be $true + $Items.PSChildName -contains $testKey2 | Should Be $true + } + + It "Verify Get-ChildItem can get subkey names" { + $items = Get-ChildItem -Name + $items.Count | Should BeExactly 2 + $items -contains $testKey | Should Be $true + $items -contains $testKey2 | Should Be $true + } + It "Verify New-Item" { $newKey = New-Item -Path "NewItemTest" Test-Path "NewItemTest" | Should Be $true @@ -87,6 +118,19 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows") $property."$testPropertyName" | Should Be 2 } + It "Verify Set-Item" { + Set-Item -Path $testKey -Value $defaultPropertyValue + $property = Get-ItemProperty -Path $testKey -Name $defaultPropertyName + $property."$defaultPropertyName" | Should BeExactly $defaultPropertyValue + } + + It "Verify Set-Item with -WhatIf" { + Set-Item -Path $testKey -Value $defaultPropertyValue + Set-Item -Path $testKey -Value $otherPropertyValue -WhatIf + $property = Get-ItemProperty -Path $testKey -Name $defaultPropertyName + $property."$defaultPropertyName" | Should BeExactly $defaultPropertyValue + } + It "Verify Get-ItemPropertyValue" { $propertyValue = Get-ItemPropertyValue -Path $testKey -Name $testPropertyName $propertyValue | Should Be $testPropertyValue @@ -125,6 +169,22 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows") $property."$testPropertyName" | Should Be 0 } + It "Verify Clear-Item" { + Set-ItemProperty -Path $testKey -Name $testPropertyName -Value $testPropertyValue + Set-Item -Path $testKey -Value $defaultPropertyValue + Clear-Item -Path $testKey + $key = Get-Item -Path $testKey + $key.Property.Length | Should BeExactly 0 + } + + It "Verify Clear-Item with -WhatIf" { + Set-ItemProperty -Path $testKey -Name $testPropertyName -Value $testPropertyValue + Set-Item -Path $testKey -Value $defaultPropertyValue + Clear-Item -Path $testKey -WhatIf + $key = Get-Item -Path $testKey + $key.Property.Length | Should BeExactly 2 + } + It "Verify Remove-ItemProperty" { Remove-ItemProperty -Path $testKey -Name $testPropertyName $properties = @(Get-ItemProperty -Path $testKey)