MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3 4Import-Module HelpersCommon5 6Describe "Set-Date for admin" -Tag @('CI', 'RequireAdminOnWindows', 'RequireSudoOnUnix') {7 BeforeAll {8 [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook("SetDate", $true)9 }10 AfterAll {11 [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook("SetDate", $false)12 }13 14 It "Set-Date should be able to set the date in an elevated context" {15 { Get-Date | Set-Date } | Should -Not -Throw16 }17 18 # Check the individual properties as the types may be different19 It "Set-Date should be able to set the date with -Date parameter" {20 $target = Get-Date21 $expected = $target22 $observed = Set-Date -Date $target23 # do not test dayofweek because the number of the day is different between native and managed24 $observed.Day | Should -Be $expected.Day25 $observed.Hour | Should -Be $expected.Hour26 $observed.Minutes | Should -Be $expected.Minutes27 $observed.Month | Should -Be $expected.Month28 $observed.Second | Should -Be $expected.Second29 $observed.Year | Should -Be $expected.Year30 }31}32 33Describe "Set-Date" -Tag 'CI' {34 It "Set-Date should produce an error in a non-elevated context" {35 if (Test-IsElevated) {36 Set-ItResult -Skipped -Because "must NOT be run as admin"37 }38 39 { Get-Date | Set-Date } | Should -Throw -ErrorId "System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.SetDateCommand"40 }41}42 