Skip to content

Commit 0396e38

Browse files
committed
Add parameter set validation tests for Get-SqlDscRSConfigurationSetting and improve error handling assertions
1 parent 059da4a commit 0396e38

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

tests/Unit/Public/Get-SqlDscRSConfigurationSetting.Tests.ps1

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ AfterAll {
4747
}
4848

4949
Describe 'Get-SqlDscRSConfigurationSetting' {
50+
Context 'When validating parameter sets' {
51+
It 'Should have the correct parameters in parameter set <ExpectedParameterSetName>' -ForEach @(
52+
@{
53+
ExpectedParameterSetName = '__AllParameterSets'
54+
ExpectedParameters = '[[-InstanceName] <string>] [<CommonParameters>]'
55+
}
56+
) {
57+
$result = (Get-Command -Name 'Get-SqlDscRSConfigurationSetting').ParameterSets |
58+
Where-Object -FilterScript { $_.Name -eq $ExpectedParameterSetName } |
59+
Select-Object -Property @(
60+
@{ Name = 'ParameterSetName'; Expression = { $_.Name } },
61+
@{ Name = 'ParameterListAsString'; Expression = { $_.ToString() } }
62+
)
63+
64+
$result.ParameterSetName | Should -Be $ExpectedParameterSetName
65+
$result.ParameterListAsString | Should -Be $ExpectedParameters
66+
}
67+
}
68+
5069
Context 'When getting all Reporting Services instances' {
5170
BeforeAll {
5271
# Mock setup configuration objects
@@ -142,9 +161,9 @@ Describe 'Get-SqlDscRSConfigurationSetting' {
142161
$ssrsResult.InstanceName | Should -Be 'SSRS'
143162
$ssrsResult.Version | Should -Be '15.0.1.0'
144163
$ssrsResult.PathName | Should -Be 'C:\Program Files\Microsoft SQL Server Reporting Services\SSRS'
145-
$ssrsResult.IsInitialized | Should -Be $true
164+
$ssrsResult.IsInitialized | Should -BeTrue
146165
$ssrsResult.ServiceAccount | Should -Be 'NT SERVICE\ReportServer'
147-
$ssrsResult.IsTlsConfigured | Should -Be $false
166+
$ssrsResult.IsTlsConfigured | Should -BeFalse
148167
$ssrsResult.WebServiceVirtualDirectory | Should -Be 'ReportServer'
149168
$ssrsResult.WebPortalVirtualDirectory | Should -Be 'Reports'
150169
$ssrsResult.WebPortalApplicationName | Should -Be 'ReportServerWebApp'
@@ -231,15 +250,8 @@ Describe 'Get-SqlDscRSConfigurationSetting' {
231250
}
232251

233252
It 'Should throw a terminating error when the currentVersion is null' {
234-
try
235-
{
236-
Get-SqlDscRSConfigurationSetting
237-
}
238-
catch
239-
{
240-
$_.CategoryInfo.Category | Should -Be 'InvalidOperation'
241-
$_.FullyQualifiedErrorId | Should -Be 'GSDCRSCS0001,Get-SqlDscRSConfigurationSetting'
242-
}
253+
{ Get-SqlDscRSConfigurationSetting } |
254+
Should -Throw -ErrorId 'GSDCRSCS0001,Get-SqlDscRSConfigurationSetting'
243255
}
244256
}
245257

@@ -256,15 +268,8 @@ Describe 'Get-SqlDscRSConfigurationSetting' {
256268
}
257269

258270
It 'Should throw a terminating error when the currentVersion is invalid' {
259-
try
260-
{
261-
Get-SqlDscRSConfigurationSetting
262-
}
263-
catch
264-
{
265-
$_.CategoryInfo.Category | Should -Be 'InvalidArgument'
266-
$_.FullyQualifiedErrorId | Should -Be 'GSDCRSCS0002,Get-SqlDscRSConfigurationSetting'
267-
}
271+
{ Get-SqlDscRSConfigurationSetting } |
272+
Should -Throw -ErrorId 'GSDCRSCS0002,Get-SqlDscRSConfigurationSetting'
268273
}
269274
}
270275

@@ -288,15 +293,8 @@ Describe 'Get-SqlDscRSConfigurationSetting' {
288293
}
289294

290295
It 'Should throw a terminating error when Get-CimInstance throws an error' {
291-
try
292-
{
293-
Get-SqlDscRSConfigurationSetting
294-
}
295-
catch
296-
{
297-
$_.CategoryInfo.Category | Should -Be 'InvalidOperation'
298-
$_.FullyQualifiedErrorId | Should -Be 'GSDCRSCS0003,Get-SqlDscRSConfigurationSetting'
299-
}
296+
{ Get-SqlDscRSConfigurationSetting } |
297+
Should -Throw -ErrorId 'GSDCRSCS0003,Get-SqlDscRSConfigurationSetting'
300298
}
301299
}
302300

@@ -352,7 +350,7 @@ Describe 'Get-SqlDscRSConfigurationSetting' {
352350
$result = Get-SqlDscRSConfigurationSetting
353351

354352
$result | Should -Not -BeNullOrEmpty
355-
$result[0].IsTlsConfigured | Should -Be $false
353+
$result[0].IsTlsConfigured | Should -BeFalse
356354
}
357355
}
358356

@@ -408,7 +406,7 @@ Describe 'Get-SqlDscRSConfigurationSetting' {
408406
$result = Get-SqlDscRSConfigurationSetting
409407

410408
$result | Should -Not -BeNullOrEmpty
411-
$result[0].IsTlsConfigured | Should -Be $true
409+
$result[0].IsTlsConfigured | Should -BeTrue
412410
}
413411
}
414412

0 commit comments

Comments
 (0)