Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created November 1, 2016 19:10
Show Gist options
  • Save bielawb/dc987a85981017997bd83402ec426149 to your computer and use it in GitHub Desktop.
Save bielawb/dc987a85981017997bd83402ec426149 to your computer and use it in GitHub Desktop.
Pester test for ValidateSet
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