@@ -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