|
179 | 179 |
|
180 | 180 | It 'Should update the scheduled task in the set method' { |
181 | 181 | Set-TargetResource @testParameters |
182 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
183 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 182 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 183 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
184 | 184 | } |
185 | 185 | } |
186 | 186 |
|
|
267 | 267 |
|
268 | 268 | It 'Should update the scheduled task in the set method' { |
269 | 269 | Set-TargetResource @testParameters |
270 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
271 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 270 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 271 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
272 | 272 | } |
273 | 273 | } |
274 | 274 |
|
|
354 | 354 |
|
355 | 355 | It 'Should update the scheduled task in the set method' { |
356 | 356 | Set-TargetResource @testParameters |
357 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
358 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 357 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 358 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
359 | 359 | } |
360 | 360 | } |
361 | 361 |
|
|
439 | 439 |
|
440 | 440 | It 'Should update the scheduled task in the set method' { |
441 | 441 | Set-TargetResource @testParameters |
442 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
443 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 442 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 443 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
444 | 444 | } |
445 | 445 | } |
446 | 446 |
|
|
490 | 490 |
|
491 | 491 | It 'Should update the scheduled task in the set method' { |
492 | 492 | Set-TargetResource @testParameters |
493 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
494 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 493 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 494 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
495 | 495 | } |
496 | 496 | } |
497 | 497 |
|
|
541 | 541 |
|
542 | 542 | It 'Should update the scheduled task in the set method' { |
543 | 543 | Set-TargetResource @testParameters |
544 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
545 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 544 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 545 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
546 | 546 | } |
547 | 547 | } |
548 | 548 |
|
|
590 | 590 |
|
591 | 591 | It 'Should update the scheduled task in the set method' { |
592 | 592 | Set-TargetResource @testParameters |
593 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
594 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 593 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 594 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
595 | 595 | } |
596 | 596 | } |
597 | 597 |
|
|
639 | 639 |
|
640 | 640 | It 'Should update the scheduled task in the set method' { |
641 | 641 | Set-TargetResource @testParameters |
642 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
643 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 642 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 643 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
644 | 644 | } |
645 | 645 | } |
646 | 646 |
|
@@ -691,12 +691,66 @@ try |
691 | 691 |
|
692 | 692 | It 'Should update the scheduled task in the set method' { |
693 | 693 | Set-TargetResource @testParameters |
694 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
695 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 694 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 695 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
696 | 696 | } |
697 | 697 |
|
698 | 698 | } |
699 | 699 |
|
| 700 | + Context 'A scheduled task is enabled without an execution time limit and but has an execution time limit set' { |
| 701 | + $testParameters = @{ |
| 702 | + TaskName = 'Test task' |
| 703 | + TaskPath = '\Test\' |
| 704 | + ActionExecutable = 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' |
| 705 | + ScheduleType = 'Once' |
| 706 | + RepeatInterval = (New-TimeSpan -Minutes 15).ToString() |
| 707 | + RepetitionDuration = (New-TimeSpan -Hours 8).ToString() |
| 708 | + ExecutionTimeLimit = (New-TimeSpan -Seconds 0).ToString() |
| 709 | + Enable = $true |
| 710 | + Verbose = $True |
| 711 | + } |
| 712 | + |
| 713 | + Mock -CommandName Get-ScheduledTask { return @{ |
| 714 | + TaskName = $testParameters.TaskName |
| 715 | + TaskPath = $testParameters.TaskPath |
| 716 | + Actions = @(@{ |
| 717 | + Execute = $testParameters.ActionExecutable |
| 718 | + Arguments = $testParameters.Arguments |
| 719 | + }) |
| 720 | + Triggers = @(@{ |
| 721 | + Repetition = @{ |
| 722 | + Duration = "PT$([System.TimeSpan]::Parse($testParameters.RepetitionDuration).TotalHours)H" |
| 723 | + Interval = "PT$([System.TimeSpan]::Parse($testParameters.RepeatInterval).TotalMinutes)M" |
| 724 | + } |
| 725 | + CimClass = @{ |
| 726 | + CimClassName = 'MSFT_TaskTimeTrigger' |
| 727 | + } |
| 728 | + }) |
| 729 | + Settings = @(@{ |
| 730 | + Enabled = $true |
| 731 | + ExecutionTimeLimit = "PT$([System.TimeSpan]::Parse($testParameters.RepeatInterval).TotalSeconds + 60)S" |
| 732 | + }) |
| 733 | + Principal = @{ |
| 734 | + UserId = 'SYSTEM' |
| 735 | + } |
| 736 | + } } |
| 737 | + |
| 738 | + It 'Should return the correct values from Get-TargetResource' { |
| 739 | + $result = Get-TargetResource @testParameters |
| 740 | + $result.Ensure | Should Be 'Present' |
| 741 | + } |
| 742 | + |
| 743 | + It 'Should return false from the test method' { |
| 744 | + Test-TargetResource @testParameters | Should Be $false |
| 745 | + } |
| 746 | + |
| 747 | + It 'Should update the scheduled task in the set method' { |
| 748 | + Set-TargetResource @testParameters |
| 749 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 750 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
| 751 | + } |
| 752 | + } |
| 753 | + |
700 | 754 | Context 'A scheduled task is enabled and has the correct settings' { |
701 | 755 | $testParameters = @{ |
702 | 756 | TaskName = 'Test task' |
|
848 | 902 |
|
849 | 903 | It 'Should update the scheduled task in the set method' { |
850 | 904 | Set-TargetResource @testParameters |
851 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
852 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 905 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 906 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
853 | 907 | } |
854 | 908 | } |
855 | 909 |
|
|
977 | 1031 |
|
978 | 1032 | It 'Should update the scheduled task in the set method' { |
979 | 1033 | Set-TargetResource @testParameters |
980 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
981 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 1034 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 1035 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
982 | 1036 | } |
983 | 1037 | } |
984 | 1038 |
|
@@ -1039,8 +1093,8 @@ try |
1039 | 1093 |
|
1040 | 1094 | It 'Should update the scheduled task in the set method' { |
1041 | 1095 | Set-TargetResource @testParameters |
1042 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
1043 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 1096 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 1097 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
1044 | 1098 | } |
1045 | 1099 | } |
1046 | 1100 |
|
@@ -1087,8 +1141,8 @@ try |
1087 | 1141 |
|
1088 | 1142 | It 'Should update the scheduled task in the set method' { |
1089 | 1143 | Set-TargetResource @testParameters |
1090 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
1091 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 1144 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 1145 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
1092 | 1146 | } |
1093 | 1147 | } |
1094 | 1148 |
|
@@ -1135,8 +1189,8 @@ try |
1135 | 1189 |
|
1136 | 1190 | It 'Should update the scheduled task in the set method' { |
1137 | 1191 | Set-TargetResource @testParameters |
1138 | | - Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1 |
1139 | | - Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1 |
| 1192 | + Assert-MockCalled -CommandName Unregister-ScheduledTask -Exactly -Times 1 |
| 1193 | + Assert-Mockcalled -CommandName Register-ScheduledTask -Exactly -Times 1 |
1140 | 1194 | } |
1141 | 1195 | } |
1142 | 1196 |
|
|
0 commit comments