Skip to content

Commit b163ea8

Browse files
authored
Use Preview V2 Base Class (#115)
1 parent d120bfd commit b163ea8

File tree

5 files changed

+91
-87
lines changed

5 files changed

+91
-87
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Converted to Class Resource.
2121
- Extracted private functions to individual files.
2222
- BREAKING: Renamed parameter `DN` to `BaseDN` - fixes [Issue #89](https://github.com/dsccommunity/WSManDsc/issues/89).
23+
- Update tests to pass using v2 base class.
2324
- `DSC_WSManConfig`
2425
- Removed Export-ModuleMember.
2526
- `DSC_WSManServiceConfig`
2627
- Removed Export-ModuleMember.
2728
- `azure-pipelines.yml`
2829
- Remove windows 2019 image add windows 2025 fixes [#112](https://github.com/dsccommunity/WSManDsc/issues/112).
30+
- `RequiredModules`
31+
- Use preview `DscResource.Base`.
2932

3033
### Removed
3134

RequiredModules.psd1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121

2222
# Build dependencies needed for using the module
2323
'DscResource.Common' = 'latest'
24-
'DscResource.Base' = 'latest'
24+
'DscResource.Base' = @{
25+
Version = 'latest'
26+
Parameters = @{
27+
AllowPrerelease = $true
28+
}
29+
}
2530

2631
# Analyzer rules
2732
'DscResource.AnalyzerRules' = 'latest'

source/Classes/020.WSManListener.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ class WSManListener : ResourceBase
121121

122122
WSManListener () : base ($PSScriptRoot)
123123
{
124-
# Enable use of Enums as optional properties
125-
$this.FeatureOptionalEnums = $true
126-
127124
# These properties will not be enforced.
128125
$this.ExcludeDscProperties = @(
129126
'Issuer'

tests/Integration/DSC_WSManServiceConfig.Integration.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ Describe "$($script:dscResourceName)_Integration" {
115115
} # foreach
116116
}
117117

118+
AfterEach {
119+
Wait-ForIdleLcm
120+
}
121+
118122
It 'Should compile without throwing' {
119123
{
120124
& "$($script:dscResourceName)_Config" `

tests/Unit/Classes/WSManListener.Tests.ps1

Lines changed: 78 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
9292

9393
<#
9494
This mocks the method GetCurrentState().
95+
This mocks the method Assert().
96+
This mocks the method Normalize().
9597
9698
Method Get() will call the base method Get() which will
97-
call back to the derived class method GetCurrentState()
98-
to get the result to return from the derived method Get().
99+
call back to the derived class methods.
99100
#>
100101
$script:mockInstance |
101102
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
@@ -107,10 +108,10 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
107108
URLPrefix = 'wsman'
108109
}
109110
} -PassThru |
110-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
111+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Assert' -Value {
111112
return
112113
} -PassThru |
113-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
114+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Normalize' -Value {
114115
return
115116
} -PassThru
116117
}
@@ -155,10 +156,11 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
155156

156157
<#
157158
This mocks the method GetCurrentState().
159+
This mocks the method Assert().
160+
This mocks the method Normalize().
158161
159162
Method Get() will call the base method Get() which will
160-
call back to the derived class method GetCurrentState()
161-
to get the result to return from the derived method Get().
163+
call back to the derived class methods.
162164
#>
163165
$script:mockInstance |
164166
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
@@ -170,10 +172,10 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
170172
URLPrefix = 'wsman'
171173
}
172174
} -PassThru |
173-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
175+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Assert' -Value {
174176
return
175177
} -PassThru |
176-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
178+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Normalize' -Value {
177179
return
178180
} -PassThru
179181
}
@@ -217,19 +219,20 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
217219

218220
<#
219221
This mocks the method GetCurrentState().
222+
This mocks the method Assert().
223+
This mocks the method Normalize().
220224
221225
Method Get() will call the base method Get() which will
222-
call back to the derived class method GetCurrentState()
223-
to get the result to return from the derived method Get().
226+
call back to the derived class methods.
224227
#>
225228
$script:mockInstance |
226229
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
227230
return @{}
228231
} -PassThru |
229-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
232+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Assert' -Value {
230233
return
231234
} -PassThru |
232-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
235+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Normalize' -Value {
233236
return
234237
} -PassThru
235238
}
@@ -256,18 +259,7 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
256259
$currentState.Hostname | Should -BeNullOrEmpty
257260

258261
$currentState.Ensure | Should -Be 'Absent'
259-
$currentState.Reasons | Should -HaveCount 1
260-
$currentState.Reasons[0].Code | Should -Be 'WSManListener:WSManListener:Transport'
261-
262-
# PS6+ treats empty enum as null
263-
if ($PSVersionTable.PSVersion.Major -gt 5)
264-
{
265-
$currentState.Reasons[0].Phrase | Should -Be 'The property Transport should be "HTTP", but was null'
266-
}
267-
else
268-
{
269-
$currentState.Reasons[0].Phrase | Should -Be 'The property Transport should be "HTTP", but was ""'
270-
}
262+
$currentState.Reasons | Should -HaveCount 0
271263
}
272264
}
273265
}
@@ -287,10 +279,11 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
287279

288280
<#
289281
This mocks the method GetCurrentState().
282+
This mocks the method Assert().
283+
This mocks the method Normalize().
290284
291285
Method Get() will call the base method Get() which will
292-
call back to the derived class method GetCurrentState()
293-
to get the result to return from the derived method Get().
286+
call back to the derived class methods.
294287
#>
295288
$script:mockInstance |
296289
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
@@ -302,10 +295,10 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
302295
URLPrefix = 'wsman'
303296
}
304297
} -PassThru |
305-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
298+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Assert' -Value {
306299
return
307300
} -PassThru |
308-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
301+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Normalize' -Value {
309302
return
310303
} -PassThru
311304
}
@@ -354,10 +347,11 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
354347

355348
<#
356349
This mocks the method GetCurrentState().
350+
This mocks the method Assert().
351+
This mocks the method Normalize().
357352
358353
Method Get() will call the base method Get() which will
359-
call back to the derived class method GetCurrentState()
360-
to get the result to return from the derived method Get().
354+
call back to the derived class methods.
361355
#>
362356
$script:mockInstance |
363357
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
@@ -374,10 +368,10 @@ Describe 'WSManListener\Get()' -Tag 'Get' {
374368
Hostname = $null
375369
}
376370
} -PassThru |
377-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
371+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Assert' -Value {
378372
return
379373
} -PassThru |
380-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
374+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Normalize' -Value {
381375
return
382376
} -PassThru
383377
}
@@ -435,6 +429,7 @@ Describe 'WSManListener\Set()' -Tag 'Set' {
435429
InModuleScope -ScriptBlock {
436430
Set-StrictMode -Version 1.0
437431

432+
$script:methodTestCallCount = 0
438433
$script:methodModifyCallCount = 0
439434
}
440435
}
@@ -445,16 +440,12 @@ Describe 'WSManListener\Set()' -Tag 'Set' {
445440
Set-StrictMode -Version 1.0
446441

447442
$script:mockInstance |
448-
# Mock method Compare() which is called by the base method Set()
449-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
450-
return $null
451-
} -PassThru |
452-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
453-
return
454-
} -PassThru |
455-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
456-
return
457-
} -PassThru
443+
# Mock method Test() which is called by the base method Set()
444+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Test' -Value {
445+
$script:methodTestCallCount += 1
446+
return $true
447+
}
448+
458449
}
459450
}
460451

@@ -464,6 +455,7 @@ Describe 'WSManListener\Set()' -Tag 'Set' {
464455

465456
$script:mockInstance.Set()
466457

458+
$script:methodTestCallCount | Should -Be 1
467459
$script:methodModifyCallCount | Should -Be 0
468460
}
469461
}
@@ -475,22 +467,19 @@ Describe 'WSManListener\Set()' -Tag 'Set' {
475467
Set-StrictMode -Version 1.0
476468

477469
$script:mockInstance |
478-
# Mock method Compare() which is called by the base method Set()
479-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
480-
return @(
481-
@{
482-
Property = 'Port'
483-
ExpectedValue = 5000
484-
ActualValue = 5985
485-
}
486-
)
487-
} -PassThru |
488-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
489-
return
490-
} -PassThru |
491-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
492-
return
493-
} -PassThru
470+
# Mock method Test() which is called by the base method Set()
471+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Test' -Value {
472+
$script:methodTestCallCount += 1
473+
return $false
474+
}
475+
476+
$script:mockInstance.PropertiesNotInDesiredState = @(
477+
@{
478+
Property = 'Port'
479+
ExpectedValue = 5000
480+
ActualValue = 5985
481+
}
482+
)
494483
}
495484
}
496485

@@ -500,6 +489,7 @@ Describe 'WSManListener\Set()' -Tag 'Set' {
500489

501490
$script:mockInstance.Set()
502491

492+
$script:methodTestCallCount | Should -Be 1
503493
$script:methodModifyCallCount | Should -Be 1
504494
}
505495
}
@@ -521,29 +511,33 @@ Describe 'WSManListener\Test()' -Tag 'Test' {
521511
}
522512
}
523513

514+
BeforeEach {
515+
InModuleScope -ScriptBlock {
516+
Set-StrictMode -Version 1.0
517+
518+
$script:getMethodCallCount = 0
519+
}
520+
}
521+
524522
Context 'When the system is in the desired state' {
525523
BeforeAll {
526524
InModuleScope -ScriptBlock {
527525
Set-StrictMode -Version 1.0
528526

529527
$script:mockInstance |
530-
# Mock method Compare() which is called by the base method Set()
531-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
532-
return $null
533-
} -PassThru |
534-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
535-
return
536-
} -PassThru |
537-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
538-
return
539-
} -PassThru
528+
# Mock method Get() which is called by the base method Test()
529+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Get' -Value {
530+
$script:getMethodCallCount += 1
531+
}
540532
}
541533

542534
It 'Should return $true' {
543535
InModuleScope -ScriptBlock {
544536
Set-StrictMode -Version 1.0
545537

546538
$script:mockInstance.Test() | Should -BeTrue
539+
540+
$script:getMethodCallCount | Should -Be 1
547541
}
548542
}
549543
}
@@ -555,21 +549,18 @@ Describe 'WSManListener\Test()' -Tag 'Test' {
555549
Set-StrictMode -Version 1.0
556550

557551
$script:mockInstance |
558-
# Mock method Compare() which is called by the base method Set()
559-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
560-
return @(
561-
@{
562-
Property = 'Port'
563-
ExpectedValue = 5986
564-
ActualValue = 443
565-
})
566-
} -PassThru |
567-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
568-
return
569-
} -PassThru |
570-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'NormalizeProperties' -Value {
571-
return
572-
} -PassThru
552+
# Mock method Get() which is called by the base method Test()
553+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Get' -Value {
554+
$script:getMethodCallCount += 1
555+
}
556+
557+
$script:mockInstance.PropertiesNotInDesiredState = @(
558+
@{
559+
Property = 'Port'
560+
ExpectedValue = 5986
561+
ActualValue = 443
562+
}
563+
)
573564
}
574565
}
575566

@@ -578,6 +569,8 @@ Describe 'WSManListener\Test()' -Tag 'Test' {
578569
Set-StrictMode -Version 1.0
579570

580571
$script:mockInstance.Test() | Should -BeFalse
572+
573+
$script:getMethodCallCount | Should -Be 1
581574
}
582575
}
583576
}
@@ -782,6 +775,7 @@ Describe 'WSManListener\Modify()' -Tag 'HiddenMember' {
782775
$script:mockInstance.Modify($mockProperties)
783776

784777
$script:methodNewInstanceCallCount | Should -Be 1
778+
$script:methodRemoveInstanceCallCount | Should -Be 0
785779
}
786780
}
787781
}
@@ -800,6 +794,7 @@ Describe 'WSManListener\Modify()' -Tag 'HiddenMember' {
800794

801795
$script:mockInstance.Modify($mockProperties)
802796

797+
$script:methodNewInstanceCallCount | Should -Be 0
803798
$script:methodRemoveInstanceCallCount | Should -Be 1
804799
}
805800
}

0 commit comments

Comments
 (0)