Open
Description
1. General summary of the issue
The Get-AzureRmContext
defines a dynamic ValidateSet for the Name
Parameter, that checks if the given Name is existing on the current Machine. Using the RemoveParameterValidation
Parameter does not remove this check.
2. Describe Your Environment
Pester version : 4.10.1 C:\Users\SSchoof\OneDrive\Dokumente\WindowsPowerShell\Modules\Pester\4.10.1\Pester.psd1
PowerShell version : 5.1.18362.752
OS version : Microsoft Windows NT 10.0.18363.0
3. Expected Behavior
With the RemoveParameterValidation
the ValidateSet
of the Name
Parameter is removed.
4.Current Behavior
Describe "Get-AzureRmContext" {
Mock Get-AzureRmContext -RemoveParameterValidation Name
It "Mocks the validate set" {
Get-AzureRmContext -Name "ThisContextDoesNotExistOnThisMaschine"
}
}
[-] Mocks the validate set 44ms
ValidationMetadataException: Das Argument "ThisContextDoesNotExistOnThisMaschine" gehört nicht zu dem vom ValidateSet-Attribut angegebenen Satz "<all my existing contexts>". Geben Sie ein Argument an, das in dem Satz enthalten ist, und führen Sie dann den Befehl erneut aus.
ParameterBindingValidationException: Das Argument für den Parameter "Name" kann nicht überprüft werden. Das Argument "ThisContextDoesNotExistOnThisMaschine" gehört nicht zu dem vom ValidateSet-Attribut angegebenen Satz "<all my existing contexts>". Geben Sie ein Argument an, das in dem Satz enthalten ist, und führen Sie dann den Befehl erneut aus.
5. Possible Solution
Adding a layer of function
Describe "Get-AzureRmContext" {
function GetAzureRmContext {
param (
[String] $Name
)
Get-AzureRmContext -Name $Name
}
Mock GetAzureRmContext
It "Mocks the validate set" {
GetAzureRmContext -Name "ThisContextDoesNotExistOnThisMaschine"
}
}
6. Context
Mock the Get-AzureRmContext
with the Name
parameter, that is working independently of the current context of the VMs.