mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add a test for IValidateSetValuesGenerator in a module (#5830)
Add a test that has been skipped in PR #5702
This commit is contained in:
@@ -410,6 +410,39 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
|
||||
Get-TestValidateSetPS6 -Param1 "AnyTestString" -ErrorAction Stop
|
||||
} | ShouldBeErrorId "TypeNotFound"
|
||||
}
|
||||
|
||||
It 'IValidateSetValuesGenerator works in PowerShell module' {
|
||||
$moduleFile = Join-Path $TestDrive -ChildPath "Test-Module-$((New-Guid).Guid).psm1"
|
||||
$module = @'
|
||||
class ValidateSetTest : System.Management.Automation.IValidateSetValuesGenerator
|
||||
{
|
||||
[string[]] GetValidValues()
|
||||
{
|
||||
return 'Hello', 'World'
|
||||
}
|
||||
}
|
||||
|
||||
function Test-ValidateSet
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet([ValidateSetTest])]
|
||||
[string[]]
|
||||
$Item
|
||||
)
|
||||
$Item
|
||||
}
|
||||
'@
|
||||
Set-Content -Path $moduleFile -Value $module -Force
|
||||
|
||||
try {
|
||||
Import-Module -Name $moduleFile -Force
|
||||
Test-ValidateSet 'Hello' | Should Be 'Hello'
|
||||
} finally {
|
||||
Remove-Module -Name $moduleFile -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context 'CachedValidValuesGeneratorBase class tests' {
|
||||
|
||||
Reference in New Issue
Block a user