Created
November 1, 2016 19:10
-
-
Save bielawb/dc987a85981017997bd83402ec426149 to your computer and use it in GitHub Desktop.
Pester test for ValidateSet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo { | |
param ( | |
[ValidateSet( | |
'this', | |
'that' | |
)] | |
[String]$bar | |
) | |
} | |
Describe 'Testing foo' { | |
$parameterInfo = (Get-Command foo).Parameters['bar'] | |
It 'Has ValidateSet for parameter bar' { | |
$parameterInfo.Attributes.Where{ $_ -is [ValidateSet]}.Count | Should be 1 | |
} | |
It 'ValidateSet contains option this' { | |
$validateSet = $parameterInfo.Attributes.Where{ $_ -is [ValidateSet]} | |
$validateSet.ValidValues -contains 'this' | Should be $true | |
} | |
It 'ValidateSet contains option this' { | |
$validateSet = $parameterInfo.Attributes.Where{ $_ -is [ValidateSet]} | |
$validateSet.ValidValues -contains 'somethingElse' | Should be $true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment