forked from PowerShell/PowerShell
/
Set-Date.Tests.ps1
37 lines (32 loc) · 1.45 KB
/
Set-Date.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Import-Module HelpersCommon
Describe "Set-Date for admin" -Tag @('CI', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {
BeforeAll {
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook("SetDate", $true)
}
AfterAll {
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook("SetDate", $false)
}
It "Set-Date should be able to set the date in an elevated context" {
{ Get-Date | Set-Date } | Should -Not -Throw
}
# Check the individual properties as the types may be different
It "Set-Date should be able to set the date with -Date parameter" {
$target = Get-Date
$expected = $target
$observed = Set-Date -Date $target
# do not test dayofweek because the number of the day is different between native and managed
$observed.Day | Should -Be $expected.Day
$observed.Hour | Should -Be $expected.Hour
$observed.Minutes | Should -Be $expected.Minutes
$observed.Month | Should -Be $expected.Month
$observed.Second | Should -Be $expected.Second
$observed.Year | Should -Be $expected.Year
}
}
Describe "Set-Date" -Tag 'CI' {
It "Set-Date should produce an error in a non-elevated context" {
{ Get-Date | Set-Date } | Should -Throw -ErrorId "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand"
}
}