July 2018
Beginner
552 pages
13h 18m
English
The main issue you will encounter while mocking functionality is that Pester cannot mock calls to .NET methods and types. This will add to your code, as you will have to generate wrapper functions around any .NET calls, which you can then mock in your tests:
# This cannot be tested properly[System.IO.DriveInfo]::new('N')# This cannot be tested internally as well, but can be mockedfunction Get-DriveInfo{ param ( $DriveLetter ) [System.IO.DriveInfo]::new($DriveLetter)}Describe SomeTest { It 'returns $false for IsReady when the drive does not exist' { Mock Get-DriveInfo {[psobject]@{IsReady = $false}} (Get-DriveInfo -DriveLetter 'N').IsReady | Should -Be $false }}
If your code relies on certain .NET types to be present but you ...
Read now
Unlock full access