Skip to content

Commit f27f342

Browse files
committed
Add PassThru support to error handling in Enable/Disable-SqlDscRsSecureConnection functions and enhance parameter set validation in tests
1 parent effaf3e commit f27f342

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

source/Public/Disable-SqlDscRsSecureConnection.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function Disable-SqlDscRsSecureConnection
123123
{
124124
$errorMessage = $script:localizedData.Disable_SqlDscRsSecureConnection_FailedToDisable -f $instanceName, $_.Exception.Message
125125

126-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage) -ErrorId 'DSRSSC0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
126+
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'DSRSSC0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
127127

128128
$PSCmdlet.ThrowTerminatingError($errorRecord)
129129
}

source/Public/Enable-SqlDscRsSecureConnection.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function Enable-SqlDscRsSecureConnection
127127
{
128128
$errorMessage = $script:localizedData.Enable_SqlDscRsSecureConnection_FailedToEnable -f $instanceName, $_.Exception.Message
129129

130-
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage) -ErrorId 'ESRSSC0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
130+
$errorRecord = New-ErrorRecord -Exception (New-InvalidOperationException -Message $errorMessage -PassThru) -ErrorId 'ESRSSC0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
131131

132132
$PSCmdlet.ThrowTerminatingError($errorRecord)
133133
}

tests/Unit/Public/Disable-SqlDscRsSecureConnection.Tests.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ Describe 'Disable-SqlDscRsSecureConnection' {
7979
}
8080
}
8181

82+
Context 'When validating parameter sets' {
83+
It 'Should have the correct parameters in parameter set <ExpectedParameterSetName>' -ForEach @(
84+
@{
85+
ExpectedParameterSetName = '__AllParameterSets'
86+
ExpectedParameters = '[-Configuration] <Object> [-PassThru] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]'
87+
}
88+
) {
89+
$result = (Get-Command -Name 'Disable-SqlDscRsSecureConnection').ParameterSets |
90+
Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } |
91+
Select-Object -Property @(
92+
@{ Name = 'ParameterSetName'; Expression = { $_.Name } },
93+
@{ Name = 'ParameterListAsString'; Expression = { $_.ToString() } }
94+
)
95+
96+
$result.ParameterSetName | Should -Be $ExpectedParameterSetName
97+
$result.ParameterListAsString | Should -Be $ExpectedParameters
98+
}
99+
}
100+
82101
Context 'When disabling secure connection successfully' {
83102
BeforeAll {
84103
$mockCimInstance = [PSCustomObject] @{

tests/Unit/Public/Enable-SqlDscRsSecureConnection.Tests.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ Describe 'Enable-SqlDscRsSecureConnection' {
7979
}
8080
}
8181

82+
Context 'When validating parameter sets' {
83+
It 'Should have the correct parameters in parameter set <ExpectedParameterSetName>' -ForEach @(
84+
@{
85+
ExpectedParameterSetName = '__AllParameterSets'
86+
ExpectedParameters = '[-Configuration] <Object> [-PassThru] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]'
87+
}
88+
) {
89+
$result = (Get-Command -Name 'Enable-SqlDscRsSecureConnection').ParameterSets |
90+
Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } |
91+
Select-Object -Property @(
92+
@{ Name = 'ParameterSetName'; Expression = { $_.Name } },
93+
@{ Name = 'ParameterListAsString'; Expression = { $_.ToString() } }
94+
)
95+
96+
$result.ParameterSetName | Should -Be $ExpectedParameterSetName
97+
$result.ParameterListAsString | Should -Be $ExpectedParameters
98+
}
99+
}
100+
82101
Context 'When enabling secure connection successfully' {
83102
BeforeAll {
84103
$mockCimInstance = [PSCustomObject] @{

0 commit comments

Comments
 (0)