I am running into some issues trying to mock Set-ADUser. The ‘Sync-OTLUserWithAD’ function contains Get-ADuser and Set-ADuser calls but it will not respect the Set-ADuser mock and instead loads the ActiveDirectory Module and I either get InvalidCastException or insufficient rights errors when I run my pester tests. Any ideas?
Describe “Sync-OTLWithADUser” {
It “Syncs information correctly” {
Mock -CommandName Get-ADUser -MockWith {Return (Import-Clixml .\Test_AD_User.xml)}
Mock -CommandName Set-ADUser -MockWith {$Instance | Export-Clixml -Path .\After_Set.xml}
$OTLUser = Get-OTLUser “EmployeeNumber”
Sync-OTLUserWithAD -OTLUser $OTLUser
$BeforeTest = (Import-Clixml .\Test_AD_User.xml)
$AfterTest = (Import-Clixml -Path .\After_Set.xml)
$Props = $before.psobject.properties | Select -ExpandProperty Name
(Compare-Object -ReferenceObject $Before -DifferenceObject $After -Property $Props).count | Should be 0
} # end it
} # end describe