From 055ffb102f1e4258a97bc0a6c4c21f516a8304cf Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Fri, 4 Jun 2021 11:17:08 +0200 Subject: [PATCH 01/12] Provide script to upload schemas into an Integration Account + docs. Related to #160 in Arcus.Scripting --- .../powershell/azure-integration-account.md | 89 ++++++++++++++++++ docs/preview/index.md | 1 + .../Arcus.Scripting.IntegrationAccount.psd1 | Bin 0 -> 7710 bytes .../Arcus.Scripting.IntegrationAccount.psm1 | 44 +++++++++ ...Arcus.Scripting.IntegrationAccount.pssproj | 40 ++++++++ .../Set-AzIntegrationAccountSchemas.ps1 | 81 ++++++++++++++++ 6 files changed, 255 insertions(+) create mode 100644 docs/preview/features/powershell/azure-integration-account.md create mode 100644 src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psd1 create mode 100644 src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1 create mode 100644 src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.pssproj create mode 100644 src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 diff --git a/docs/preview/features/powershell/azure-integration-account.md b/docs/preview/features/powershell/azure-integration-account.md new file mode 100644 index 00000000..fc74f65d --- /dev/null +++ b/docs/preview/features/powershell/azure-integration-account.md @@ -0,0 +1,89 @@ +--- +title: "Scripts related to interacting with an Azure Integration Account" +layout: default +--- + +# Azure Integration Account + +This module provides the following capabilities: +- [Uploading schemas into an Azure Integration Account](#uploading-schemas-into-an-azure-integration-account) + +## Installation + +To have access to the following features, you have to import the module: + +```powershell +PS> Install-Module -Name Arcus.Scripting.IntegrationAccount +``` + +## Uploading schemas into an Azure Integration Account + +Upload/update a single, or multiple schemas into an Azure Integration Account. + +| Parameter | Mandatory | Description | +| ---------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| `ResourceGroupName` | yes | The name of the Azure resource group where the Azure Integration Account is located. | +| `Name` | yes | The name of the Azure Integration Account into which the schemas are to be uploaded/updated. | +| `SchemaFilePath` | no | The full path of a schema that should be uploaded/updated. (Mandatory if SchemasFolder has not been specified). | +| `SchemasFolder` | no | The path to a directory containing all schemas that should be uploaded/updated. (Mandatory if SchemaFilePath has not been specified). | +| `ArtifactsPrefix` | no | The prefix, if any, that should be added to the schemas before uploading/updating. | +| `RemoveFileExtensions` | no | Indicator (switch) whether the extension should be removed from the name before uploading/updating. | + +**Example** + +Uploading a *single schema* into an Integration Account. +```powershell +PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd" +# Uploading schema 'MySchema.xsd' into the Integration Account 'my-integration-account' +# Schema 'MySchema.xsd' has been uploaded into the Integration Account. +``` + +Uploading a *single schema* into an Integration Account and remove the file-extension. +```powershell +PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd" -RemoveFileExtensions +# Uploading schema 'MySchema' into the Integration Account 'my-integration-account' +# Schema 'MySchema' has been uploaded into the Integration Account. +``` +Uploading a *single schema* into an Integration Account and set add a prefix to the name of the schema within the Integration Account. +```powershell +PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd" -ArtifactsPrefix 'dev-' +# Uploading schema 'dev-MySchema.xsd' into the Integration Account 'my-integration-account' +# Schema 'dev-MySchema.xsd' has been uploaded into the Integration Account. +``` + +Uploading *all schemas* located in a specific folder into an Integration Account. +```powershell +PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas" +# Uploading schema 'MyFirstSchema.xsd' into the Integration Account 'my-integration-account' +# Schema 'MyFirstSchema.xsd' has been uploaded into the Integration Account. +# ---------- +# Uploading schema 'MySecondSchema.xsd' into the Integration Account 'my-integration-account' +# Schema 'MySecondSchema.xsd' has been uploaded into the Integration Account. +# ---------- +``` + +Uploading *all schemas* located in a specific folder into an Integration Account and remove the file-extension. +```powershell +PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas" -RemoveFileExtensions +# Uploading schema 'MyFirstSchema' into the Integration Account 'my-integration-account' +# Schema 'MyFirstSchema' has been uploaded into the Integration Account. +# ---------- +# Uploading schema 'MySecondSchema' into the Integration Account 'my-integration-account' +# Schema 'MySecondSchema' has been uploaded into the Integration Account. +# ---------- +``` + +Uploading *all schemas* located in a specific folder into an Integration Account and remove the file-extension. +```powershell +PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas" -ArtifactsPrefix 'dev-' +# Uploading schema 'dev-MyFirstSchema.xsd' into the Integration Account 'my-integration-account' +# Schema 'dev-MyFirstSchema.xsd' has been uploaded into the Integration Account. +# ---------- +# Uploading schema 'dev-MySecondSchema.xsd' into the Integration Account 'my-integration-account' +# Schema 'dev-MySecondSchema.xsd' has been uploaded into the Integration Account. +# ---------- +``` + + + + diff --git a/docs/preview/index.md b/docs/preview/index.md index de9fcdde..26f2003d 100644 --- a/docs/preview/index.md +++ b/docs/preview/index.md @@ -21,6 +21,7 @@ For more granular packages we recommend reading the documentation. * Automate Azure API Management tasks ([powershell](features/powershell/azure-api-management)) * Automate Azure Data Factory tasks ([powershell](features/powershell/azure-data-factory)) * Automate Azure DevOps tasks ([powershell](features/powershell/azure-devops)) +* Automate Azure Integration Account tasks ([powershell](features/powershell/azure-integration-account)) * Automate Azure Key Vault tasks ([powershell](features/powershell/azure-key-vault)) * Automate Azure Logic Apps tasks ([powershell](features/powershell/azure-logic-apps)) * Automate Azure Resource Manager (ARM) tasks ([powershell](features/powershell/arm)) diff --git a/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psd1 b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psd1 new file mode 100644 index 0000000000000000000000000000000000000000..c94fe1660ad633fc10182cfdcb8e54fb2d12d9c5 GIT binary patch literal 7710 zcmc(kYi}Ay6o%(>rTzybD&bT$#Ez3Tl`4h!l2~%m$Z^ts#egZT4FvF|sq)v`zRw&c zGqWrNoVXRjyX?-KdCz;UGydoAs{7h~<*KgYUbvy_xJ!5Ly83nDT5jO_?o7WXZmK6| zdO!AW(s4D7jK6C$X+h>Q%^v7Gmb9s^9nC*=f4U!aZR%-T>rGaeGn5qOJaP@Uqwlu6 zukV(ge6Q!*?g#ySptneUk;ntb6Ze;Y5-`2is$*$3@>-?nD>DsG^>!e{V~>(|u%rg{ABYs5U4b&uy*bB7w0^Zt{@*Ai~(F2xJ3o~yelVZ_)gcZSjQTD`4B!e)!mtYlJXp} zqU|&HMob~sa6NUq@{%omcJ$qLoAR5-@}x()+j0B4f2up49O%uad}~ji$No)I&mOpk z8n;_O-V{18SadAo4@~*!qP25Qb|v#dRwNS9-B!5r`gc}bFPHIBvMw|~Ffza1NGlN? zJ!wSL6Z_`f%!Bus2^KTYszphr>xR7Io@7`A-`8Et19kuFT$ZjR7>J;;*2Xi&4(&Vg zryTj7e;?yI_;$1gI-hxeYD))u-_lA%E8LDGdnoDVUm;KBQJj0%qBTv=G-`te=QAde zZvNeL?}Z8NDhpy7e$uGU^?o6|M977tTu27&jKx&B{=fLqc+R!PR1~A!G2^wYO@zTb zR_^(cpaL85*Y|g;@KPoJ4hF!FpRGa@q!-@PU7 zQk!y%+(svSkjR61Y(|EtyO+wEC%QY(8_PM@dOKD{xQ$O?n?22+N^Vzw=cRr*eaLEf zK9%%BAFGnYE^%?GD-{hbtj-dB{N7MyIC956yWP(FZ2l^myz+dvwXXFb^kwubZDA*) zb#*rtKFcf{Vht_2?mLb9RkiJrziSG4NB29Qfq5Q@%E%ZUR_~16~ew`EY}%rTE62U^WFvSazy3m)0!4LVKmrK#M5nV zc~6Qq#3y5{U_(02V6C>d6Z?&^>N#?#Jzv^l*0o}@6#qooX{ZW_Z-h8nWVI7@2qUjY z=>Bt^Z)DH&ndWq@=C8T!u6L+ojEWPS{&fodTYs7UeN@;HyaN zNx^OUcHNCITE4@Acq%;}(G&KSQC|?u%L3_sCMTe%DH^Dxo9Zv$FX%n<&Xee&GU8Jc z#cQ6~cJ;iYC_v`t=#a}P$6s^b7W)6U!bDDQ`MeskDzUgei}SKpMbY#*9di1ZN{bbykQ&-B*EOOtfYFz5kakb!4xj)4BIhr&R-5$w-bj8== zD&;81?|oGi+rd`kq1?5k%Tz2G7j#hJcc@G$XLpe+a$I{KQJEI;ys9E(d|oM9KRqgp zu4=}KWcIvfEm?fzJu^L7DbFJ8z)yUXRD?mWhzGIr)Y6s6V?e=xN7SAMjhReuI3lP z55P}%Fz_)=77krwSq?7O2p^3y-gy1P4wy5Rsra4f{Ia1B`)=00R358q78$=G=E6zo zrtSkD>GQfIq^BS3R2n`P(hWCeIh#5;)~_S6xU0JGQeL&6WYWM%xGv|0I$)OO4B=D= zZ0AwN5}oVN{jPCTx^kYZ7Yk$lJD%3{4fcU_aae~tI$ZQ4=i3Pxtn|Dut?ngv&JmKiJO_*R9O=={473>&+#^6n*g zUAQimWSQY^V+VUiJtks;xFj#F^X;HfxK_mm-cB^8tJrBP`O*AmUB(v6HO7`( z?m+sYVaS1?zzf)=VMA&F{h#GV+dJDyNnR1qDejE1y!Bv~OUV)8oZn6@INcQlp#6-`jI`qDQ+i2}I!LgWkZ;zDF7&Gw(4t zg_+3SaL-vq%EhAjX|EN#mBo?*yI^^)73ee$g^4O_75PxtPcc?Dn`+KnIH)BVi?J|< zh51h>zG%6dzVt@FLWQ^5OO3;t(Tmgbr%&z4=%#+2^+j-lR}ftmHT+tPgRCC%z@h4Q k*a>cCU3f+NH_If3Kc02uTJDNP&N5A#bjCbKA3l2hzg55D)c^nh literal 0 HcmV?d00001 diff --git a/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1 b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1 new file mode 100644 index 00000000..6144e691 --- /dev/null +++ b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1 @@ -0,0 +1,44 @@ +<# + .Synopsis + Upload/update a single, or multiple schemas into an Azure Integration Account. + + .Description + Provide a file- or folder-path to upload/update a single or multiple schemas into an Integration Account. + + .Parameter ResourceGroupName + The name of the Azure resource group where the Azure Integration Account is located. + + .Parameter Name + The name of the Azure Integration Account into which the schemas are to be uploaded/updated. + + .Parameter SchemaFilePath + The full path of a schema that should be uploaded/updated. + + .Parameter SchemasFolder + The path to a directory containing all schemas that should be uploaded/updated. + + .Parameter ArtifactsPrefix + The prefix, if any, that should be added to the schemas before uploading/updating. + + .Parameter RemoveFileExtensions + Indicator whether the extension should be removed from the name before uploading/updating. + +#> +function Set-AzIntegrationAccountSchemas { + param( + [Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Resource group name is required"), + [Parameter(Mandatory = $true)][string] $Name = $(throw "Name of the Integration Account is required"), + [parameter(Mandatory = $false)][string] $SchemaFilePath = $(if ($SchemasFolder -eq '') { throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" }), + [parameter(Mandatory = $false)][string] $SchemasFolder = $(if ($SchemaFilePath -eq '') { throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" }), + [Parameter(Mandatory = $false)][string] $ArtifactsPrefix = '', + [Parameter(Mandatory = $false)][switch] $RemoveFileExtensions = $false + ) + + if($RemoveFileExtensions) { + . $PSScriptRoot\Scripts\Set-AzIntegrationAccountSchemas.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -SchemaFilePath $SchemaFilePath -SchemasFolder $SchemasFolder -ArtifactsPrefix $ArtifactsPrefix -RemoveFileExtensions + } else { + . $PSScriptRoot\Scripts\Set-AzIntegrationAccountSchemas.ps1 -ResourceGroupName $ResourceGroupName -Name $Name -SchemaFilePath $SchemaFilePath -SchemasFolder $SchemasFolder -ArtifactsPrefix $ArtifactsPrefix + } +} + +Export-ModuleMember -Function Set-AzIntegrationAccountSchemas diff --git a/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.pssproj b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.pssproj new file mode 100644 index 00000000..52fc8d7f --- /dev/null +++ b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.pssproj @@ -0,0 +1,40 @@ + + + Debug + 2.0 + {AFCEA845-372E-4000-85FD-5672D7551527} + Exe + Arcus.Scripting.IntegrationAccount + Arcus.Scripting.IntegrationAccount + Arcus.Scripting.IntegrationAccount + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 b/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 new file mode 100644 index 00000000..4cadfdf5 --- /dev/null +++ b/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 @@ -0,0 +1,81 @@ +Param( + [Parameter(Mandatory = $true)][string] $ResourceGroupName = $(throw "Resource group name is required"), + [Parameter(Mandatory = $true)][string] $Name = $(throw "Name of the Integration Account is required"), + [parameter(Mandatory = $false)][string] $SchemaFilePath = $(if ($SchemasFolder -eq '') { throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" }), + [parameter(Mandatory = $false)][string] $SchemasFolder = $(if ($SchemaFilePath -eq '') { throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" }), + [Parameter(Mandatory = $false)][string] $ArtifactsPrefix = '', + [Parameter(Mandatory = $false)][switch] $RemoveFileExtensions = $false +) + +if ($SchemaFilePath -ne '' -and $SchemasFolder -ne '') { + throw "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" +} + +function UploadSchema { + param + ( + [System.IO.FileInfo][parameter(Mandatory = $true)]$Schema + ) + + $schemaName = $Schema.Name + if ($RemoveFileExtensions) { + $schemaName = $Schema.BaseName + } + if ($ArtifactsPrefix -ne '') { + $schemaName = $ArtifactsPrefix + $schemaName + } + Write-Host "Uploading schema '$schemaName' into the Integration Account '$Name'" + + ## Check if the schema already exists + $existingSchema = $null + try { + Write-Verbose "Checking if the schema '$schemaName' already exists in the Integration Account." + $existingSchema = Get-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -ErrorAction Stop + } + catch { + if ($_.Exception.Message.Contains('could not be found')) { + Write-Verbose "Schema '$schemaName' could not be found." + } + else { + throw $_.Exception + } + } + + try { + if ($existingSchema -eq $null) { + # Create the schema + Write-Verbose "Creating schema '$schemaName'" + $createdSchema = New-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -SchemaFilePath $schema.FullName -ErrorAction Stop + Write-Verbose ($createdSchema | Format-List -Force | Out-String) + } + else { + # Update the schema + Write-Verbose "Updating schema '$schemaName'" + $updatedSchema = Set-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -SchemaFilePath $schema.FullName -ErrorAction Stop -Force + Write-Verbose ($updatedSchema | Format-List -Force | Out-String) + } + Write-Host "Schema '$schemaName' has been uploaded into the Integration Account." + } + catch { + Write-Error "Failed to upload schema '$schemaName' in Integration Account '$Name': '$($_.Exception.Message)_'" + } +} + +# Verify if Integration Account can be found based on the given information +$integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue +if ($integrationAccount -eq $null) { + Write-Error "Unable to find the the Integration Account with name '$Name' in resource group '$ResourceGroupName'" +} +else { + if ($SchemasFolder -ne '' -and $SchemaFilePath -eq '') { + foreach ($schema in Get-ChildItem("$schemasFolder") -File) { + UploadSchema -Schema $schema + Write-Host '----------' + } + } + elseif ($schemasFolder -eq '' -and $SchemaFilePath -ne '') { + [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + UploadSchema -Schema $schema + } +} + From bda15c6e556ed8f976c9287c7d45c2a8f0d0c957 Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Fri, 4 Jun 2021 17:41:51 +0200 Subject: [PATCH 02/12] Integration Account Schemas: add integration tests. Related to #160 on Arcus.Scripting --- .../Arcus.Scripting.IntegrationAccount.psd1 | Bin 7710 -> 7646 bytes .../Set-AzIntegrationAccountSchemas.ps1 | 2 +- ...cus.Scripting.IntegrationAccount.tests.ps1 | 178 ++++++++++++++++++ .../Schemas/Acknowledgement.xsd | Bin 0 -> 1300 bytes .../Schemas/Common/NestedSchemaRoot.xsd | Bin 0 -> 2022 bytes .../Schemas/NestedSchema.xsd | Bin 0 -> 1022 bytes .../appsettings.json | Bin 714 -> 890 bytes 7 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 create mode 100644 src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/Acknowledgement.xsd create mode 100644 src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/Common/NestedSchemaRoot.xsd create mode 100644 src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/NestedSchema.xsd diff --git a/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psd1 b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psd1 index c94fe1660ad633fc10182cfdcb8e54fb2d12d9c5..f9e2e6d24c8867b09ebc99c332bb689d1a488eeb 100644 GIT binary patch delta 33 lcmbPdbI*E17!#`jgC2w7=4z(hVi4x!x03Rkt0b4O0061A3CjQg delta 97 zcmca-JmLpG31XGmqxV+aG1MGVCZnGE?1c?`7-%A2E^c8d|G Obn;qB`OQ|6OIQF+kQPY* diff --git a/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 b/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 index 4cadfdf5..cd8b7b8c 100644 --- a/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 +++ b/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 @@ -64,7 +64,7 @@ function UploadSchema { # Verify if Integration Account can be found based on the given information $integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue if ($integrationAccount -eq $null) { - Write-Error "Unable to find the the Integration Account with name '$Name' in resource group '$ResourceGroupName'" + Write-Error "Unable to find the Integration Account with name '$Name' in resource group '$ResourceGroupName'" } else { if ($SchemasFolder -ne '' -and $SchemaFilePath -eq '') { diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 new file mode 100644 index 00000000..57a7e7ca --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -0,0 +1,178 @@ +Import-Module Az.KeyVault +Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.IntegrationAccount -ErrorAction Stop + +InModuleScope Arcus.Scripting.IntegrationAccount { + Describe "Arcus Azure Integration Account integration tests" { + BeforeEach { + $filePath = "$PSScriptRoot\appsettings.json" + [string]$appsettings = Get-Content $filePath + $config = ConvertFrom-Json $appsettings + + $clientSecret = ConvertTo-SecureString $config.Arcus.ServicePrincipal.ClientSecret -AsPlainText -Force + $pscredential = New-Object -TypeName System.Management.Automation.PSCredential($config.Arcus.ServicePrincipal.ClientId, $clientSecret) + Disable-AzContextAutosave -Scope Process + Connect-AzAccount -Credential $pscredential -TenantId $config.Arcus.TenantId -ServicePrincipal + } + Context "Handling Schemas" { + It "Create a single schema in an Integration Account" { + # Arrange + $resourceGroupName = $config.Arcus.ResourceGroupName + $integrationAccountName = $config.Arcus.IntegrationAccount.Name + $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" + [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + $expectedSchemaName = $schema.Name + $executionDateTime = Get-Date + + try { + # Act + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schema.FullName + + # Assert + $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName + $actual | Should -Not -BeNullOrEmpty + $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") + $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + + } finally { + Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force + } + } + It "Create a single schema, without extension, in an Integration Account" { + # Arrange + $resourceGroupName = $config.Arcus.ResourceGroupName + $integrationAccountName = $config.Arcus.IntegrationAccount.Name + $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" + [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + $expectedSchemaName = $schema.BaseName + $executionDateTime = Get-Date + + try { + # Act + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schema.FullName -RemoveFileExtensions + + # Assert + $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName + $actual | Should -Not -BeNullOrEmpty + $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") + $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + + } finally { + Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force + } + } + It "Create a single schema, without extension and with prefix, in an Integration Account" { + # Arrange + $resourceGroupName = $config.Arcus.ResourceGroupName + $integrationAccountName = $config.Arcus.IntegrationAccount.Name + $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" + [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + $artifactsPrefix = "dev-" + $expectedSchemaName = $artifactsPrefix + $schema.BaseName + $executionDateTime = Get-Date + + try { + # Act + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schema.FullName -ArtifactsPrefix $artifactsPrefix -RemoveFileExtensions + + # Assert + $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName + $actual | Should -Not -BeNullOrEmpty + $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") + $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + + } finally { + Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force + } + } + It "Create multiple schemas located in a folder in an Integration Account" { + # Arrange + $resourceGroupName = $config.Arcus.ResourceGroupName + $integrationAccountName = $config.Arcus.IntegrationAccount.Name + $schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas" + $executionDateTime = Get-Date + + try { + # Act + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemasFolder $schemasFolder + + # Assert + foreach ($schema in Get-ChildItem("$schemasFolder") -File) { + $expectedSchemaName = $schema.Name + + $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName + $actual | Should -Not -BeNullOrEmpty + $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") + $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + } + + } finally { + foreach ($schema in Get-ChildItem("$schemasFolder") -File) { + $expectedSchemaName = $schema.Name + + Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force + } + } + } + It "Create multiple schemas, without extension, located in a folder in an Integration Account" { + # Arrange + $resourceGroupName = $config.Arcus.ResourceGroupName + $integrationAccountName = $config.Arcus.IntegrationAccount.Name + $schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas" + $executionDateTime = Get-Date + + try { + # Act + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemasFolder $schemasFolder -RemoveFileExtensions + + # Assert + foreach ($schema in Get-ChildItem("$schemasFolder") -File) { + $expectedSchemaName = $schema.BaseName + + $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName + $actual | Should -Not -BeNullOrEmpty + $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") + $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + } + + } finally { + foreach ($schema in Get-ChildItem("$schemasFolder") -File) { + $expectedSchemaName = $schema.BaseName + + Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force + } + } + } + It "Create multiple schemas, without extension and with prefix, located in a folder in an Integration Account" { + # Arrange + $resourceGroupName = $config.Arcus.ResourceGroupName + $integrationAccountName = $config.Arcus.IntegrationAccount.Name + $schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas" + $artifactsPrefix = "dev-" + $executionDateTime = Get-Date + + try { + # Act + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemasFolder $schemasFolder -ArtifactsPrefix $artifactsPrefix -RemoveFileExtensions + + # Assert + foreach ($schema in Get-ChildItem("$schemasFolder") -File) { + $expectedSchemaName = $artifactsPrefix + $schema.BaseName + + $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName + $actual | Should -Not -BeNullOrEmpty + $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") + $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + } + + } finally { + foreach ($schema in Get-ChildItem("$schemasFolder") -File) { + $expectedSchemaName = $artifactsPrefix + $schema.BaseName + + Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force + } + } + } + + } + } +} \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/Acknowledgement.xsd b/src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/Acknowledgement.xsd new file mode 100644 index 0000000000000000000000000000000000000000..1f9902989cd01c791fee9b0fd9444db9588ed450 GIT binary patch literal 1300 zcmcJP%TB^j5QhJ?iSIzz%S96x1R-8FCh7(kZV@XGXp8h<(T7*RIi9ZT#3et73oY>HC0oC{|b>v1J<92MjHC)LQc;*BI}f#t~xr@ zf!fqd)Z#bLh<%~@?9VVFR;})colY~d>RcDPR}Z9KX-Bf*{has&^jIl;1Go%*edFdl z%L1jP#|=njPKFSoW`O1xUNKr6Yo;>vtj2nWSs$zk@5eaN(22)!tj;~U(;d$tJQDQu z*&S@a-H$@^`L~-X?xg5Q;aWqB@yyvbd3w;TZq~f6t~yttPkHwO@384IZ!6q0m4>&g z57``8wQ|MG*O{-o#Md|c3QEX7^An;kT6hNL>U!0m+1vQ$ST@IQg=;$UIdyoHO|@mz z|AEwl@4(MMLT~nucj@~($DJwtajTPi&B@q5_7$jhp3J-1H}>Cg+c=+hWLxKpyj>Gj QWUfy~{+%lDiZ4}1UrU|R%m4rY literal 0 HcmV?d00001 diff --git a/src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/Common/NestedSchemaRoot.xsd b/src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/Common/NestedSchemaRoot.xsd new file mode 100644 index 0000000000000000000000000000000000000000..ff17b8f30c1703e6ab4cd3bb7bd9a0c03a54be97 GIT binary patch literal 2022 zcmchYOHbQC6otZxTT2BH|&j4pagbU38N;PKm&e#tser@wDHa!SXmZAr(>- zIkso+oqNu?5C45V)1}r*^rW7i6>F(N3uQ`mt|J|*uOasyJE>2_BtHP;uc zzG8E!3mxh}XPj4P#1-iQzeE%KeTik*tc!B+3&xSHns7*E$ah1a~Do#>1WA%Duou?6t5~R zrjukIBLmg{|LScyH=ko#1Cf?#@{=8(zp>ykQ&Ww_x{|RxYCDt$Av# ziRZZu-xc+dF^7s4w(68H?yfkye0Rg#<++L9X8&5>sMrV%?Au~Wuh4x87rW2U#P_SO zaohLvbi{YTGk&j|}19YK1 A3;+NC literal 0 HcmV?d00001 diff --git a/src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/NestedSchema.xsd b/src/Arcus.Scripting.Tests.Integration/Files/IntegrationAccount/Schemas/NestedSchema.xsd new file mode 100644 index 0000000000000000000000000000000000000000..57a0b1797b040d016981c3716b9d64d91af4ddd9 GIT binary patch literal 1022 zcmcJOOHaa35QWd$#Q)H+mxm-S2ts77Y+&IQYZan>NH2>1c=emxHmyi7(U_*~?VXu3 z=bX9ycpqx4tztbY(6b_~m20I`iO$thPi=L12SgHu?B5bibnl}ZIo;`mtTS@P8tGU^ z8iJQ=z#VEyU91K5MURAC!(CG8l#$ipnrN;Woo0=Se9!k3w4AyK7R_AaSK|+Kv!_Rs zjbX>=2vM7Yn4-e5XZm8#XQekdEpX+5?^8VJs_%Vp?5@!tQ88s5drldvkk$WdGjG3l zd68Xh?mo}dGpu;`P;jj)UG8{ROe?^{u%5qJV&il#TI`gYj)gM{+tN+Q7J^_ZNr5*qP literal 0 HcmV?d00001 diff --git a/src/Arcus.Scripting.Tests.Integration/appsettings.json b/src/Arcus.Scripting.Tests.Integration/appsettings.json index 0f5d55805a2c54d1201fdfe4bc050accfbfd686b..22d355303a45f68367447e9af41fbf0bc8a10495 100644 GIT binary patch delta 97 zcmX@b`ipJDHm1o^OajWD40#MC45 Date: Mon, 7 Jun 2021 08:12:04 +0200 Subject: [PATCH 03/12] Resolve issue with hidden/invalid char --- .../Arcus.Scripting.IntegrationAccount.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 index 57a7e7ca..81c84558 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -7,7 +7,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $filePath = "$PSScriptRoot\appsettings.json" [string]$appsettings = Get-Content $filePath $config = ConvertFrom-Json $appsettings - + $clientSecret = ConvertTo-SecureString $config.Arcus.ServicePrincipal.ClientSecret -AsPlainText -Force $pscredential = New-Object -TypeName System.Management.Automation.PSCredential($config.Arcus.ServicePrincipal.ClientId, $clientSecret) Disable-AzContextAutosave -Scope Process From 06158316c522dbce698a1e6da5c12f32b333b07d Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Tue, 8 Jun 2021 15:08:40 +0200 Subject: [PATCH 04/12] Integration Test: Add missing test-case. --- .../Arcus.Scripting.IntegrationAccount.tests.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 index 81c84558..be1428c4 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -14,6 +14,22 @@ InModuleScope Arcus.Scripting.IntegrationAccount { Connect-AzAccount -Credential $pscredential -TenantId $config.Arcus.TenantId -ServicePrincipal } Context "Handling Schemas" { + It "Try to upload single schema to unexisting Integration Account" { + # Arrange + $resourceGroupName = $config.Arcus.ResourceGroupName + $integrationAccountName = "unexisting-integration-account" + $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" + [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + + # Act + { + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schema.FullName -ErrorAction Stop + } | Should -Throw + + # Assert + Assert-VerifiableMock + Assert-MockCalled Set-AzKeyVaultSecret -Times 0 + } It "Create a single schema in an Integration Account" { # Arrange $resourceGroupName = $config.Arcus.ResourceGroupName From d67ecc1c5498a5353ec63a4e28f195cca58957b9 Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Tue, 8 Jun 2021 15:31:41 +0200 Subject: [PATCH 05/12] Integration Test: correct assertion --- .../Arcus.Scripting.IntegrationAccount.tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 index be1428c4..73aba82e 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -47,7 +47,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName $actual | Should -Not -BeNullOrEmpty $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") - $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + $actual.CreatedTime | Should -BeGreaterOrEqual $executionDateTime } finally { Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force @@ -70,7 +70,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName $actual | Should -Not -BeNullOrEmpty $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") - $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + $actual.CreatedTime | Should -BeGreaterOrEqual $executionDateTime } finally { Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force @@ -94,7 +94,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName $actual | Should -Not -BeNullOrEmpty $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") - $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + $actual.CreatedTime | Should -BeGreaterOrEqual $executionDateTime } finally { Remove-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName -Force @@ -118,7 +118,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName $actual | Should -Not -BeNullOrEmpty $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") - $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + $actual.CreatedTime | Should -BeGreaterOrEqual $executionDateTime } } finally { @@ -147,7 +147,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName $actual | Should -Not -BeNullOrEmpty $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") - $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + $actual.CreatedTime | Should -BeGreaterOrEqual $executionDateTime } } finally { @@ -177,7 +177,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $actual = Get-AzIntegrationAccountSchema -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaName $expectedSchemaName $actual | Should -Not -BeNullOrEmpty $actual.CreatedTime.ToString("yyyy-MM-ddTHH:mm:ss") | Should -Be $actual.ChangedTime.ToString("yyyy-MM-ddTHH:mm:ss") - $actual.CreatedTime | Should -BeLessOrEqual $executionDateTime + $actual.CreatedTime | Should -BeGreaterOrEqual $executionDateTime } } finally { From 42451b1036778f23c9282f8ab590a4331901f452 Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Tue, 8 Jun 2021 16:00:44 +0200 Subject: [PATCH 06/12] Integration Test: correcting tests --- .../Arcus.Scripting.IntegrationAccount.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 index 73aba82e..89580a13 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -4,7 +4,7 @@ Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.IntegrationAccount -ErrorAc InModuleScope Arcus.Scripting.IntegrationAccount { Describe "Arcus Azure Integration Account integration tests" { BeforeEach { - $filePath = "$PSScriptRoot\appsettings.json" + $filePath = "$PSScriptRoot\appsettings.local.json" [string]$appsettings = Get-Content $filePath $config = ConvertFrom-Json $appsettings From cf0f0f901dff8a938b4d37d5f57f6f28cb709e49 Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Tue, 8 Jun 2021 16:07:23 +0200 Subject: [PATCH 07/12] Integration Test: correcting tests v2 --- .../Arcus.Scripting.IntegrationAccount.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 index 89580a13..73aba82e 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -4,7 +4,7 @@ Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.IntegrationAccount -ErrorAc InModuleScope Arcus.Scripting.IntegrationAccount { Describe "Arcus Azure Integration Account integration tests" { BeforeEach { - $filePath = "$PSScriptRoot\appsettings.local.json" + $filePath = "$PSScriptRoot\appsettings.json" [string]$appsettings = Get-Content $filePath $config = ConvertFrom-Json $appsettings From a6af194a1a1abd96f0fe0bdb7569dc33931b8542 Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Tue, 8 Jun 2021 16:14:43 +0200 Subject: [PATCH 08/12] Integration Test: new attempt to correct tests --- .../Arcus.Scripting.IntegrationAccount.tests.ps1 | 2 +- .../Arcus.Scripting.Tests.Integration.pssproj | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 index 73aba82e..874755f2 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -38,7 +38,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") $expectedSchemaName = $schema.Name $executionDateTime = Get-Date - + try { # Act Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schema.FullName diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj index e739b495..d61de7ed 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Tests.Integration.pssproj @@ -61,6 +61,9 @@ + + + From 349f8b5fce41ed7fd0127ccfa549fc2573abe7dc Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Tue, 8 Jun 2021 16:30:56 +0200 Subject: [PATCH 09/12] Integration Test: this should fix the tests --- .../Arcus.Scripting.IntegrationAccount.tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 index 874755f2..817c7553 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -19,7 +19,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $resourceGroupName = $config.Arcus.ResourceGroupName $integrationAccountName = "unexisting-integration-account" $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" - [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + $schema = Get-ChildItem($schemaFilePath) -File # Act { @@ -35,10 +35,10 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $resourceGroupName = $config.Arcus.ResourceGroupName $integrationAccountName = $config.Arcus.IntegrationAccount.Name $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" - [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + $schema = Get-ChildItem($schemaFilePath) -File $expectedSchemaName = $schema.Name $executionDateTime = Get-Date - + try { # Act Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schema.FullName @@ -58,7 +58,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $resourceGroupName = $config.Arcus.ResourceGroupName $integrationAccountName = $config.Arcus.IntegrationAccount.Name $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" - [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + $schema = Get-ChildItem($schemaFilePath) -File $expectedSchemaName = $schema.BaseName $executionDateTime = Get-Date @@ -81,7 +81,7 @@ InModuleScope Arcus.Scripting.IntegrationAccount { $resourceGroupName = $config.Arcus.ResourceGroupName $integrationAccountName = $config.Arcus.IntegrationAccount.Name $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" - [System.IO.FileInfo]$schema = New-Object System.IO.FileInfo("$SchemaFilePath") + $schema = Get-ChildItem($schemaFilePath) -File $artifactsPrefix = "dev-" $expectedSchemaName = $artifactsPrefix + $schema.BaseName $executionDateTime = Get-Date From 802960b8ac3a92160cb5ac944e9535f5ed883f60 Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Wed, 14 Jul 2021 10:48:09 +0200 Subject: [PATCH 10/12] Resolve remarks based on PR-review. --- .../powershell/azure-integration-account.md | 36 +++++++++--------- .../Arcus.Scripting.IntegrationAccount.psd1 | Bin 7646 -> 7710 bytes .../Arcus.Scripting.IntegrationAccount.psm1 | 1 - .../Set-AzIntegrationAccountSchemas.ps1 | 16 ++++---- ...cus.Scripting.IntegrationAccount.tests.ps1 | 1 - 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/docs/preview/features/powershell/azure-integration-account.md b/docs/preview/features/powershell/azure-integration-account.md index fc74f65d..b4324c74 100644 --- a/docs/preview/features/powershell/azure-integration-account.md +++ b/docs/preview/features/powershell/azure-integration-account.md @@ -34,53 +34,53 @@ Upload/update a single, or multiple schemas into an Azure Integration Account. Uploading a *single schema* into an Integration Account. ```powershell PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd" -# Uploading schema 'MySchema.xsd' into the Integration Account 'my-integration-account' -# Schema 'MySchema.xsd' has been uploaded into the Integration Account. +# Uploading schema 'MySchema.xsd' into the Azure Integration Account 'my-integration-account'. +# Schema 'MySchema.xsd' has been uploaded into the Azure Integration Account 'my-integration-account'. ``` Uploading a *single schema* into an Integration Account and remove the file-extension. ```powershell PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd" -RemoveFileExtensions -# Uploading schema 'MySchema' into the Integration Account 'my-integration-account' -# Schema 'MySchema' has been uploaded into the Integration Account. +# Uploading schema 'MySchema' into the Azure Integration Account 'my-integration-account'. +# Schema 'MySchema' has been uploaded into the Azure Integration Account 'my-integration-account'. ``` Uploading a *single schema* into an Integration Account and set add a prefix to the name of the schema within the Integration Account. ```powershell PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemaFilePath "C:\Schemas\MySchema.xsd" -ArtifactsPrefix 'dev-' -# Uploading schema 'dev-MySchema.xsd' into the Integration Account 'my-integration-account' -# Schema 'dev-MySchema.xsd' has been uploaded into the Integration Account. +# Uploading schema 'dev-MySchema.xsd' into the Azure Integration Account 'my-integration-account'. +# Schema 'dev-MySchema.xsd' has been uploaded into the Azure Integration Account 'my-integration-account'. ``` Uploading *all schemas* located in a specific folder into an Integration Account. ```powershell PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas" -# Uploading schema 'MyFirstSchema.xsd' into the Integration Account 'my-integration-account' -# Schema 'MyFirstSchema.xsd' has been uploaded into the Integration Account. +# Uploading schema 'MyFirstSchema.xsd' into the Azure Integration Account 'my-integration-account'. +# Schema 'MyFirstSchema.xsd' has been uploaded into the Azure Integration Account 'my-integration-account'. # ---------- -# Uploading schema 'MySecondSchema.xsd' into the Integration Account 'my-integration-account' -# Schema 'MySecondSchema.xsd' has been uploaded into the Integration Account. +# Uploading schema 'MySecondSchema.xsd' into the Azure Integration Account 'my-integration-account'. +# Schema 'MySecondSchema.xsd' has been uploaded into the Azure Integration Account 'my-integration-account'. # ---------- ``` Uploading *all schemas* located in a specific folder into an Integration Account and remove the file-extension. ```powershell PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas" -RemoveFileExtensions -# Uploading schema 'MyFirstSchema' into the Integration Account 'my-integration-account' -# Schema 'MyFirstSchema' has been uploaded into the Integration Account. +# Uploading schema 'MyFirstSchema' into the Azure Integration Account 'my-integration-account'. +# Schema 'MyFirstSchema' has been uploaded into the Azure Integration Account 'my-integration-account'. # ---------- -# Uploading schema 'MySecondSchema' into the Integration Account 'my-integration-account' -# Schema 'MySecondSchema' has been uploaded into the Integration Account. +# Uploading schema 'MySecondSchema' into the Azure Integration Account 'my-integration-account'. +# Schema 'MySecondSchema' has been uploaded into the Azure Integration Account 'my-integration-account'. # ---------- ``` Uploading *all schemas* located in a specific folder into an Integration Account and remove the file-extension. ```powershell PS> Set-AzIntegrationAccountSchemas -ResourceGroupName 'my-resource-group' -Name 'my-integration-account' -SchemasFolder "C:\Schemas" -ArtifactsPrefix 'dev-' -# Uploading schema 'dev-MyFirstSchema.xsd' into the Integration Account 'my-integration-account' -# Schema 'dev-MyFirstSchema.xsd' has been uploaded into the Integration Account. +# Uploading schema 'dev-MyFirstSchema.xsd' into the Azure Integration Account 'my-integration-account'. +# Schema 'dev-MyFirstSchema.xsd' has been uploaded into the Azure Integration Account 'my-integration-account'. # ---------- -# Uploading schema 'dev-MySecondSchema.xsd' into the Integration Account 'my-integration-account' -# Schema 'dev-MySecondSchema.xsd' has been uploaded into the Integration Account. +# Uploading schema 'dev-MySecondSchema.xsd' into the Azure Integration Account 'my-integration-account' +# Schema 'dev-MySecondSchema.xsd' has been uploaded into the Azure Integration Account 'my-integration-account'. # ---------- ``` diff --git a/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psd1 b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psd1 index f9e2e6d24c8867b09ebc99c332bb689d1a488eeb..c94fe1660ad633fc10182cfdcb8e54fb2d12d9c5 100644 GIT binary patch delta 97 zcmca-JmLpG31XGmqxV+aG1MGVCZnGE?1c?`7-%A2E^c8d|G Obn;qB`OQ|6OIQF+kQPY* delta 33 lcmbPdbI*E17!#`jgC2w7=4z(hVi4x!x03Rkt0b4O0061A3CjQg diff --git a/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1 b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1 index 6144e691..f3e02fe0 100644 --- a/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1 +++ b/src/Arcus.Scripting.IntegrationAccount/Arcus.Scripting.IntegrationAccount.psm1 @@ -22,7 +22,6 @@ .Parameter RemoveFileExtensions Indicator whether the extension should be removed from the name before uploading/updating. - #> function Set-AzIntegrationAccountSchemas { param( diff --git a/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 b/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 index cd8b7b8c..447d36ff 100644 --- a/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 +++ b/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 @@ -29,12 +29,12 @@ function UploadSchema { ## Check if the schema already exists $existingSchema = $null try { - Write-Verbose "Checking if the schema '$schemaName' already exists in the Integration Account." + Write-Verbose "Checking if the schema '$schemaName' already exists in the Integration Account '$Name'." $existingSchema = Get-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -ErrorAction Stop } catch { if ($_.Exception.Message.Contains('could not be found')) { - Write-Verbose "Schema '$schemaName' could not be found." + Write-Verbose "No schema '$schemaName' could not be found in Azure Integration Account '$Name'." } else { throw $_.Exception @@ -44,31 +44,31 @@ function UploadSchema { try { if ($existingSchema -eq $null) { # Create the schema - Write-Verbose "Creating schema '$schemaName'" + Write-Verbose "Creating schema '$schemaName' in Azure Integration Account '$Name'" $createdSchema = New-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -SchemaFilePath $schema.FullName -ErrorAction Stop Write-Verbose ($createdSchema | Format-List -Force | Out-String) } else { # Update the schema - Write-Verbose "Updating schema '$schemaName'" + Write-Verbose "Updating schema '$schemaName' in Azure Integration Account '$Name'" $updatedSchema = Set-AzIntegrationAccountSchema -ResourceGroupName $ResourceGroupName -Name $Name -SchemaName $schemaName -SchemaFilePath $schema.FullName -ErrorAction Stop -Force Write-Verbose ($updatedSchema | Format-List -Force | Out-String) } - Write-Host "Schema '$schemaName' has been uploaded into the Integration Account." + Write-Host "Schema '$schemaName' has been uploaded into the Azure Integration Account '$Name'." } catch { - Write-Error "Failed to upload schema '$schemaName' in Integration Account '$Name': '$($_.Exception.Message)_'" + Write-Error "Failed to upload schema '$schemaName' in Azure Integration Account '$Name': '$($_.Exception.Message)_'" } } # Verify if Integration Account can be found based on the given information $integrationAccount = Get-AzIntegrationAccount -ResourceGroupName $ResourceGroupName -Name $Name -ErrorAction SilentlyContinue if ($integrationAccount -eq $null) { - Write-Error "Unable to find the Integration Account with name '$Name' in resource group '$ResourceGroupName'" + Write-Error "Unable to find the Azure Integration Account with name '$Name' in resource group '$ResourceGroupName'" } else { if ($SchemasFolder -ne '' -and $SchemaFilePath -eq '') { - foreach ($schema in Get-ChildItem("$schemasFolder") -File) { + foreach ($schema in Get-ChildItem($schemasFolder) -File) { UploadSchema -Schema $schema Write-Host '----------' } diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 index 817c7553..adb1b79f 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -1,4 +1,3 @@ -Import-Module Az.KeyVault Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.IntegrationAccount -ErrorAction Stop InModuleScope Arcus.Scripting.IntegrationAccount { From 9adcf7748e17127912e52f6133687a593db48207 Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Wed, 14 Jul 2021 10:51:52 +0200 Subject: [PATCH 11/12] Resolve remarks based on PR-review. --- .../Scripts/Set-AzIntegrationAccountSchemas.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 b/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 index 447d36ff..ef551fe1 100644 --- a/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 +++ b/src/Arcus.Scripting.IntegrationAccount/Scripts/Set-AzIntegrationAccountSchemas.ps1 @@ -24,7 +24,7 @@ function UploadSchema { if ($ArtifactsPrefix -ne '') { $schemaName = $ArtifactsPrefix + $schemaName } - Write-Host "Uploading schema '$schemaName' into the Integration Account '$Name'" + Write-Host "Uploading schema '$schemaName' into the Integration Account '$Name'." ## Check if the schema already exists $existingSchema = $null From e0916077203c1b140c8e4376824bfa64cf113b97 Mon Sep 17 00:00:00 2001 From: Maxim Braekman Date: Wed, 14 Jul 2021 12:22:21 +0200 Subject: [PATCH 12/12] Include some unit tests. --- ...cus.Scripting.IntegrationAccount.tests.ps1 | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAccount.tests.ps1 diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAccount.tests.ps1 b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAccount.tests.ps1 new file mode 100644 index 00000000..87e6b01a --- /dev/null +++ b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.IntegrationAccount.tests.ps1 @@ -0,0 +1,196 @@ +Describe "Arcus" { + InModuleScope Arcus.Scripting.IntegrationAccount { + Context "Azure Integration Account Schemas" { + It "Providing both schemaFilePath and schemasFolder should fail" { + # Arrange + $resourceGroupName = "rg-infrastructure" + $integrationAccountName = "unexisting-integration-account" + $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\NestedSchema.xsd" + $SchemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas\" + + # Act + { + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schemaFilePath -SchemasFolder $schemasFolder -ErrorAction Stop + } | Should -Throw -ExpectedMessage "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" + + # Assert + Assert-VerifiableMock + } + It "Providing neither a schemaFilePath nor schemasFolder should fail" { + # Arrange + $resourceGroupName = "rg-infrastructure" + $integrationAccountName = "unexisting-integration-account" + + # Act + { + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -ErrorAction Stop + } | Should -Throw -ExpectedMessage "Either the file path of a specific schema or the file path of a folder containing multiple schemas is required, e.g.: -SchemaFilePath 'C:\Schemas\Schema.xsd' or -SchemasFolder 'C:\Schemas'" + + # Assert + Assert-VerifiableMock + } + It "Providing only the schemaFilePath to create a schema is OK" { + # Arrange + $subscriptionId = [guid]::NewGuid() + $resourceGroupName = "rg-infrastructure" + $integrationAccountName = "unexisting-integration-account" + $integrationAccountResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName" + $schemaName = 'Dummy_New_Schema' + $schemaResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName/schemas/$schemaName" + $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\$schemaName.xsd" + + Mock Get-AzIntegrationAccount { + return [pscustomobject]@{ Id = $integrationAccountResourceId; Name = $integrationAccountName; Type = 'Microsoft.Logic/integrationAccounts'; Location = 'westeurope'; Sku = 'Free' } + } -Verifiable + + Mock Get-AzIntegrationAccountSchema { + return $null + } -Verifiable + + Mock Set-AzIntegrationAccountSchema { + return $null + } + + Mock New-AzIntegrationAccountSchema { + return [pscustomobject]@{ Id = $schemaResourceId; Name = $schemaName; Type = 'Microsoft.Logic/integrationAccounts/schemas'; SchemaType = 'Xml'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow } + } + + # Act + { + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schemaFilePath -ErrorAction Stop + } | Should -Not -Throw + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzIntegrationAccount -Times 1 + Assert-MockCalled Get-AzIntegrationAccountSchema -Times 1 + Assert-MockCalled Set-AzIntegrationAccountSchema -Times 0 + Assert-MockCalled New-AzIntegrationAccountSchema -Times 1 + } + It "Providing only the schemaFilePath to update a schema is OK" { + # Arrange + $subscriptionId = [guid]::NewGuid() + $resourceGroupName = "rg-infrastructure" + $integrationAccountName = "unexisting-integration-account" + $integrationAccountResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName" + $schemaName = 'Dummy_Existing_Schema' + $schemaResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName/schemas/$schemaName" + $schemaFilePath = "$PSScriptRoot\Files\IntegrationAccount\Schemas\$schemaName.xsd" + + Mock Get-AzIntegrationAccount { + return [pscustomobject]@{ Id = $integrationAccountResourceId; Name = $integrationAccountName; Type = 'Microsoft.Logic/integrationAccounts'; Location = 'westeurope'; Sku = 'Free' } + } -Verifiable + + Mock Get-AzIntegrationAccountSchema { + return [pscustomobject]@{ Id = $schemaResourceId; Name = $schemaName; Type = 'Microsoft.Logic/integrationAccounts/schemas'; SchemaType = 'Xml'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow } + } -Verifiable + + Mock Set-AzIntegrationAccountSchema { + return [pscustomobject]@{ Id = $schemaResourceId; Name = $schemaName; Type = 'Microsoft.Logic/integrationAccounts/schemas'; SchemaType = 'Xml'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow } + } + + Mock New-AzIntegrationAccountSchema { + return $null + } + + # Act + { + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemaFilePath $schemaFilePath -ErrorAction Stop + } | Should -Not -Throw + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzIntegrationAccount -Times 1 + Assert-MockCalled Get-AzIntegrationAccountSchema -Times 1 + Assert-MockCalled Set-AzIntegrationAccountSchema -Times 1 + Assert-MockCalled New-AzIntegrationAccountSchema -Times 0 + } + It "Providing only a schemasFolder to create schemas is OK" { + # Arrange + $subscriptionId = [guid]::NewGuid() + $resourceGroupName = "rg-infrastructure" + $integrationAccountName = "unexisting-integration-account" + $integrationAccountResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName" + $schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas\" + + Mock Get-ChildItem { + return @( + new-item -name "Schema1.xsd" -type file -fo + new-item -name "Schema2.xsd" -type file -fo + ) + } + + Mock Get-AzIntegrationAccount { + return [pscustomobject]@{ Id = $integrationAccountResourceId; Name = $integrationAccountName; Type = 'Microsoft.Logic/integrationAccounts'; Location = 'westeurope'; Sku = 'Free' } + } -Verifiable + + Mock Get-AzIntegrationAccountSchema { + return $null + } -Verifiable + + Mock Set-AzIntegrationAccountSchema { + return $null + } + + Mock New-AzIntegrationAccountSchema { + return [pscustomobject]@{ Id = 'fake-resource-id'; Name = 'Dummy.xsd'; Type = 'Microsoft.Logic/integrationAccounts/schemas'; SchemaType = 'Xml'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow } + } + + # Act + { + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemasFolder $schemasFolder -ErrorAction Stop + } | Should -Not -Throw + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzIntegrationAccount -Times 1 + Assert-MockCalled Get-AzIntegrationAccountSchema -Times 2 + Assert-MockCalled Set-AzIntegrationAccountSchema -Times 0 + Assert-MockCalled New-AzIntegrationAccountSchema -Times 2 + } + It "Providing only a schemasFolder to update schemas is OK" { + # Arrange + $subscriptionId = [guid]::NewGuid() + $resourceGroupName = "rg-infrastructure" + $integrationAccountName = "unexisting-integration-account" + $integrationAccountResourceId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Logic/integrationAccounts/$integrationAccountName" + $schemasFolder = "$PSScriptRoot\Files\IntegrationAccount\Schemas\" + + Mock Get-ChildItem { + return @( + new-item -name "Schema1.xsd" -type file -fo + new-item -name "Schema2.xsd" -type file -fo + ) + } + + Mock Get-AzIntegrationAccount { + return [pscustomobject]@{ Id = $integrationAccountResourceId; Name = $integrationAccountName; Type = 'Microsoft.Logic/integrationAccounts'; Location = 'westeurope'; Sku = 'Free' } + } -Verifiable + + Mock Get-AzIntegrationAccountSchema { + return [pscustomobject]@{ Id = 'fake-resource-id'; Name = 'Dummy.xsd'; Type = 'Microsoft.Logic/integrationAccounts/schemas'; SchemaType = 'Xml'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow } + } -Verifiable + + Mock Set-AzIntegrationAccountSchema { + return [pscustomobject]@{ Id = 'fake-resource-id'; Name = 'Dummy.xsd'; Type = 'Microsoft.Logic/integrationAccounts/schemas'; SchemaType = 'Xml'; CreatedTime = [datetime]::UtcNow; ChangedTime = [datetime]::UtcNow } + } + + Mock New-AzIntegrationAccountSchema { + return $null + } + + # Act + { + Set-AzIntegrationAccountSchemas -ResourceGroupName $resourceGroupName -Name $integrationAccountName -SchemasFolder $schemasFolder -ErrorAction Stop + } | Should -Not -Throw + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzIntegrationAccount -Times 1 + Assert-MockCalled Get-AzIntegrationAccountSchema -Times 2 + Assert-MockCalled Set-AzIntegrationAccountSchema -Times 2 + Assert-MockCalled New-AzIntegrationAccountSchema -Times 0 + } + } + } +}