Skip to content

Commit

Permalink
xSQLServerRSConfig: No longer returns a null value from Test-TargetRe…
Browse files Browse the repository at this point in the history
…source (#825)

- Changes to xSQLServerRSConfig
  - No longer returns a null value from Test-TargetResource when Reporting
    Services has not been initialized (issue #822).
  • Loading branch information
johlju committed Sep 20, 2017
1 parent fd76e7f commit 0be02ae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -74,6 +74,9 @@
- Added new resource xSQLServerAccount ([issue #706](https://github.com/PowerShell/xSQLServer/issues/706))
- Added localization support for all strings
- Added examples for usage
- Changes to xSQLServerRSConfig
- No longer returns a null value from Test-TargetResource when Reporting
Services has not been initialized ([issue #822](https://github.com/PowerShell/xSQLServer/issues/822)).

## 8.1.0.0

Expand Down
Expand Up @@ -54,6 +54,14 @@ function Get-TargetResource
}

$isInitialized = $reportingServicesConfiguration.IsInitialized
if (-not $isInitialized)
{
<#
Make sure the value returned is false, if the value returned was
either empty, $null or $false. Fic for issue #822.
#>
[System.Boolean] $isInitialized = $false
}
}
else
{
Expand Down
30 changes: 27 additions & 3 deletions Tests/Unit/MSFT_xSQLServerRSConfig.Tests.ps1
Expand Up @@ -50,7 +50,7 @@ try
$mockGetWmiObject_ConfigurationSetting_NamedInstance = {
return New-Object Object |
Add-Member -MemberType NoteProperty -Name 'DatabaseServerName' -Value "$mockReportingServicesDatabaseServerName\$mockReportingServicesDatabaseNamedInstanceName" -PassThru |
Add-Member -MemberType NoteProperty -Name 'IsInitialized' -Value $true -PassThru |
Add-Member -MemberType NoteProperty -Name 'IsInitialized' -Value $mockDynamicIsInitialized -PassThru |
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportServer' -Value '' -PassThru |
Add-Member -MemberType NoteProperty -Name 'VirtualDirectoryReportManager' -Value '' -PassThru |
Add-Member -MemberType ScriptMethod -Name SetVirtualDirectory {
Expand Down Expand Up @@ -92,7 +92,7 @@ try
$mockGetWmiObject_ConfigurationSetting_DefaultInstance = {
return @{
DatabaseServerName = $mockReportingServicesDatabaseServerName
IsInitialized = $false
IsInitialized = $mockDynamicIsInitialized
}
}

Expand Down Expand Up @@ -131,6 +131,8 @@ try
-Verifiable
}

$mockDynamicIsInitialized = $true

It 'Should return the same values as passed as parameters' {
$resultGetTargetResource = Get-TargetResource @testParameters
$resultGetTargetResource.InstanceName | Should Be $mockNamedInstanceName
Expand All @@ -153,6 +155,8 @@ try
-Verifiable
}

$mockDynamicIsInitialized = $false

It 'Should return the same values as passed as parameters' {
$resultGetTargetResource = Get-TargetResource @testParameters
$resultGetTargetResource.InstanceName | Should Be $mockNamedInstanceName
Expand All @@ -161,11 +165,31 @@ try
$resultGetTargetResource | Should BeOfType [System.Collections.Hashtable]
}

It 'Should return the the state as initialized' {
It 'Should return the state as not initialized' {
$resultGetTargetResource = Get-TargetResource @testParameters
$resultGetTargetResource.IsInitialized | Should Be $false
}

# Regression test for issue #822.
Context 'When Reporting Services has not been initialized (IsInitialized returns $null)' {
$mockDynamicIsInitialized = $null

It 'Should return the state as not initialized' {
$resultGetTargetResource = Get-TargetResource @testParameters
$resultGetTargetResource.IsInitialized | Should Be $false
}
}

# Regression test for issue #822.
Context 'When Reporting Services has not been initialized (IsInitialized returns empty string)' {
$mockDynamicIsInitialized = ''

It 'Should return the state as not initialized' {
$resultGetTargetResource = Get-TargetResource @testParameters
$resultGetTargetResource.IsInitialized | Should Be $false
}
}

Context 'When there is no Reporting Services instance' {
BeforeEach {
Mock -CommandName Get-ItemProperty
Expand Down

0 comments on commit 0be02ae

Please sign in to comment.