Skip to content

Commit db0af12

Browse files
committed
Refactor Get-SqlDscRSDatabaseInstallation to check result length and update related tests
1 parent 537f663 commit db0af12

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

source/Public/Get-SqlDscRSDatabaseInstallation.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ function Get-SqlDscRSDatabaseInstallation
7777
$result = Invoke-RsCimMethod @invokeRsCimMethodParameters -ErrorAction 'Stop'
7878

7979
<#
80-
The WMI method returns multiple parallel arrays:
80+
The WMI method returns:
81+
- Length: Number of entries in the arrays
8182
- InstallationID: Array of installation IDs
8283
- MachineName: Array of machine names
8384
- InstanceName: Array of instance names
8485
- IsInitialized: Array of initialization states
8586
#>
86-
if ($result.InstallationID)
87+
if ($result.Length -gt 0)
8788
{
88-
for ($i = 0; $i -lt $result.InstallationID.Count; $i++)
89+
for ($i = 0; $i -lt $result.Length; $i++)
8990
{
9091
[PSCustomObject] @{
9192
InstallationID = $result.InstallationID[$i]

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ Describe 'Get-SqlDscRSDatabaseInstallation' {
7171

7272
Mock -CommandName Invoke-RsCimMethod -MockWith {
7373
return @{
74+
Length = 2
7475
InstallationID = @('GUID1', 'GUID2')
75-
MachineName = @('SERVER1', 'SERVER2')
76-
InstanceName = @('SSRS', 'SSRS')
77-
IsInitialized = @($true, $true)
76+
MachineName = @('SERVER1', 'SERVER2')
77+
InstanceName = @('SSRS', 'SSRS')
78+
IsInitialized = @($true, $true)
7879
}
7980
}
8081
}
@@ -103,10 +104,11 @@ Describe 'Get-SqlDscRSDatabaseInstallation' {
103104

104105
Mock -CommandName Invoke-RsCimMethod -MockWith {
105106
return @{
107+
Length = 0
106108
InstallationID = @()
107-
MachineName = @()
108-
InstanceName = @()
109-
IsInitialized = @()
109+
MachineName = @()
110+
InstanceName = @()
111+
IsInitialized = @()
110112
}
111113
}
112114
}
@@ -144,10 +146,11 @@ Describe 'Get-SqlDscRSDatabaseInstallation' {
144146

145147
Mock -CommandName Invoke-RsCimMethod -MockWith {
146148
return @{
149+
Length = 1
147150
InstallationID = @('GUID1')
148-
MachineName = @('SERVER1')
149-
InstanceName = @('SSRS')
150-
IsInitialized = @($true)
151+
MachineName = @('SERVER1')
152+
InstanceName = @('SSRS')
153+
IsInitialized = @($true)
151154
}
152155
}
153156
}

0 commit comments

Comments
 (0)