diff --git a/CHANGELOG.md b/CHANGELOG.md index 946e3ba96e..7db76c61ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Removed + +- SqlServerDsc.Common + - Removed the function `Get-RegistryPropertyValue` in favor of the command + with the same name in the module _DscResource.Common_. + ### Added - Public commands: diff --git a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1 b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1 index e73d52d1b3..059014ed05 100644 --- a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1 +++ b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psd1 @@ -21,7 +21,6 @@ # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = @( - 'Get-RegistryPropertyValue' 'Format-Path' 'Copy-ItemWithRobocopy' 'Invoke-InstallationMediaCopy' diff --git a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 index 12b01ce988..52d3779ddb 100644 --- a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 +++ b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 @@ -4,53 +4,6 @@ Import-Module -Name $script:resourceHelperModulePath $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' -<# - .SYNOPSIS - Returns the value of the provided Name parameter at the registry - location provided in the Path parameter. - - .PARAMETER Path - Specifies the path in the registry to the property name. - - .PARAMETER PropertyName - Specifies the the name of the property to return the value for. -#> -function Get-RegistryPropertyValue -{ - [CmdletBinding()] - [OutputType([System.String])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Path, - - [Parameter(Mandatory = $true)] - [System.String] - $Name - ) - - $getItemPropertyParameters = @{ - Path = $Path - Name = $Name - } - - <# - Using a try/catch block instead of 'SilentlyContinue' to be - able to unit test a failing registry path. - #> - try - { - $getItemPropertyResult = (Get-ItemProperty @getItemPropertyParameters -ErrorAction 'Stop').$Name - } - catch - { - $getItemPropertyResult = $null - } - - return $getItemPropertyResult -} - <# .SYNOPSIS Returns the value of the provided in the Name parameter, at the registry diff --git a/tests/Unit/SqlServerDsc.Common.Tests.ps1 b/tests/Unit/SqlServerDsc.Common.Tests.ps1 index 960bb8feef..f38e14e431 100644 --- a/tests/Unit/SqlServerDsc.Common.Tests.ps1 +++ b/tests/Unit/SqlServerDsc.Common.Tests.ps1 @@ -83,68 +83,6 @@ AfterAll { Get-Module -Name 'CommonTestHelper' -All | Remove-Module -Force } -Describe 'SqlServerDsc.Common\Get-RegistryPropertyValue' -Tag 'GetRegistryPropertyValue' { - BeforeAll { - $mockWrongRegistryPath = 'HKLM:\SOFTWARE\AnyPath' - $mockPropertyName = 'InstanceName' - $mockPropertyValue = 'AnyValue' - } - - Context 'When there are no property in the registry' { - BeforeAll { - Mock -CommandName Get-ItemProperty -MockWith { - return @{ - 'UnknownProperty' = $mockPropertyValue - } - } - } - - It 'Should return $null' { - $result = Get-RegistryPropertyValue -Path $mockWrongRegistryPath -Name $mockPropertyName - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It -Module $script:subModuleName - } - } - - Context 'When the call to Get-ItemProperty throws an error (i.e. when the path does not exist)' { - BeforeAll { - Mock -CommandName Get-ItemProperty -MockWith { - throw 'mocked error' - } - } - - It 'Should not throw an error, but return $null' { - $result = Get-RegistryPropertyValue -Path $mockWrongRegistryPath -Name $mockPropertyName - $result | Should -BeNullOrEmpty - - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It - } - } - - Context 'When there are a property in the registry' { - BeforeAll { - $mockCorrectRegistryPath = 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS' - - Mock -CommandName Get-ItemProperty -MockWith { - return @{ - $mockPropertyName = $mockPropertyValue - } - } -ParameterFilter { - $Path -eq $mockCorrectRegistryPath ` - -and $Name -eq $mockPropertyName - } - } - - It 'Should return the correct value' { - $result = Get-RegistryPropertyValue -Path $mockCorrectRegistryPath -Name $mockPropertyName - $result | Should -Be $mockPropertyValue - - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It - } - } -} - Describe 'SqlServerDsc.Common\Format-Path' -Tag 'FormatPath' { BeforeAll { $mockCorrectPath = 'C:\Correct\Path'