From 0693c19bdda35f79c420c8328df7a4aad5e3176e Mon Sep 17 00:00:00 2001 From: iSazonov Date: Tue, 9 Jan 2018 13:13:33 +0300 Subject: [PATCH] Add a test for IValidateSetValuesGenerator in a module --- .../Scripting.Classes.Attributes.Tests.ps1 | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1 index 959ff2239d7..4a6cb7053fb 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.Attributes.Tests.ps1 @@ -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' {