MockExample.ps1
function Get-Version {} function Get-NextVersion {} function Build ($version) { Write-Host "a build was run for version: $version" } function BuildIfChanged { $thisVersion = Get-Version $nextVersion = Get-NextVersion if ($thisVersion -ne $nextVersion) { Build $nextVersion } return $nextVersion } Describe "BuildIfChanged" { Context "When there are Changes" { Mock Get-Version {1.1} Mock Get-NextVersion {1.2} Mock Build {} -Verifiable -ParameterFilter {$version -eq 1.2} $result = BuildIfChanged It "Builds the next version" { Assert-VerifiableMocks } It "returns the next version number" { $result | Should Be 1.2 } } Context "When there are no Changes" { Mock Get-Version {1.1} Mock Get-NextVersion {1.1} Mock Build {} $result = BuildIfChanged It "Should not build the next version" { Assert-MockCalled Build -Times 0 # -ParameterFilter {$version -eq 1.1} } } } |