11# Requires -Version 5.0
22$Global :DSCModuleName = ' xComputerManagement'
33$Global :DSCResourceName = ' MSFT_xScheduledTask'
4-
54# region HEADER
6- # Unit Test Template Version: 1.1.0
7- [String ] $moduleRoot = Split-Path - Parent (Split-Path - Parent ( Split-Path - Parent $ Script :MyInvocation .MyCommand.Path ) )
8- if ( (-not (Test-Path - Path (Join-Path - Path $moduleRoot - ChildPath ' DSCResource.Tests' ))) -or `
9- (-not (Test-Path - Path (Join-Path - Path $moduleRoot - ChildPath ' DSCResource.Tests\TestHelper.psm1' ))) )
5+ # Integration Test Template Version: 1.1.1
6+ [String ] $script : moduleRoot = Split-Path - Parent (Split-Path - Parent $PSScriptRoot )
7+ if ( (-not (Test-Path - Path (Join-Path - Path $script : moduleRoot - ChildPath ' DSCResource.Tests' ))) -or `
8+ (-not (Test-Path - Path (Join-Path - Path $script : moduleRoot - ChildPath ' DSCResource.Tests\TestHelper.psm1' ))) )
109{
11- & git @ (' clone' , ' https://github.com/PowerShell/DscResource.Tests.git' , (Join-Path - Path $moduleRoot - ChildPath ' \DSCResource.Tests\' ))
10+ & git @ (' clone' , ' https://github.com/PowerShell/DscResource.Tests.git' , (Join-Path - Path $script : moduleRoot - ChildPath ' \DSCResource.Tests\' ))
1211}
1312
14- Import-Module (Join-Path - Path $moduleRoot - ChildPath ' DSCResource.Tests\ TestHelper.psm1' ) - Force
13+ Import-Module - Name (Join-Path - Path $script : moduleRoot - ChildPath ( Join-Path - Path ' DSCResource.Tests' - ChildPath ' TestHelper.psm1' ) ) - Force
1514$TestEnvironment = Initialize-TestEnvironment `
16- - DSCModuleName $Global :DSCModuleName `
17- - DSCResourceName $Global :DSCResourceName `
18- - TestType Integration
15+ - DSCModuleName $script :DSCModuleName `
16+ - DSCResourceName $script :DSCResourceName `
17+ - TestType Integration
1918
19+ # endregion
2020# Begin Testing
2121try
2222{
2626 # region Pester Tests
2727 Describe $Global :DSCResourceName {
2828
29- Context " No scheduled task exists, but it should" {
30- $CurrentConfig = " xScheduledTask_Add"
29+ # region Schedule type once
30+ Context ' [Once] No scheduled task exists but it should' {
31+ $CurrentConfig = " xScheduledTaskOnceAdd"
3132 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
3233 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
3334
3940
4041 It " should apply the MOF correctly" {
4142 {
42- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
43+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
4344 } | Should Not Throw
4445 }
4546
4647 It " should return a compliant state after being applied" {
47- (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose ).InDesiredState | Should be $true
48+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
4849 }
4950 }
50-
51- Context " A scheduled task with minutes based repetition exists, but has the wrong settings" {
52- $CurrentConfig = " xScheduledTask_Edit1 "
51+
52+ Context ' [Once] A scheduled task exists with the wrong settings' {
53+ $CurrentConfig = " xScheduledTaskOnceMod "
5354 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
5455 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
5556
6162
6263 It " should apply the MOF correctly" {
6364 {
64- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
65+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
6566 } | Should Not Throw
6667 }
6768
6869 It " should return a compliant state after being applied" {
69- (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose ).InDesiredState | Should be $true
70+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
7071 }
7172 }
72-
73- Context " A scheduled task with hourly based repetition exists, but has the wrong settings " {
74- $CurrentConfig = " xScheduledTask_Edit2 "
73+
74+ Context ' [Once] A scheduled tasks exists but it should not ' {
75+ $CurrentConfig = " xScheduledTaskOnceDel "
7576 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
7677 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
7778
8384
8485 It " should apply the MOF correctly" {
8586 {
86- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
87+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
8788 } | Should Not Throw
8889 }
8990
9091 It " should return a compliant state after being applied" {
91- (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose ).InDesiredState | Should be $true
92+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
9293 }
9394 }
94-
95- Context " A scheduled task with daily based repetition exists, but has the wrong settings" {
96- $CurrentConfig = " xScheduledTask_Edit3"
95+ # endregion
96+
97+ # region Schedule type daily
98+ Context ' [Daily] No scheduled task exists but it should' {
99+ $CurrentConfig = " xScheduledTaskDailyAdd"
97100 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
98101 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
99102
@@ -105,17 +108,17 @@ try
105108
106109 It " should apply the MOF correctly" {
107110 {
108- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
111+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
109112 } | Should Not Throw
110113 }
111114
112115 It " should return a compliant state after being applied" {
113- (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose ).InDesiredState | Should be $true
116+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
114117 }
115118 }
116-
117- Context " A scheduled task exists and is configured with the wrong working directory " {
118- $CurrentConfig = " xScheduledTask_Edit4 "
119+
120+ Context ' [Daily] A scheduled task exists with the wrong settings ' {
121+ $CurrentConfig = " xScheduledTaskDailyMod "
119122 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
120123 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
121124
@@ -127,17 +130,17 @@ try
127130
128131 It " should apply the MOF correctly" {
129132 {
130- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
133+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
131134 } | Should Not Throw
132135 }
133136
134137 It " should return a compliant state after being applied" {
135- (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose ).InDesiredState | Should be $true
138+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
136139 }
137140 }
138-
139- Context " A scheduled task exists and is configured with the wrong executable arguments " {
140- $CurrentConfig = " xScheduledTask_Edit5 "
141+
142+ Context ' [Daily] A scheduled tasks exists but it should not ' {
143+ $CurrentConfig = " xScheduledTaskDailyDel "
141144 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
142145 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
143146
@@ -149,17 +152,19 @@ try
149152
150153 It " should apply the MOF correctly" {
151154 {
152- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
155+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
153156 } | Should Not Throw
154157 }
155158
156159 It " should return a compliant state after being applied" {
157- (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose ).InDesiredState | Should be $true
160+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
158161 }
159162 }
163+ # endregion
160164
161- Context " A scheduled task exists, but it shouldn't" {
162- $CurrentConfig = " xScheduledTask_Remove"
165+ # region Schedule type weekly
166+ Context ' [Weekly] No scheduled task exists but it should' {
167+ $CurrentConfig = " xScheduledTaskWeeklyAdd"
163168 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
164169 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
165170
@@ -171,17 +176,17 @@ try
171176
172177 It " should apply the MOF correctly" {
173178 {
174- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
179+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
175180 } | Should Not Throw
176181 }
177182
178183 It " should return a compliant state after being applied" {
179184 (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose).InDesiredState | Should be $true
180185 }
181186 }
182-
183- Context " A scheduled task exists, and should be enabled " {
184- $CurrentConfig = " xScheduledTask_Enable "
187+
188+ Context ' [Weekly] A scheduled task exists with the wrong settings ' {
189+ $CurrentConfig = " xScheduledTaskWeeklyMod "
185190 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
186191 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
187192
@@ -193,17 +198,41 @@ try
193198
194199 It " should apply the MOF correctly" {
195200 {
196- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
201+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
197202 } | Should Not Throw
198203 }
199204
200205 It " should return a compliant state after being applied" {
201- (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose ).InDesiredState | Should be $true
206+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
202207 }
203208 }
209+
210+ Context ' [Weekly] A scheduled tasks exists but it should not' {
211+ $CurrentConfig = " xScheduledTaskWeeklyDel"
212+ $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
213+ $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
214+
215+ It " should compile a MOF file without error" {
216+ {
217+ . $CurrentConfig - OutputPath $ConfigDir
218+ } | Should Not Throw
219+ }
220+
221+ It " should apply the MOF correctly" {
222+ {
223+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
224+ } | Should Not Throw
225+ }
226+
227+ It " should return a compliant state after being applied" {
228+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
229+ }
230+ }
231+ # endregion
204232
205- Context " A scheduled task exists, and should be disabled" {
206- $CurrentConfig = " xScheduledTask_Disable"
233+ # region Schedule type atlogon
234+ Context ' [AtLogon] No scheduled task exists but it should' {
235+ $CurrentConfig = " xScheduledTaskLogonAdd"
207236 $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
208237 $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
209238
@@ -215,18 +244,129 @@ try
215244
216245 It " should apply the MOF correctly" {
217246 {
218- Start-DscConfiguration - Path $ConfigDir - Wait - Verbose - Force
247+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
219248 } | Should Not Throw
220249 }
221250
222251 It " should return a compliant state after being applied" {
223- (Test-DscConfiguration - ReferenceConfiguration $ConfigMof - Verbose).InDesiredState | Should be $true
252+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
253+ }
254+ }
255+
256+ Context ' [AtLogon] A scheduled task exists with the wrong settings' {
257+ $CurrentConfig = " xScheduledTaskLogonMod"
258+ $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
259+ $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
260+
261+ It " should compile a MOF file without error" {
262+ {
263+ . $CurrentConfig - OutputPath $ConfigDir
264+ } | Should Not Throw
265+ }
266+
267+ It " should apply the MOF correctly" {
268+ {
269+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
270+ } | Should Not Throw
271+ }
272+
273+ It " should return a compliant state after being applied" {
274+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
224275 }
225276 }
277+
278+ Context ' [AtLogon] A scheduled tasks exists but it should not' {
279+ $CurrentConfig = " xScheduledTaskLogonDel"
280+ $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
281+ $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
282+
283+ It " should compile a MOF file without error" {
284+ {
285+ . $CurrentConfig - OutputPath $ConfigDir
286+ } | Should Not Throw
287+ }
288+
289+ It " should apply the MOF correctly" {
290+ {
291+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
292+ } | Should Not Throw
293+ }
294+
295+ It " should return a compliant state after being applied" {
296+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
297+ }
298+ }
299+ # endregion
226300
227- AfterEach {
228- Remove-DscConfigurationDocument - Stage Current, Pending, Previous - Force - Confirm:$false - WarningAction SilentlyContinue
301+ # region Schedule type atstartup
302+ Context ' [AtStartup] No scheduled task exists but it should' {
303+
304+ $CurrentConfig = " xScheduledTaskStartupAdd"
305+ $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
306+ $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
307+
308+ It " should compile a MOF file without error" {
309+ {
310+ . $CurrentConfig - OutputPath $ConfigDir
311+ } | Should Not Throw
312+ }
313+
314+ It " should apply the MOF correctly" {
315+ {
316+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
317+ } | Should Not Throw
318+ }
319+
320+ It " should return a compliant state after being applied" {
321+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
322+ }
323+ }
324+
325+ Context ' [AtStartup] A scheduled task exists with the wrong settings' {
326+
327+ $CurrentConfig = " xScheduledTaskStartupMod"
328+ $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
329+ $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
330+
331+ It " should compile a MOF file without error" {
332+ {
333+ . $CurrentConfig - OutputPath $ConfigDir
334+ } | Should Not Throw
335+ }
336+
337+ It " should apply the MOF correctly" {
338+ {
339+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
340+ } | Should Not Throw
341+ }
342+
343+ It " should return a compliant state after being applied" {
344+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
345+ }
346+ }
347+
348+ Context ' [AtStartup] A scheduled tasks exists but it should not' {
349+ $CurrentConfig = " xScheduledTaskStartupDel"
350+ $ConfigDir = (Join-Path $TestDrive $CurrentConfig )
351+ $ConfigMof = (Join-Path $ConfigDir " localhost.mof" )
352+
353+ It " should compile a MOF file without error" {
354+ {
355+ . $CurrentConfig - OutputPath $ConfigDir
356+ } | Should Not Throw
357+ }
358+
359+ It " should apply the MOF correctly" {
360+ {
361+ Start-DscConfiguration - Path $ConfigDir - Wait - Force
362+ } | Should Not Throw
363+ }
364+
365+ It " should return a compliant state after being applied" {
366+ (Test-DscConfiguration - ReferenceConfiguration $ConfigMof ).InDesiredState | Should be $true
367+ }
229368 }
369+ # endregion
230370 }
231371 # endregion
232372}
0 commit comments