Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Unreleased
- Added workaround for GetDynamicParameters() bug that was affecting mocks on the ActiveDirectory module in Windows 7. [GH-295]

## 3.3.6 (March 19, 2015)
- Fix for mocking aliases for commands that are in scopes that Pester can't normally see. [GH-267]
- Added line information to test failure output in Should assertion failures. [GH-266]
Expand Down
15 changes: 13 additions & 2 deletions Functions/Mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1010,11 +1010,22 @@ function Get-DynamicParametersForCmdlet

try
{
$cmdlet.GetDynamicParameters()
# This unary comma is important in some cases. On Windows 7 systems, the ActiveDirectory module cmdlets
# return objects from this method which implement IEnumerable for some reason, and even cause PowerShell
# to throw an exception when it tries to cast the object to that interface.

# We avoid that problem by wrapping the result of GetDynamicParameters() in a one-element array with the
# unary comma. PowerShell enumerates that array instead of trying to enumerate the goofy object, and
# everyone's happy.

# Love the comma. Don't delete it. We don't have a test for this yet, unless we can get the AD module
# on a Server 2008 R2 build server, or until we write some C# code to reproduce its goofy behavior.

,$cmdlet.GetDynamicParameters()
}
catch [System.NotImplementedException]
{
#ignore the exception
# Some cmdlets implement IDynamicParameters but then throw a NotImplementedException. I have no idea why. Ignore them.
}
}

Expand Down