Skip to content

Commit

Permalink
[dsccommunity#864] Updated unit tests for SqlRS
Browse files Browse the repository at this point in the history
  • Loading branch information
bozho committed May 6, 2019
1 parent 1a7ed8f commit 6e71f79
Showing 1 changed file with 76 additions and 75 deletions.
151 changes: 76 additions & 75 deletions Tests/Unit/MSFT_SqlRS.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -532,105 +532,106 @@ try

Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-Sqlcmd -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It
}
}

Context 'When configuring a named instance that are already initialized, suppress restart' {
BeforeAll {
$mockDynamic_SqlBuildVersion = '13.0.4001.0'
$mockDynamicIsInitialized = $true
Context "When configuring a named instance that are already initialized ($($sqlVersion.VersionName)), suppress restart" {
BeforeAll {
$mockDynamicIsInitialized = $true

Mock -CommandName Get-TargetResource -MockWith {
return @{
ReportServerReservedUrl = $mockReportServerApplicationUrl
ReportsReservedUrl = $mockReportsApplicationUrl
Mock -CommandName Get-ReportingServicesData -MockWith {
return @{
Configuration = (& $mockGetCimInstance_ConfigurationSetting_NamedInstance)[0]
ReportsApplicationName = 'ReportServerWebApp'
SqlVersion = $sqlVersion.Version
}
}
}

Mock -CommandName Test-TargetResource -MockWith {
return $true
}
Mock -CommandName Get-TargetResource -MockWith {
return @{
ReportServerReservedUrl = $mockReportServerApplicationUrl
ReportsReservedUrl = $mockReportsApplicationUrl
}
}

$testParameters = @{
InstanceName = $mockNamedInstanceName
DatabaseServerName = $mockReportingServicesDatabaseServerName
DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName
ReportServerVirtualDirectory = 'ReportServer_NewName'
ReportsVirtualDirectory = 'Reports_NewName'
ReportServerReservedUrl = 'https://+:4443'
ReportsReservedUrl = 'https://+:4443'
UseSsl = $true
SuppressRestart = $true
Mock -CommandName Test-TargetResource -MockWith {
return $true
}

$testParameters = @{
InstanceName = $mockNamedInstanceName
DatabaseServerName = $mockReportingServicesDatabaseServerName
DatabaseInstanceName = $mockReportingServicesDatabaseNamedInstanceName
ReportServerVirtualDirectory = 'ReportServer_NewName'
ReportsVirtualDirectory = 'Reports_NewName'
ReportServerReservedUrl = 'https://+:4443'
ReportsReservedUrl = 'https://+:4443'
UseSsl = $true
SuppressRestart = $true
}
}
}

BeforeEach {
Mock -CommandName Get-CimInstance `
-MockWith $mockGetCimInstance_ConfigurationSetting_NamedInstance `
-ParameterFilter $mockGetCimInstance_ConfigurationSetting_ParameterFilter `
-Verifiable

Mock -CommandName Get-CimInstance `
-MockWith $mockGetCimInstance_Language `
-ParameterFilter $mockGetCimInstance_OperatingSystem_ParameterFilter `
-Verifiable
}
BeforeEach {
Mock -CommandName Get-CimInstance `
-MockWith $mockGetCimInstance_Language `
-ParameterFilter $mockGetCimInstance_OperatingSystem_ParameterFilter
}

It 'Should configure Reporting Service without throwing an error' {
{ Set-TargetResource @testParameters } | Should -Not -Throw
It 'Should configure Reporting Service without throwing an error' {
{ Set-TargetResource @testParameters } | Should -Not -Throw

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetSecureConnectionLevel'
} -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetSecureConnectionLevel'
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 2 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 2 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'InitializeReportServer'
} -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'InitializeReportServer'
} -Exactly -Times 0 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetDatabaseConnection'
} -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetDatabaseConnection'
} -Exactly -Times 0 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'GenerateDatabaseRightsScript'
} -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'GenerateDatabaseRightsScript'
} -Exactly -Times 0 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'GenerateDatabaseCreationScript'
} -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'GenerateDatabaseCreationScript'
} -Exactly -Times 0 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 1 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 2 -Scope It

Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 2 -Scope It

Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 2 -Scope It
Assert-MockCalled -CommandName Invoke-Sqlcmd -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-Sqlcmd -Exactly -Times 0 -Scope It
Assert-MockCalled -CommandName Restart-ReportingServicesService -Exactly -Times 0 -Scope It
}
}
}

Context "When configuring a default instance that are not initialized ($($sqlVersion.VersionName))" {
Context "When configuring a default instance that are not initialized ($($sqlVersion.VersionName))" {
BeforeAll {
$mockDynamicIsInitialized = $false

Expand Down

0 comments on commit 6e71f79

Please sign in to comment.