Skip to content

Commit 41d6501

Browse files
committed
Unit tests updated to cover new properties
1 parent 34b8da6 commit 41d6501

1 file changed

Lines changed: 45 additions & 23 deletions

File tree

Tests/Unit/MSFT_xScheduledTask.Tests.ps1

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ try
3939
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
4040
ScheduleType = "Once"
4141
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
42+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Minutes 150)
4243
}
4344

4445
Mock Get-ScheduledTask { return $null }
@@ -62,6 +63,7 @@ try
6263
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
6364
ScheduleType = "Once"
6465
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
66+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Minutes 15)
6567
Ensure = "Absent"
6668
}
6769

@@ -73,7 +75,7 @@ try
7375
})
7476
Triggers = @(@{
7577
Repetition = @{
76-
Duration = $null
78+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalMinutes)M"
7779
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
7880
}
7981
CimClass = @{
@@ -124,6 +126,7 @@ try
124126
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
125127
ScheduleType = "Once"
126128
RepeatInterval =[datetime]::Today + (New-TimeSpan -Minutes 15)
129+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Minutes 150)
127130
}
128131

129132
Mock Get-ScheduledTask { return @{
@@ -156,7 +159,8 @@ try
156159

157160
It "should update the scheduled task in the set method" {
158161
Set-TargetResource @testParams
159-
Assert-MockCalled Set-ScheduledTask
162+
Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1
163+
Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1
160164
}
161165
}
162166

@@ -166,6 +170,7 @@ try
166170
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
167171
ScheduleType = "Once"
168172
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
173+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Minutes 30)
169174
}
170175

171176
Mock Get-ScheduledTask { return @{
@@ -176,7 +181,7 @@ try
176181
})
177182
Triggers = @(@{
178183
Repetition = @{
179-
Duration = $null
184+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalMinutes)M"
180185
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
181186
}
182187
CimClass = @{
@@ -203,6 +208,7 @@ try
203208
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
204209
ScheduleType = "Once"
205210
RepeatInterval = [datetime]::Today + (New-TimeSpan -Hours 4)
211+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
206212
}
207213

208214
Mock Get-ScheduledTask { return @{
@@ -213,7 +219,7 @@ try
213219
})
214220
Triggers = @(@{
215221
Repetition = @{
216-
Duration = $null
222+
Duration = "PT$(($testParams.RepetitionDuration.TimeOfDay.TotalHours))H"
217223
Interval = "PT$(($testParams.RepeatInterval.TimeOfDay.TotalHours) + 1)H"
218224
}
219225
CimClass = @{
@@ -235,7 +241,8 @@ try
235241

236242
It "should update the scheduled task in the set method" {
237243
Set-TargetResource @testParams
238-
Assert-MockCalled Set-ScheduledTask
244+
Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1
245+
Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1
239246
}
240247
}
241248

@@ -245,6 +252,7 @@ try
245252
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
246253
ScheduleType = "Once"
247254
RepeatInterval = [datetime]::Today + (New-TimeSpan -Hours 4)
255+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
248256
}
249257

250258
Mock Get-ScheduledTask { return @{
@@ -255,7 +263,7 @@ try
255263
})
256264
Triggers = @(@{
257265
Repetition = @{
258-
Duration = $null
266+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalHours)H"
259267
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalHours)H"
260268
}
261269
CimClass = @{
@@ -314,7 +322,8 @@ try
314322

315323
It "should update the scheduled task in the set method" {
316324
Set-TargetResource @testParams
317-
Assert-MockCalled Set-ScheduledTask
325+
Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1
326+
Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1
318327
}
319328
}
320329

@@ -358,6 +367,7 @@ try
358367
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
359368
ScheduleType = "Once"
360369
RepeatInterval = [DateTime]::Today.Add((New-TimeSpan -Minutes 15))
370+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
361371
ExecuteAsCredential = New-Object System.Management.Automation.PSCredential ("DEMO\RightUser", (ConvertTo-SecureString "ExamplePassword" -AsPlainText -Force))
362372
}
363373

@@ -369,8 +379,8 @@ try
369379
})
370380
Triggers = @(@{
371381
Repetition = @{
372-
Duration = $null
373-
Interval = "PT$($testParams.RepeatInterval)M"
382+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalHours)H"
383+
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
374384
}
375385
CimClass = @{
376386
CimClassName = "MSFT_TaskTimeTrigger"
@@ -391,7 +401,8 @@ try
391401

392402
It "should update the scheduled task in the set method" {
393403
Set-TargetResource @testParams
394-
Assert-MockCalled Set-ScheduledTask
404+
Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1
405+
Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1
395406
}
396407
}
397408

@@ -402,6 +413,7 @@ try
402413
ActionWorkingPath = "C:\Example"
403414
ScheduleType = "Once"
404415
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
416+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
405417
}
406418

407419
Mock Get-ScheduledTask { return @{
@@ -414,7 +426,7 @@ try
414426
Triggers = @(@{
415427
Repetition = @{
416428
Duration = $null
417-
Interval = "PT$($testParams.RepeatInterval)M"
429+
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
418430
}
419431
CimClass = @{
420432
CimClassName = "MSFT_TaskTimeTrigger"
@@ -435,7 +447,8 @@ try
435447

436448
It "should update the scheduled task in the set method" {
437449
Set-TargetResource @testParams
438-
Assert-MockCalled Set-ScheduledTask
450+
Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1
451+
Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1
439452
}
440453
}
441454

@@ -446,6 +459,7 @@ try
446459
ActionArguments = "-File `"C:\something\right.ps1`""
447460
ScheduleType = "Once"
448461
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
462+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
449463
}
450464

451465
Mock Get-ScheduledTask { return @{
@@ -457,8 +471,8 @@ try
457471
})
458472
Triggers = @(@{
459473
Repetition = @{
460-
Duration = $null
461-
Interval = "PT$($testParams.RepeatInterval)M"
474+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalHours)H"
475+
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
462476
}
463477
CimClass = @{
464478
CimClassName = "MSFT_TaskTimeTrigger"
@@ -479,7 +493,8 @@ try
479493

480494
It "should update the scheduled task in the set method" {
481495
Set-TargetResource @testParams
482-
Assert-MockCalled Set-ScheduledTask
496+
Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1
497+
Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1
483498
}
484499
}
485500

@@ -489,6 +504,7 @@ try
489504
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
490505
ScheduleType = "Once"
491506
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
507+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
492508
Enable = $false
493509
}
494510

@@ -501,8 +517,8 @@ try
501517
})
502518
Triggers = @(@{
503519
Repetition = @{
504-
Duration = $null
505-
Interval = "PT$($testParams.RepeatInterval)M"
520+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalHours)H"
521+
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
506522
}
507523
CimClass = @{
508524
CimClassName = "MSFT_TaskTimeTrigger"
@@ -526,7 +542,8 @@ try
526542

527543
It "should update the scheduled task in the set method" {
528544
Set-TargetResource @testParams
529-
Assert-MockCalled Set-ScheduledTask
545+
Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1
546+
Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1
530547
}
531548

532549
}
@@ -537,6 +554,7 @@ try
537554
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
538555
ScheduleType = "Once"
539556
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
557+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
540558
Enable = $true
541559
}
542560

@@ -549,7 +567,7 @@ try
549567
})
550568
Triggers = @(@{
551569
Repetition = @{
552-
Duration = $null
570+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalHours)H"
553571
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
554572
}
555573
CimClass = @{
@@ -579,6 +597,7 @@ try
579597
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
580598
ScheduleType = "Once"
581599
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
600+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
582601
Enable = $false
583602
}
584603

@@ -591,7 +610,7 @@ try
591610
})
592611
Triggers = @(@{
593612
Repetition = @{
594-
Duration = $null
613+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalHours)H"
595614
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
596615
}
597616
CimClass = @{
@@ -621,6 +640,7 @@ try
621640
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
622641
ScheduleType = "Once"
623642
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
643+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
624644
Enable = $true
625645
}
626646

@@ -633,7 +653,7 @@ try
633653
})
634654
Triggers = @(@{
635655
Repetition = @{
636-
Duration = $null
656+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalHours)H"
637657
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
638658
}
639659
CimClass = @{
@@ -658,7 +678,8 @@ try
658678

659679
It "should update the scheduled task in the set method" {
660680
Set-TargetResource @testParams
661-
Assert-MockCalled Set-ScheduledTask
681+
Assert-MockCalled -CommandName Unregister-ScheduledTask -Times 1
682+
Assert-Mockcalled -CommandName Register-ScheduledTask -Times 1
662683
}
663684
}
664685

@@ -668,6 +689,7 @@ try
668689
ActionExecutable = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
669690
ScheduleType = "Once"
670691
RepeatInterval = [datetime]::Today + (New-TimeSpan -Minutes 15)
692+
RepetitionDuration = [datetime]::Today + (New-TimeSpan -Hours 8)
671693
}
672694

673695
Mock Get-ScheduledTask { return @{
@@ -679,7 +701,7 @@ try
679701
})
680702
Triggers = @(@{
681703
Repetition = @{
682-
Duration = $null
704+
Duration = "PT$($testParams.RepetitionDuration.TimeOfDay.TotalHours)H"
683705
Interval = "PT$($testParams.RepeatInterval.TimeOfDay.TotalMinutes)M"
684706
}
685707
CimClass = @{

0 commit comments

Comments
 (0)