Skip to content

Instantly share code, notes, and snippets.

@brantb
Last active March 22, 2016 19:44
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 brantb/77013b44e791ce762f24 to your computer and use it in GitHub Desktop.
Save brantb/77013b44e791ce762f24 to your computer and use it in GitHub Desktop.
Describe 'Mocking Azure Powershell cmdlets' {
Mock New-AzureRmResource { Write-Host "Mock invoked" }
It 'Does not throw an exception' {
New-AzureRmResource -Properties @{} -ResourceId foo
}
}
<#
Without running Login-AzureRmAccount:
Describing Mocking Azure Powershell cmdlets
[-] Does not throw an exception 41ms
PSInvalidOperationException: Run Login-AzureRmAccount to login.
MethodInvocationException: Exception calling ".ctor" with "0" argument(s): "Run Login-AzureRmAccount to login."
CmdletInvocationException: Exception calling ".ctor" with "0" argument(s): "Run Login-AzureRmAccount to login."
ParameterBindingException: Cannot retrieve the dynamic parameters for the cmdlet. Exception calling ".ctor" with "0" argument(s): "Run Login-AzureRmAccount to login."
at <ScriptBlock>, C:\users\brant\Desktop\Pester.Tests.ps1: line 5
After running Login-AzureRmAccount:
Describing Mocking Azure Powershell cmdlets
Mock invoked
[+] Does not throw an exception 43ms
Tests completed in 43ms
Passed: 1 Failed: 0 Skipped: 0 Pending: 0 Inconclusive: 0
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment