@@ -13,6 +13,9 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows") |
13 | 13 | $testKey2 = "TestKey2" |
14 | 14 | $testPropertyName = "TestEntry" |
15 | 15 | $testPropertyValue = 1 |
| 16 | + $defaultPropertyName = "(Default)" |
| 17 | + $defaultPropertyValue = "something" |
| 18 | + $otherPropertyValue = "other" |
16 | 19 | } |
17 | 20 | } |
18 | 21 |
|
@@ -44,6 +47,34 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows") |
44 | 47 | } |
45 | 48 |
|
46 | 49 | Context "Validate basic registry provider Cmdlets" { |
| 50 | + It "Verify Test-Path" { |
| 51 | + Test-Path -IsValid Registry::HKCU/Software | Should Be $true |
| 52 | + Test-Path -IsValid Registry::foo/Softare | Should Be $false |
| 53 | + } |
| 54 | + |
| 55 | + It "Verify Get-Item" { |
| 56 | + $item = Get-Item $testKey |
| 57 | + $item.PSChildName | Should BeExactly $testKey |
| 58 | + } |
| 59 | + |
| 60 | + It "Verify Get-Item on inaccessible path" { |
| 61 | + { Get-Item HKLM:\SAM\SAM -ErrorAction Stop } | ShouldBeErrorId "System.Security.SecurityException,Microsoft.PowerShell.Commands.GetItemCommand" |
| 62 | + } |
| 63 | + |
| 64 | + It "Verify Get-ChildItem" { |
| 65 | + $items = Get-ChildItem |
| 66 | + $items.Count | Should BeExactly 2 |
| 67 | + $Items.PSChildName -contains $testKey | Should Be $true |
| 68 | + $Items.PSChildName -contains $testKey2 | Should Be $true |
| 69 | + } |
| 70 | + |
| 71 | + It "Verify Get-ChildItem can get subkey names" { |
| 72 | + $items = Get-ChildItem -Name |
| 73 | + $items.Count | Should BeExactly 2 |
| 74 | + $items -contains $testKey | Should Be $true |
| 75 | + $items -contains $testKey2 | Should Be $true |
| 76 | + } |
| 77 | + |
47 | 78 | It "Verify New-Item" { |
48 | 79 | $newKey = New-Item -Path "NewItemTest" |
49 | 80 | Test-Path "NewItemTest" | Should Be $true |
@@ -87,6 +118,19 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows") |
87 | 118 | $property."$testPropertyName" | Should Be 2 |
88 | 119 | } |
89 | 120 |
|
| 121 | + It "Verify Set-Item" { |
| 122 | + Set-Item -Path $testKey -Value $defaultPropertyValue |
| 123 | + $property = Get-ItemProperty -Path $testKey -Name $defaultPropertyName |
| 124 | + $property."$defaultPropertyName" | Should BeExactly $defaultPropertyValue |
| 125 | + } |
| 126 | + |
| 127 | + It "Verify Set-Item with -WhatIf" { |
| 128 | + Set-Item -Path $testKey -Value $defaultPropertyValue |
| 129 | + Set-Item -Path $testKey -Value $otherPropertyValue -WhatIf |
| 130 | + $property = Get-ItemProperty -Path $testKey -Name $defaultPropertyName |
| 131 | + $property."$defaultPropertyName" | Should BeExactly $defaultPropertyValue |
| 132 | + } |
| 133 | + |
90 | 134 | It "Verify Get-ItemPropertyValue" { |
91 | 135 | $propertyValue = Get-ItemPropertyValue -Path $testKey -Name $testPropertyName |
92 | 136 | $propertyValue | Should Be $testPropertyValue |
@@ -125,6 +169,22 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows") |
125 | 169 | $property."$testPropertyName" | Should Be 0 |
126 | 170 | } |
127 | 171 |
|
| 172 | + It "Verify Clear-Item" { |
| 173 | + Set-ItemProperty -Path $testKey -Name $testPropertyName -Value $testPropertyValue |
| 174 | + Set-Item -Path $testKey -Value $defaultPropertyValue |
| 175 | + Clear-Item -Path $testKey |
| 176 | + $key = Get-Item -Path $testKey |
| 177 | + $key.Property.Length | Should BeExactly 0 |
| 178 | + } |
| 179 | + |
| 180 | + It "Verify Clear-Item with -WhatIf" { |
| 181 | + Set-ItemProperty -Path $testKey -Name $testPropertyName -Value $testPropertyValue |
| 182 | + Set-Item -Path $testKey -Value $defaultPropertyValue |
| 183 | + Clear-Item -Path $testKey -WhatIf |
| 184 | + $key = Get-Item -Path $testKey |
| 185 | + $key.Property.Length | Should BeExactly 2 |
| 186 | + } |
| 187 | + |
128 | 188 | It "Verify Remove-ItemProperty" { |
129 | 189 | Remove-ItemProperty -Path $testKey -Name $testPropertyName |
130 | 190 | $properties = @(Get-ItemProperty -Path $testKey) |
|