mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
* Fix GetType() bad pattern and related issues in tests $var.GetType() can raise an exception in tests so we should check $var before make the call. A large part of the tests does not make this check. I start with searching ".GetType()" but discovered many related issues in tests (reduntant and unneeded tests, "throw" bad pattens, bugs, formattings (sorry!) and so on) - I had to fix them too. * Fix after code review * Second wave of migration GetType() -> BeOfType Removed 'GetType().Name' patterns.
46 lines
1.5 KiB
PowerShell
46 lines
1.5 KiB
PowerShell
Describe "Get-Uptime" -Tags "CI" {
|
|
BeforeAll {
|
|
$IsHighResolution = [system.diagnostics.stopwatch]::IsHighResolution
|
|
# Skip Get-Uptime test if IsHighResolution = false
|
|
# because stopwatch.GetTimestamp() return DateTime.UtcNow.Ticks
|
|
# instead of ticks from system startup
|
|
if ( ! $IsHighResolution )
|
|
{
|
|
$origDefaults = $PSDefaultParameterValues.Clone()
|
|
$PSDefaultParameterValues['it:skip'] = $true
|
|
}
|
|
}
|
|
AfterAll {
|
|
if ( ! $IsHighResolution ){
|
|
$global:PSDefaultParameterValues = $origDefaults
|
|
}
|
|
}
|
|
It "Get-Uptime return timespan (default -Timespan)" {
|
|
$upt = Get-Uptime
|
|
$upt | Should BeOfType "Timespan"
|
|
}
|
|
It "Get-Uptime -Since return DateTime" {
|
|
$upt = Get-Uptime -Since
|
|
$upt | Should BeOfType "DateTime"
|
|
}
|
|
It "Get-Uptime throw if IsHighResolution == false" {
|
|
try
|
|
{
|
|
# Enable the test hook
|
|
[system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsNotHighResolution', $true)
|
|
|
|
Get-Uptime
|
|
throw "No Exception!"
|
|
}
|
|
catch
|
|
{
|
|
$_.FullyQualifiedErrorId | Should be "GetUptimePlatformIsNotSupported,Microsoft.PowerShell.Commands.GetUptimeCommand"
|
|
}
|
|
finally
|
|
{
|
|
# Disable the test hook
|
|
[system.management.automation.internal.internaltesthooks]::SetTestHook('StopwatchIsHighResolutionIsFalse', $false)
|
|
}
|
|
}
|
|
}
|