GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add test coverage for Registry (#4354) · Thatgfsj-contribs/PowerShell@c3c5f46

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/powershell/Modules/Microsoft.PowerShell.Management
    • Registry.Tests.ps1
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/powershell/Modules/Microsoft.PowerShell.Management/Registry.Tests.ps1‎

Copy file name to clipboardExpand all lines: test/powershell/Modules/Microsoft.PowerShell.Management/Registry.Tests.ps1
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows")
1313
$testKey2 = "TestKey2"
1414
$testPropertyName = "TestEntry"
1515
$testPropertyValue = 1
16+
$defaultPropertyName = "(Default)"
17+
$defaultPropertyValue = "something"
18+
$otherPropertyValue = "other"
1619
}
1720
}
1821

@@ -44,6 +47,34 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows")
4447
}
4548

4649
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+
4778
It "Verify New-Item" {
4879
$newKey = New-Item -Path "NewItemTest"
4980
Test-Path "NewItemTest" | Should Be $true
@@ -87,6 +118,19 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows")
87118
$property."$testPropertyName" | Should Be 2
88119
}
89120

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+
90134
It "Verify Get-ItemPropertyValue" {
91135
$propertyValue = Get-ItemPropertyValue -Path $testKey -Name $testPropertyName
92136
$propertyValue | Should Be $testPropertyValue
@@ -125,6 +169,22 @@ Describe "Basic Registry Provider Tests" -Tags @("CI", "RequireAdminOnWindows")
125169
$property."$testPropertyName" | Should Be 0
126170
}
127171

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+
128188
It "Verify Remove-ItemProperty" {
129189
Remove-ItemProperty -Path $testKey -Name $testPropertyName
130190
$properties = @(Get-ItemProperty -Path $testKey)

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.