Skip to content

Mocking Azure AcquireAccessToken #2274

Answered by fflaten
JamSpot asked this question in Q&A
Discussion options

You must be logged in to vote

I'd try mocking New-Object and return a mocked object with the necessary method and output. Ex.

Describe 'd' {
    It 'i' {
        # Create mocked RMProfileClient with required method and output
        Mock -CommandName 'New-Object' -ParameterFilter { $TypeName -eq 'Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient' } -MockWith {
            $p = @{
                Type   = 'Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient'
                Methods = @{
                    AcquireAccessToken = { param($TenantId) @{ AccessToken = "myFakeTokenForTenant$TenantId" } }
                }
            }
            New-MockObject @p
        }

        # Not sure why …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fflaten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants