Skip to content

Commit 16d7a88

Browse files
committed
Fix unit test
1 parent 33c8402 commit 16d7a88

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

tests/Unit/Classes/SqlRSSetup.Tests.ps1

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,78 @@ Describe 'SqlRSSetup\Test()' -Tag 'Test' {
258258
}
259259
}
260260
}
261+
262+
Describe 'SqlRSSetup\Set()' -Tag 'Set' {
263+
BeforeAll {
264+
InModuleScope -ScriptBlock {
265+
$script:mockSqlRSSetupInstance = [SqlRSSetup] @{
266+
InstanceName = 'SSRS'
267+
Edition = 'Developer'
268+
Action = 'Install'
269+
} |
270+
# Mock method Modify which is called by the base method Set().
271+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Modify' -Value {
272+
$script:mockMethodModifyCallCount += 1
273+
} -PassThru
274+
}
275+
}
276+
277+
BeforeEach {
278+
InModuleScope -ScriptBlock {
279+
$script:mockMethodModifyCallCount = 0
280+
}
281+
}
282+
283+
Context 'When the system is in the desired state' {
284+
BeforeAll {
285+
InModuleScope -ScriptBlock {
286+
$script:mockSqlRSSetupInstance |
287+
# Mock method Compare() which is called by the base method Set()
288+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
289+
return $null
290+
} -PassThru |
291+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
292+
return
293+
} -PassThru |
294+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
295+
return
296+
}
297+
}
298+
}
299+
300+
It 'Should not call method Modify()' {
301+
InModuleScope -ScriptBlock {
302+
$script:mockSqlRSSetupInstance.Set()
303+
304+
$script:mockMethodModifyCallCount | Should -Be 0
305+
}
306+
}
307+
}
308+
309+
Context 'When the system is not in the desired state' {
310+
BeforeAll {
311+
InModuleScope -ScriptBlock {
312+
$script:mockSqlRSSetupInstance |
313+
# Mock method Compare() which is called by the base method Set()
314+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
315+
return @{
316+
Property = 'Installed'
317+
ExpectedValue = $true
318+
ActualValue = $false
319+
}
320+
} -PassThru |
321+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
322+
return
323+
}
324+
}
325+
}
326+
327+
It 'Should call method Modify()' {
328+
InModuleScope -ScriptBlock {
329+
$script:mockSqlRSSetupInstance.Set()
330+
331+
$script:mockMethodModifyCallCount | Should -Be 1
332+
}
333+
}
334+
}
335+
}

0 commit comments

Comments
 (0)