Skip to content

Commit f61cb14

Browse files
committed
Fix unit test
1 parent 16d7a88 commit f61cb14

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

source/Classes/020.SqlRSSetup.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ class SqlRSSetup : ResourceBase
292292
$this.localizedData.Instance_Installed -f $properties.InstanceName
293293
)
294294

295+
$currentState.InstanceName = $rsConfiguration.InstanceName
295296
$currentState.InstallFolder = $rsConfiguration.InstallFolder
296297
$currentState.ProductVersion = $rsConfiguration.ProductVersion
297298
}

tests/Unit/Classes/SqlRSSetup.Tests.ps1

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,71 @@ Describe 'SqlRSSetup\Set()' -Tag 'Set' {
333333
}
334334
}
335335
}
336+
337+
Describe 'SqlRSSetup\GetCurrentState()' -Tag 'GetCurrentState' {
338+
Context 'When current state is missing SSRS instance' {
339+
BeforeAll {
340+
InModuleScope -ScriptBlock {
341+
$script:mockSqlRSSetupInstance = [SqlRSSetup] @{
342+
InstanceName = 'SSRS'
343+
} |
344+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetServerObject' -Value {
345+
return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server'
346+
} -PassThru
347+
}
348+
349+
Mock -CommandName Get-SqlDscRSSetupConfiguration
350+
}
351+
352+
It 'Should return the correct values' {
353+
InModuleScope -ScriptBlock {
354+
$currentState = $script:mockSqlRSSetupInstance.GetCurrentState(
355+
@{
356+
Name = 'InstanceName'
357+
InstanceName = 'SSRS'
358+
}
359+
)
360+
361+
$currentState.InstanceName | Should -BeNullOrEmpty
362+
}
363+
}
364+
}
365+
366+
Context 'When current state have an SSRS instance' {
367+
BeforeAll {
368+
InModuleScope -ScriptBlock {
369+
$script:mockSqlRSSetupInstance = [SqlRSSetup] @{
370+
InstanceName = 'SSRS'
371+
} |
372+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetServerObject' -Value {
373+
return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server'
374+
} -PassThru
375+
}
376+
377+
Mock -CommandName Get-SqlDscRSSetupConfiguration -MockWith {
378+
return @(
379+
[PSCustomObject] @{
380+
InstanceName = 'SSRS'
381+
InstallFolder = 'C:\Program Files\SSRS'
382+
ProductVersion = '15.0.2000.5'
383+
}
384+
)
385+
}
386+
}
387+
388+
It 'Should return the correct values' {
389+
InModuleScope -ScriptBlock {
390+
$currentState = $script:mockSqlRSSetupInstance.GetCurrentState(
391+
@{
392+
Name = 'InstanceName'
393+
InstanceName = 'SSRS'
394+
}
395+
)
396+
397+
$currentState.InstanceName | Should -Be 'SSRS'
398+
$currentState.ProductVersion | Should -Be '15.0.2000.5'
399+
$currentState.InstallFolder | Should -Be 'C:\Program Files\SSRS'
400+
}
401+
}
402+
}
403+
}

0 commit comments

Comments
 (0)