forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxyCommand.tests.ps1
More file actions
60 lines (51 loc) · 3.23 KB
/
Copy pathProxyCommand.tests.ps1
File metadata and controls
60 lines (51 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe 'ProxyCommand Tests' -Tag 'CI' {
BeforeAll {
$testCases = @(
@{ Name = 'ValidateLengthAttribute'; ParamBlock = '[ValidateLength(1, 10)][int]${Parameter}' }
@{ Name = 'ValidateRangeAttribute with Minimum and Maximum'; ParamBlock = '[ValidateRange(1, 10)][int]${Parameter}' }
@{ Name = 'ValidateRangeAttribute with RangeKind'; ParamBlock = '[ValidateRange([System.Management.Automation.ValidateRangeKind]::Positive)][int]${Parameter}' }
@{ Name = 'AllowNullAttribute'; ParamBlock = '[AllowNull()][int]${Parameter}' }
@{ Name = 'AllowEmptyStringAttribute'; ParamBlock = '[AllowEmptyString()][int]${Parameter}' }
@{ Name = 'AllowEmptyCollectionAttribute'; ParamBlock = '[AllowEmptyCollection()][int]${Parameter}' }
@{ Name = 'ValidatePatternAttribute'; ParamBlock = '[ValidatePattern(''.*'')][int]${Parameter}' }
@{ Name = 'ValidateCountAttribute'; ParamBlock = '[ValidateCount(1, 10)][int]${Parameter}' }
@{ Name = 'ValidateNotNullAttribute'; ParamBlock = '[ValidateNotNull()][int]${Parameter}' }
@{ Name = 'ValidateNotNullOrEmptyAttribute'; ParamBlock = '[ValidateNotNullOrEmpty()][int]${Parameter}' }
@{ Name = 'ValidateSetAttribute with explicit set'; ParamBlock = '[ValidateSet(''1'',''10'')][int]${Parameter}' }
@{ Name = 'PSTypeNameAttribute'; ParamBlock = '[PSTypeName(''TypeName'')][int]${Parameter}' }
)
}
Context 'GetParamBlock method' {
AfterAll {
Remove-Item function:testProxyCommandFunction -ErrorAction SilentlyContinue
}
It 'Generates a param block when <Name> is used' -TestCases $testCases {
param (
$Name,
$ParamBlock
)
$functionDefinition = 'param ( {0} )' -f $ParamBlock
Set-Item -Path function:testProxyCommandFunction -Value $functionDefinition
$generatedParamBlock = [System.Management.Automation.ProxyCommand]::GetParamBlock(
(Get-Command testProxyCommandFunction)
)
$generatedParamBlock = $generatedParamBlock -split '\r?\n' -replace '^ *' -join ''
$generatedParamBlock | Should -Be $ParamBlock
}
It 'Generates a param block when ValidateScriptAttribute is used' {
param (
$Name,
$ParamBlock
)
$functionDefinition = 'param ( [ValidateScript({ $true })][int]${Parameter} )'
Set-Item -Path function:testProxyCommandFunction -Value $functionDefinition
$generatedParamBlock = [System.Management.Automation.ProxyCommand]::GetParamBlock(
(Get-Command testProxyCommandFunction)
)
$generatedParamBlock = $generatedParamBlock -split '\r?\n' -replace '^ *' -join ''
$generatedParamBlock | Should -Be '[ValidateScript({ $true })][int]${Parameter}'
}
}
}