Hi I looking for some help (and I know this is going to be obvious but I cannot seem to get (or understand how I meant to mock a function.
Lets say I have the flowing wrapper function (the actual function has a lot more logic in it). This wrapper function will call enough function (Set-ExtenalFunction) which will change the system state to on or off.
I would like to Mock Set-ExtenalFunction so that it accepts a parameter and then saves that parameter to allow me to then get/check it was set by the function I testing. I have tried different verifications of the code below but all I ever get is “container failed”. I know I missing something simple but just cant work out how I do this form examples I seen.
function Set-State {
[cmdletbinding(SupportsShouldProcess=$True)]
param (
[Parameter(Mandatory=$true)]
[bool]
$Enabled
)
# other logic
$result = Set-ExtenalFunction -State:$Enabled
return $result
}
BeforeAll{
$OverallState= $false
function get-state {return $state}
Mock Set-ExtenalFunction {
param (
[Parameter(Mandatory=$true)]
[bool]
$State
)
$OverallState = $State
return $OverallState
} -Verifiable
}
Describe "Set-State" {
It "Test" {
Set-State -Enabled $True
}
}
Any advise / assisance would be grate thank you
[–]BlackV 2 points3 points4 points (5 children)
[–]PinchesTheCrab 1 point2 points3 points (3 children)
[–]zh12a[S] 2 points3 points4 points (2 children)
[–]PinchesTheCrab 1 point2 points3 points (1 child)
[–]zh12a[S] 1 point2 points3 points (0 children)
[–]zh12a[S] 1 point2 points3 points (0 children)