Hello all,
I’m pretty new to the unit testing world and have been working through the Pester Book. I’m struggling with mocking Set-ADUser when it has a non-terminating error.
Generally, I want to set a property with Set-ADUser and pipeline an object with what happened (success or failure for any reason) My pipeline object does contain more information than this sample.
Rough code in function:
Try{
Set-ADuser $Props
$UpdateProps = @{
sammaccountname = $user.samaccountname
status = 'updated'
}
$OutObject = New-Object PSObject -property $UpdateProps
$OutObject
}
Catch{
$FailedProps = @{
samaccountname = $User.samaccountname
status = 'failed'
}
$OutObject = New-Object PSObject -Property $FailedProps
$OutObject
}
How can I mock Set-ADUser to hit the catch block? I know the code hits the catch block if i test my function with bad input. I’ve looked at some references to $ErrorAction and counting non terminating errors, but I can’t ever get the mock right that it hits the catch.
Thanks in advance.
Dan