Created
December 23, 2015 07:29
-
-
Save PlagueHO/ab32cf7c028dfb0c0f87 to your computer and use it in GitHub Desktop.
Example DSC Test for Custom Exception
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
Context 'Virtual Disk exists and should but has a different ParentPath' { | |
Mock Get-iSCSIVirtualDisk -MockWith { return @($MockVirtualDisk) } | |
It 'should throw an iSCSIVirtualDiskRequiresRecreateError exception' { | |
$Splat = $TestVirtualDisk.Clone() | |
$Splat.ParentPath = 'c:\NewParent.vhdx' | |
$errorId = 'iSCSIVirtualDiskRequiresRecreateError' | |
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument | |
$errorMessage = $($LocalizedData.iSCSIVirtualDiskRequiresRecreateError) -f $Splat.Path | |
$exception = New-Object -TypeName System.InvalidOperationException ` | |
-ArgumentList $errorMessage | |
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord ` | |
-ArgumentList $exception, $errorId, $errorCategory, $null | |
{ Test-TargetResource @Splat } | Should Throw $errorRecord | |
} | |
It 'should call expected Mocks' { | |
Assert-MockCalled -commandName Get-iSCSIVirtualDisk -Exactly 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment