Mocking

47 views
Skip to first unread message

simcelil...@gmail.com

unread,
Apr 17, 2015, 4:52:45 AM4/17/15
to pes...@googlegroups.com
Hi guys,

how can I mock this function such that Get-ChildItem returns Thumbprint?
function Get-ItemName
{
 Get-ChildItem -Path "cert:\localmachine\my"|Where-Object -FilterScript{$_.Subject -match "CN=localhost"} | Select-Object -ExpandProperty Thumbprint
}

Test:
Describe 'Get-TextFileNames' {
 Context 'When thumpsprint exists'{
    It 'should returns thumpsprint ' {
        Mock Get-ChildItem{[PSCustomObject]@{Thumbprint="89C9D79D47DCBF847F67DAE9860CFC2B4639623C"}}
        Get-ItemName| Should Be '89C9D79D47DCBF847F67DAE9860CFC2B4639623C'
    }
 }
}

Dave Wyatt

unread,
Apr 17, 2015, 7:24:40 AM4/17/15
to simcelil...@gmail.com, pes...@googlegroups.com
You will also need your mock object to have a Subject field which contains "CN=localhost" in order for your Get-ItemName function to use it.  Your mock should already have a Thumbprint; it's just being discarded by the Where-Object clause.

--
You received this message because you are subscribed to the Google Groups "Pester" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pester+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages