Skip to content

Commit

Permalink
DynamicParam update
Browse files Browse the repository at this point in the history
Assignment of session state now comes straight from the mocked function's script block, instead of only when the script block is part of a module.
  • Loading branch information
dlwyatt committed Sep 3, 2014
1 parent 73a9860 commit 3f72ac2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Functions/Mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ about_Mocking
$dynamicParamStatements = Get-DynamicParamBlock -ScriptBlock $contextInfo.Command.ScriptBlock
$dynamicParamScriptBlock = [scriptblock]::Create("$cmdletBinding`r`nparam( $paramBlock )`r`n$dynamicParamStatements")

if ($contextInfo.Command.ScriptBlock.Module)
$sessionStateInternal = Get-ScriptBlockScope -ScriptBlock $contextInfo.Command.ScriptBlock

if ($null -ne $sessionStateInternal)
{
Set-ScriptBlockScope -ScriptBlock $dynamicParamScriptBlock -SessionState $contextInfo.Command.ScriptBlock.Module.SessionState
Set-ScriptBlockScope -ScriptBlock $dynamicParamScriptBlock -SessionStateInternal $sessionStateInternal
}
}
}
Expand Down

0 comments on commit 3f72ac2

Please sign in to comment.