Skip to content

Naming conflict in Mock.ps1 - Set-DynamicParameterVariables #582

@mbreakey3

Description

@mbreakey3

The parameter $Metadata in Set-DynamicParameterVariables (Mock.ps1: line 1202) is causing a type-conflict for mocked functions that also have a parameter called 'Metadata' (WebAdministration's Set-WebConfiguration particularly).

When this line:

$SessionState.PSVariable.Set($variableName, $keyValuePair.Value) (line 1219)

is called, it won't allow the mocked $Metadata to be set because it thinks it should be of type [System.Management.Automation.CommandMetadata].

One solution is to change the names of the parameters in this function to be more unique so that conflicts such as this don't arise.

Repro:

function Sample {
param(
[string]
${Metadata}
)
}

function Wrapper {
Sample -Metadata 'test'
}

Describe 'Bug in mock' {
Mock -CommandName Sample -MockWith {}
Wrapper
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions