MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Get-Uptime" -Tags "CI" {4 BeforeAll {5 $IsHighResolution = [system.diagnostics.stopwatch]::IsHighResolution6 # Skip Get-Uptime test if IsHighResolution = false7 # because stopwatch.GetTimestamp() return DateTime.UtcNow.Ticks8 # instead of ticks from system startup9 if ( ! $IsHighResolution )10 {11 $origDefaults = $PSDefaultParameterValues.Clone()12 $PSDefaultParameterValues['it:skip'] = $true13 }14 }15 AfterAll {16 if ( ! $IsHighResolution ){17 $global:PSDefaultParameterValues = $origDefaults18 }19 }20 It "Get-Uptime return timespan (default -Timespan)" {21 $upt = Get-Uptime22 $upt | Should -BeOfType Timespan23 }24 It "Get-Uptime -Since return DateTime" {25 $upt = Get-Uptime -Since26 $upt | Should -BeOfType DateTime27 }28 It "Get-Uptime -Since:`$false return TimeSpan" {29 $upt = Get-Uptime -Since:$false30 $upt | Should -BeOfType TimeSpan31 }32 It "Get-Uptime throw if IsHighResolution == false" {33 # Enable the test hook34 [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsNotHighResolution', $true)35 36 try {37 { Get-Uptime } | Should -Throw -ErrorId "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand"38 } finally {39 # Disable the test hook40 [system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsHighResolutionIsFalse', $false)41 }42 }43}44 