Skip to content

Instantly share code, notes, and snippets.

@PlagueHO
Created December 23, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlagueHO/ab32cf7c028dfb0c0f87 to your computer and use it in GitHub Desktop.
Save PlagueHO/ab32cf7c028dfb0c0f87 to your computer and use it in GitHub Desktop.
Example DSC Test for Custom Exception
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