pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.11k stars 473 forks source link

Missing Dynamic Parameters #1137

Open rdbartram opened 6 years ago

rdbartram commented 6 years ago

1. General summary of the issue

When mocking Copy-Item the dynamic parameters ToSession and FromSession are not available

2. Describe Your Environment

Pester version : 4.4.2 C:\Users\ryan.bartram\OneDrive - itnetx AG\Documents\WindowsPowerShell\Modules\Pester\4.4.2\Pester.psd1 PowerShell version : 5.1.17134.228 OS version : Microsoft Windows NT 10.0.17134.0

3. Expected Behavior

Pester should find the dynamic params and include them in the generated mock

4.Current Behavior

The two parameters in question are missing and it leads to the function failing and claiming that copy-item does not have parameters tosession or fromsession

5. Possible Solution

in Mock.ps1 line 1394, change the current method of retrieving the cmdlet definition with Get-Command. Don't ask me what the difference is in these two method calls but Get-Command returns the dynamic params and the $ExecutionContext.InvokeCommand.GetCommand does not. I have also tried with the 'old' pre PS 5.0 block and it fails there also.

6. Context

I am unable to mock a function that makes a call to Copy-Item using the ToSession and/or FromSession parameters

rdbartram commented 6 years ago

I would just make a PR but I assume i'm doing something wrong and this isn't a real bug :D

nohwnd commented 5 years ago

Dynamic params were always a bit problematic, if you have a PR ready then PR away :)