Skip to content

Commit b6f18e7

Browse files
authored
Add a test for IValidateSetValuesGenerator in a module (#5830)
Add a test that has been skipped in PR #5702
1 parent 378e8d5 commit b6f18e7

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,39 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
410410
Get-TestValidateSetPS6 -Param1 "AnyTestString" -ErrorAction Stop
411411
} | ShouldBeErrorId "TypeNotFound"
412412
}
413+
414+
It 'IValidateSetValuesGenerator works in PowerShell module' {
415+
$moduleFile = Join-Path $TestDrive -ChildPath "Test-Module-$((New-Guid).Guid).psm1"
416+
$module = @'
417+
class ValidateSetTest : System.Management.Automation.IValidateSetValuesGenerator
418+
{
419+
[string[]] GetValidValues()
420+
{
421+
return 'Hello', 'World'
422+
}
423+
}
424+
425+
function Test-ValidateSet
426+
{
427+
[CmdletBinding()]
428+
param (
429+
[Parameter(Mandatory = $true)]
430+
[ValidateSet([ValidateSetTest])]
431+
[string[]]
432+
$Item
433+
)
434+
$Item
435+
}
436+
'@
437+
Set-Content -Path $moduleFile -Value $module -Force
438+
439+
try {
440+
Import-Module -Name $moduleFile -Force
441+
Test-ValidateSet 'Hello' | Should Be 'Hello'
442+
} finally {
443+
Remove-Module -Name $moduleFile -Force
444+
}
445+
}
413446
}
414447

415448
Context 'CachedValidValuesGeneratorBase class tests' {

0 commit comments

Comments
 (0)