From bd26e4197dad847b101fcc0dde4726230306ffdc Mon Sep 17 00:00:00 2001 From: Pim Simons <32359437+pim-simons@users.noreply.github.com> Date: Thu, 18 Aug 2022 06:10:36 +0200 Subject: [PATCH] feat: Add APIM context validation (#317) * added apim context validation * fix apimContext name * Use Get-AzApiManagement to validate if the API Management instance exists * removed tabs Co-authored-by: Pim Simons --- .../Create-AzApiManagementApiOperation.ps1 | 4 + .../Import-AzApiManagementApiPolicy.ps1 | 4 + .../Import-AzApiManagementOperationPolicy.ps1 | 4 + .../Import-AzApiManagementProductPolicy.ps1 | 4 + .../Remove-AzApiManagementDefaults.ps1 | 6 +- .../Set-AzApiManagementApiSubscriptionKey.ps1 | 4 + .../Upload-AzApiManagementCertificate.ps1 | 8 +- .../Arcus.Scripting.ApiManagement.tests.ps1 | 97 +++++++++++++++++++ 8 files changed, 128 insertions(+), 3 deletions(-) diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Create-AzApiManagementApiOperation.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Create-AzApiManagementApiOperation.ps1 index db82e249..14d66784 100644 --- a/src/Arcus.Scripting.ApiManagement/Scripts/Create-AzApiManagementApiOperation.ps1 +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Create-AzApiManagementApiOperation.ps1 @@ -10,6 +10,10 @@ param( [Parameter(Mandatory = $false)][string] $PolicyFilePath = "" ) +$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName +if ($apim -eq $null) { + throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" +} $apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName New-AzApiManagementOperation -Context $apimContext -ApiId $ApiId -OperationId $OperationId -Name $OperationName -Method $Method -UrlTemplate $UrlTemplate -Description $Description diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementApiPolicy.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementApiPolicy.ps1 index 1c7de2a8..52aa9702 100644 --- a/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementApiPolicy.ps1 +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementApiPolicy.ps1 @@ -5,6 +5,10 @@ param( [Parameter(Mandatory = $true)][string] $policyFilePath ) +$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName +if ($apim -eq $null) { + throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" +} $apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName Write-Host "Updating policy of API '$ApiId'" diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementOperationPolicy.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementOperationPolicy.ps1 index c96fc345..6b68494c 100644 --- a/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementOperationPolicy.ps1 +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementOperationPolicy.ps1 @@ -6,6 +6,10 @@ param( [Parameter(Mandatory = $true)][string] $PolicyFilePath ) +$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName +if ($apim -eq $null) { + throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" +} $apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName Write-Host "Updating policy of the operation '$OperationId' in API '$ApiId'" diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementProductPolicy.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementProductPolicy.ps1 index c0334fcc..f65d0122 100644 --- a/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementProductPolicy.ps1 +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Import-AzApiManagementProductPolicy.ps1 @@ -5,6 +5,10 @@ param( [Parameter(Mandatory = $true)][string] $PolicyFilePath ) +$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName +if ($apim -eq $null) { + throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" +} $apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName Write-Host "Updating policy of product '$ProductId'" diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementDefaults.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementDefaults.ps1 index 0f0e5404..4a7c10df 100644 --- a/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementDefaults.ps1 +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementDefaults.ps1 @@ -4,7 +4,11 @@ param( ) Write-Host "Start removing Azure API Management defaults..." -$apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName +$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName +if ($apim -eq $null) { + throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" +} +$apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName $exceptionOccurred = $false $failedActions = @() diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Set-AzApiManagementApiSubscriptionKey.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Set-AzApiManagementApiSubscriptionKey.ps1 index fe6d8363..040cd145 100644 --- a/src/Arcus.Scripting.ApiManagement/Scripts/Set-AzApiManagementApiSubscriptionKey.ps1 +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Set-AzApiManagementApiSubscriptionKey.ps1 @@ -6,6 +6,10 @@ param( [Parameter(Mandatory = $false)][string] $QueryParamName = "apiKey" ) +$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName +if ($apim -eq $null) { + throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" +} $apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName Write-Host "Using API Management instance '$ServiceName' in resource group '$ResourceGroupName'" diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Upload-AzApiManagementCertificate.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Upload-AzApiManagementCertificate.ps1 index 053d8595..f8666012 100644 --- a/src/Arcus.Scripting.ApiManagement/Scripts/Upload-AzApiManagementCertificate.ps1 +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Upload-AzApiManagementCertificate.ps1 @@ -5,9 +5,13 @@ param( [Parameter(Mandatory = $true)][string] $CertificatePassword = $(throw "Password for certificate is required") ) -$context = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName +$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName +if ($apim -eq $null) { + throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" +} +$apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName Write-Host "Using API Management instance '$ServiceName' in resource group '$ResourceGroupName'" Write-Verbose "Uploading private certificate at '$CertificateFilePath'..." -New-AzApiManagementCertificate -Context $context -PfxFilePath $CertificateFilePath -PfxPassword $CertificatePassword +New-AzApiManagementCertificate -Context $apimContext -PfxFilePath $CertificateFilePath -PfxPassword $CertificatePassword Write-Host "Uploaded private certificate at '$CertificateFilePath'" diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 index 81897838..0e64b6b2 100644 --- a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 @@ -169,7 +169,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $method = "POST" $urlTemplate = "https://{host}.com/{path}{query}" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -187,6 +192,8 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled New-AzApiManagementContext -Times 1 Assert-MockCalled New-AzApiManagementOperation -Times 1 Assert-MockCalled Set-AzApiManagementPolicy -Times 0 @@ -203,7 +210,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $description = "API that can process posted orders" $policyFilePath = "/file-path/operation-policy" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -225,6 +237,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled New-AzApiManagementContext -Times 1 Assert-MockCalled New-AzApiManagementOperation -Times 1 Assert-MockCalled Set-AzApiManagementPolicy -Times 1 @@ -238,7 +251,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $productId = "shopping-API" $policyFilePath = "/file-path/operation-policy" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -263,7 +281,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $productId = "shopping-API" $policyFilePath = "/file-path/operation-policy" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -287,7 +310,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $resourceGroup = "shopping" $serviceName = "shopping-API-management" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock Get-AzApiManagementApi { $Context | Should -Be $context return $null } -Verifiable -ParameterFilter { $ApiId -eq "echo-api" } @@ -314,6 +342,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled Get-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Remove-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Get-AzApiManagementProduct -Times 1 -ParameterFilter { $ProductId -eq "starter" } @@ -326,7 +355,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $resourceGroup = "shopping" $serviceName = "shopping-API-management" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock Get-AzApiManagementApi { $Context | Should -Be $context return $null } -Verifiable -ParameterFilter { $ApiId -eq "echo-api" } @@ -340,6 +374,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled Get-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Remove-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } } @@ -348,7 +383,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $resourceGroup = "shopping" $serviceName = "shopping-API-management" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock Get-AzApiManagementApi { $Context | Should -Be $context return $null } -Verifiable -ParameterFilter { $ApiId -eq "echo-api" } @@ -369,6 +409,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled Get-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Remove-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Get-AzApiManagementProduct -Times 1 -ParameterFilter { $ProductId -eq "starter" } @@ -379,7 +420,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $resourceGroup = "shopping" $serviceName = "shopping-API-management" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock Get-AzApiManagementApi { $Context | Should -Be $context return $null } -Verifiable -ParameterFilter { $ApiId -eq "echo-api" } @@ -407,6 +453,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled Get-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Remove-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Get-AzApiManagementProduct -Times 1 -ParameterFilter { $ProductId -eq "starter" } @@ -419,7 +466,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $resourceGroup = "shopping" $serviceName = "shopping-API-management" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock Get-AzApiManagementApi { $Context | Should -Be $context $errorDetails = '{"code": 1, "message": "NotFound", "more_info": "", "status": 404}' @@ -452,6 +504,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled Get-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Get-AzApiManagementProduct -Times 1 -ParameterFilter { $ProductId -eq "starter" } Assert-MockCalled Remove-AzApiManagementProduct -Times 1 -ParameterFilter { $ProductId -eq "starter" } @@ -463,7 +516,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $resourceGroup = "shopping" $serviceName = "shopping-API-management" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock Get-AzApiManagementApi { $Context | Should -Be $context return $null } -Verifiable -ParameterFilter { $ApiId -eq "echo-api" } @@ -495,6 +553,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled Get-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Remove-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Get-AzApiManagementProduct -Times 1 -ParameterFilter { $ProductId -eq "starter" } @@ -506,7 +565,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $resourceGroup = "shopping" $serviceName = "shopping-API-management" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock Get-AzApiManagementApi { $Context | Should -Be $context return $null } -Verifiable -ParameterFilter { $ApiId -eq "echo-api" } @@ -538,6 +602,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled Get-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Remove-AzApiManagementApi -Times 1 -ParameterFilter { $ApiId -eq "echo-api" } Assert-MockCalled Get-AzApiManagementProduct -Times 1 -ParameterFilter { $ProductId -eq "starter" } @@ -553,7 +618,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $apiId = "shopping-API" $policyFilePath = "/file-path/operation-policy" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -577,7 +647,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $apiId = "shopping-API" $policyFilePath = "/file-path/operation-policy" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -594,6 +669,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Assert Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 Assert-MockCalled New-AzApiManagementContext -Times 1 Assert-MockCalled Set-AzApiManagementPolicy -Times 1 } @@ -607,7 +683,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $operationId = "orders" $policyFilePath = "/file-path/operation-policy" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -633,7 +714,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $operationId = "orders" $policyFilePath = "/file-path/operation-policy" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -842,7 +928,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $apiKeyHeaderName = "header-name" $apiKeyQueryParamName = "query-param-name" $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup $ServiceName | Should -Be $serviceName @@ -869,6 +960,12 @@ InModuleScope Arcus.Scripting.ApiManagement { $filePath = "c:\temp\certificate.pfx" $password = "P@ssw0rd" $stubContext = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable Mock New-AzApiManagementContext { $ResourceGroupName | Should -Be $resourceGroup