Last active
February 24, 2016 17:12
-
-
Save adamdriscoll/31bab7cf1e40a8652f45 to your computer and use it in GitHub Desktop.
Mocking with Pester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remove-Module 'Smlets' | |
Import-Module 'C:\Program Files\Common Files\SMLets\SMLets.psd1' -Force | |
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | |
Import-Module (Join-Path $here "ScsmBulkOperations.psd1") -Force | |
Describe "Move-ScsmObject" { | |
$Session = New-ScsmMigrationSession -SourceComputerName 'SourceComp' -TargetComputerName 'TargetComp' | |
Context "When classes differ between source and target SCSM (number of properties) and strict specified" { | |
Mock Get-ScsmClass -ModuleName 'ScsmBulkOperations' -MockWith { @{ PropertyCollection = @() }} | |
Mock Get-ScsmClass -ModuleName 'ScsmBulkOperations' -ParameterFilter { $ComputerName -eq 'SourceComp' -and $ClassName -eq 'TestClass' } -MockWith { @{ | |
PropertyCollection = 1..5 | |
} } | |
Mock Get-ScsmClass -ModuleName 'ScsmBulkOperations' -ParameterFilter { $ComputerName -eq 'TargetComp' -and $ClassName -eq 'TestClass' } -MockWith { @{ | |
PropertyCollection = 1..6 | |
} } | |
It "Should throw an error" { | |
{ Move-ScsmObject -ClassName 'TestClass' -Session $Session -Strict } | Should throw "Source and target property sets do not match." | |
} | |
} | |
} | |
# | |
# [-] Should throw an error 2.37s | |
# Expected: the expression to throw an exception with message {Source and target property sets do not match.}, an exception was raised, message was {No such host is known} | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment