Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
47 changes: 0 additions & 47 deletions source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 0 additions & 62 deletions tests/Unit/SqlServerDsc.Common.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down