[string] $badCandidate = 'abc'
[string] $goodCandidate = '12/25/2021 08:09:11'
[Nullable[DateTime]] $dateTimeResult = [Covert]::GetDateTime($badCandidate)
if ($null -ne $dateTimeResult) {
throw "$badCandidate should result in an invalid DateTime"
}
$dateTimeResult = [Covert]::GetDateTime($null)
if ($null -ne $dateTimeResult) {
throw "`$null should result in an invalid DateTime"
}
$dateTimeResult = [Covert]::GetDateTime($goodCandidate)
if ($null -eq $dateTimeResult) {
throw "$goodCandidate should result in a valid DateTime"
}
$goodCandidate = '123'
[Nullable[int]] $intResult = [Covert]::GetInt($badCandidate)
if ($null -ne $intResult) {
throw "$badCandidate should result in an invalid int"
}
$intResult = [Covert]::GetInt($null)
if ($null -ne $intResult) {
throw "`$null should result in an invalid int"
}
$intResult = [Covert]::GetInt($goodCandidate)
if ($null -eq $intResult) {
throw "$goodCandidate should result in a valid int"
}
$goodCandidate = 'False'
[Nullable[bool]] $boolResult = [Covert]::GetBool($badCandidate)
if ($null -ne $boolResult) {
throw "$badCandidate should result in an invalid bool"
}
$boolResult = [Covert]::GetBool($null)
if ($null -ne $boolResult) {
throw "`$null should result in an invalid bool"
}
$boolResult = [Covert]::GetBool($goodCandidate)
if ($null -eq $boolResult) {
throw "$goodCandidate should result in a valid bool"
}
$goodCandidate = '123.123'
[Nullable[double]] $doubleResult = [Covert]::GetDouble($badCandidate)
if ($null -ne $doubleResult) {
throw "$badCandidate should result in an invalid double"
}
$doubleResult = [Covert]::GetDouble($null)
if ($null -ne $doubleResult) {
throw "`$null should result in an invalid double"
}
$doubleResult = [Covert]::GetDouble($goodCandidate)
if ($null -eq $doubleResult) {
throw "$goodCandidate should result in a valid double"
}
No comments :
Post a Comment