Tests/Join-AppSettingActiveDirectory.Tests.ps1
$projectRoot = Split-Path -Path $PSScriptRoot; . "$projectRoot\_functionReference.ps1"; Describe "Join-AppSettingActiveDirectory" { #set objects $resourceGroupName = "test resource"; $webAppList = New-Object System.Collections.ArrayList; $siteSettingsList = New-Object System.Collections.ArrayList; $scannedADApplications = New-Object System.Collections.ArrayList; $webapp1 = [PsCustomObject]@{SiteName = "testSiteName"}; $siteSetting1 = [PSCustomObject]@{ Properties = [PsCustomObject]@{ WEBSITE_NODE_DEFAULT_VERSION = "6.9.1"; ClientId = "96b3aa6e-9a9a-4cbc-a499-5a35800855cc" } } $adApplication1 = New-Object -TypeName Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory.PSADApplication; $adApplication1.ApplicationId = "96b3aa6e-9a9a-4cbc-a499-5a35800855cc"; $adApplication1.DisplayName = "testName"; $webAppList.Add($webapp1); $siteSettingsList.Add($siteSetting1); $scannedADApplications.Add($adApplication1); #Mock services Mock -commandName Get-AzureRmWebApp { return $webAppList } Mock -CommandName Invoke-AzureRmResourceAction { return $siteSettingsList } Mock -CommandName Add-Log -MockWith {}; Mock -CommandName Out-Error -MockWith {}; Mock -CommandName Set-Output -MockWith {}; Context "Retrieves all web apps for a given resource group" { Join-AppSettingActiveDirectory It "Calls the web app service to retrieve all webapps with the correct resource group" { Assert-MockCalled -CommandName Get-AzureRmWebApp -ParameterFilter { $ResourceGroupName -eq $resourceGroupName } -Times 1 -Exactly } It "Retrieves app settings for each web app found" { Assert-MockCalled -CommandName Invoke-AzureRmResourceAction -ParameterFilter { $ResourceGroupName -eq $resourceGroupName } -Times 1 -Exactly } It "Sends acquired data to the output pipeline" { Assert-MockCalled -CommandName Set-Output -Times 1 -Exactly } } } |