|
| 1 | + Set-Variable -Name VerbosePreference -Value Continue |
| 2 | + |
| 3 | +function PollingInterval() |
| 4 | +{ |
| 5 | + if ($env:AZURE_TEST_MODE -eq 'Playback') |
| 6 | + { |
| 7 | + $pollingIntervalSecs = 5 |
| 8 | + } |
| 9 | + else |
| 10 | + { |
| 11 | + $pollingIntervalSecs = 60 * 5 |
| 12 | + } |
| 13 | + $pollingIntervalSecs |
| 14 | +} |
| 15 | + |
| 16 | +function Assert([ScriptBlock] $Condition) |
| 17 | +{ |
| 18 | + if ((& $Condition) -eq $false) |
| 19 | + { |
| 20 | + throw "Assertion Failed $($Condition.ToString()): $(Get-PSCallStack | Out-String)" |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +<# |
| 25 | + This will pick a location, image, billing plan and create a ARA App collection and returns the collection name. |
| 26 | +#> |
| 27 | +function CreateCloudCollection([string] $Collection) |
| 28 | +{ |
| 29 | + |
| 30 | + Write-Verbose "Entering $($MyInvocation.MyCommand.name)" |
| 31 | + [PSObject[]] $locationList = Get-AzureRemoteAppLocation | % Name |
| 32 | + Assert -Condition {$locationList -ne $null -or $locationList.Count -lt 1} |
| 33 | + |
| 34 | + [PSObject[]] $templateImageList = Get-AzureRemoteAppTemplateImage | ? {$_.Type -eq 'Platform' -and $_.OfficeType -ne 'Office365'} |
| 35 | + Assert -Condition {$templateImageList -ne $null -or $templateImageList.Count -lt 1} |
| 36 | + |
| 37 | + $templateImage = $null |
| 38 | + $locCounter = 0 |
| 39 | + $imageCounter = 0 |
| 40 | + $found = $false |
| 41 | + do |
| 42 | + { |
| 43 | + $location = $locationList[$locCounter] |
| 44 | + do |
| 45 | + { |
| 46 | + $templateImage = $templateImageList[$imageCounter] |
| 47 | + if ($templateImage.RegionList -contains $location) |
| 48 | + { |
| 49 | + $found = $true |
| 50 | + } |
| 51 | + |
| 52 | + $imageCounter++ |
| 53 | + } while ($imageCounter -lt $templateImageList.Count -and -not $found) |
| 54 | + |
| 55 | + $locCounter++ |
| 56 | + } while ($locCounter -lt $locationList.Count -and -not $found) |
| 57 | + |
| 58 | + Assert -Condition {$found} |
| 59 | + |
| 60 | + $billingPlans = Get-AzureRemoteAppPlan | % Name |
| 61 | + $billingPlan = $billingPlans[0] |
| 62 | + Assert -Condition {-not [String]::IsNullOrWhiteSpace($billingPlan)} |
| 63 | + |
| 64 | + Write-Verbose "New-AzureRemoteAppCollection -CollectionName $Collection -ImageName $($templateImage.Name) -Plan $billingPlan -Location $location -Description 'Test Collection'" |
| 65 | + $trackIdCollection = New-AzureRemoteAppCollection -CollectionName $Collection -ImageName $templateImage.Name -Plan $billingPlan -Location $location -Description 'Test Collection' -ErrorAction SilentlyContinue -ErrorVariable er |
| 66 | + if ($? -eq $false) |
| 67 | + { |
| 68 | + throw $er |
| 69 | + } |
| 70 | + |
| 71 | + do |
| 72 | + { |
| 73 | + Write-Verbose "Waiting current time: $(Get-Date)" |
| 74 | + sleep -Seconds (PollingInterval) |
| 75 | + |
| 76 | + $collectionState = Get-AzureRemoteAppOperationResult -TrackingId $trackIdCollection.TrackingId -ErrorAction SilentlyContinue -ErrorVariable er |
| 77 | + if ($? -eq $false) |
| 78 | + { |
| 79 | + throw $er |
| 80 | + } |
| 81 | + |
| 82 | + Write-Verbose "Collection state: $($collectionState.Status)" |
| 83 | + } while ($collectionState.Status -eq 'InProgress' -or $collectionState.Status -eq 'Pending') |
| 84 | + |
| 85 | + Assert -Condition {$collectionState.Status -eq 'Success'} |
| 86 | + Write-Verbose "$($MyInvocation.MyCommand.name) succsssfully created this collection $Collection" |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +<# |
| 91 | + This will pick a 5 applications to publish, verifies that they've been published and returns the Publishing Info. |
| 92 | +#> |
| 93 | +function PublishRemoteApplications([string] $Collection) |
| 94 | +{ |
| 95 | + Write-Verbose "Entering $($MyInvocation.MyCommand.name)" |
| 96 | + $numOfApps = 5 |
| 97 | + $availablePrograms = Get-AzureRemoteAppStartMenuProgram $Collection -ErrorAction SilentlyContinue -ErrorVariable er |
| 98 | + if ($? -eq $false) |
| 99 | + { |
| 100 | + throw $er |
| 101 | + } |
| 102 | + |
| 103 | + Assert({$availablePrograms.Count -ge $numOfApps}) |
| 104 | + |
| 105 | + $currentPrograms = Get-AzureRemoteAppProgram -CollectionName $Collection -ErrorAction SilentlyContinue -ErrorVariable er |
| 106 | + if ($? -eq $false) |
| 107 | + { |
| 108 | + throw $er |
| 109 | + } |
| 110 | + |
| 111 | + $programsToPublish = $availablePrograms[0..2] |
| 112 | + $programsToPublish += $availablePrograms[$($availablePrograms.Count-2)..$($availablePrograms.Count-1)] |
| 113 | + Assert({$programsToPublish.Count -eq $numOfApps}) |
| 114 | + $applications = $programsToPublish | % { |
| 115 | + Publish-AzureRemoteAppProgram -CollectionName $Collection -StartMenuAppId $_.StartMenuAppId -ErrorAction SilentlyContinue -ErrorVariable er |
| 116 | + if ($? -eq $false) |
| 117 | + { |
| 118 | + throw $er |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + $publishedPrograms = Get-AzureRemoteAppProgram -CollectionName $Collection -ErrorAction SilentlyContinue -ErrorVariable er |
| 123 | + if ($? -eq $false) |
| 124 | + { |
| 125 | + throw $er |
| 126 | + } |
| 127 | + |
| 128 | + Assert -Condition {($publishedPrograms.Count - $currentPrograms.Count) -eq $numOfApps} |
| 129 | + |
| 130 | + $applications | % {Write-Verbose "($([IO.FileInfo]$_.ApplicationVirtualPath))"} |
| 131 | + Write-Verbose "$($MyInvocation.MyCommand.name) completed succsssfully" |
| 132 | + |
| 133 | + $applications |
| 134 | +} |
| 135 | + |
| 136 | + |
| 137 | +<# |
| 138 | + This will pick a add the given users to the collection. |
| 139 | +#> |
| 140 | +function AddRemoteAppUsers([string] $Collection, [string[]] $msaUsers) |
| 141 | +{ |
| 142 | + Write-Verbose "Entering $($MyInvocation.MyCommand.name)" |
| 143 | + $previousUsers = Get-AzureRemoteAppUser -CollectionName $Collection -ErrorAction SilentlyContinue -ErrorVariable er |
| 144 | + if ($? -eq $false) |
| 145 | + { |
| 146 | + throw $er |
| 147 | + } |
| 148 | + |
| 149 | + $msaUsers | % { |
| 150 | + Add-AzureRemoteAppUser -CollectionName $Collection -Type MicrosoftAccount -UserUpn $_ -ErrorAction SilentlyContinue -ErrorVariable er |
| 151 | + if ($? -eq $false) |
| 152 | + { |
| 153 | + throw $er |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + $currentUsers = Get-AzureRemoteAppUser -CollectionName $Collection -ErrorAction SilentlyContinue -ErrorVariable er |
| 158 | + if ($? -eq $false) |
| 159 | + { |
| 160 | + throw $er |
| 161 | + } |
| 162 | + |
| 163 | + Assert -Condition {($previousUsers.Count + $msaUsers.Count) -eq $currentUsers.Count} |
| 164 | + Write-Verbose "$($MyInvocation.MyCommand.name) completed succsssfully" |
| 165 | + |
| 166 | + $currentUsers | % {Write-Verbose "Username: $($_.Name),and Type: $($_.UserIdType)" } |
| 167 | +} |
| 168 | + |
| 169 | +<# |
| 170 | + This will remove the given users from the collection. |
| 171 | +#> |
| 172 | +function RemoveRemoteAppUsers([string] $Collection, [string[]] $msaUsers) |
| 173 | +{ |
| 174 | + Write-Verbose "Entering $($MyInvocation.MyCommand.name)" |
| 175 | + $previousUsers = Get-AzureRemoteAppUser -CollectionName $Collection -ErrorAction SilentlyContinue -ErrorVariable er |
| 176 | + if ($? -eq $false) |
| 177 | + { |
| 178 | + throw $er |
| 179 | + } |
| 180 | + |
| 181 | + $msaUsers | % { |
| 182 | + Remove-AzureRemoteAppUser -CollectionName $Collection -Type MicrosoftAccount -UserUpn $_ -ErrorAction SilentlyContinue -ErrorVariable er |
| 183 | + if ($? -eq $false) |
| 184 | + { |
| 185 | + throw $er |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + $currentUsers = Get-AzureRemoteAppUser -CollectionName $Collection -ErrorAction SilentlyContinue -ErrorVariable er |
| 190 | + Assert -Condition {$currentUsers -eq $null} |
| 191 | + Write-Verbose "$($MyInvocation.MyCommand.name) completed succsssfully" |
| 192 | +} |
| 193 | + |
| 194 | +<# |
| 195 | + This will unpublish the specified applications from the collection. |
| 196 | +#> |
| 197 | +function UnpublishRemoteApplications([string] $Collection, [string[]] $applications) |
| 198 | +{ |
| 199 | + Write-Verbose "Entering $($MyInvocation.MyCommand.name)" |
| 200 | + $applications | % { |
| 201 | + Unpublish-AzureRemoteAppProgram -CollectionName $Collection -Alias $_ -ErrorAction SilentlyContinue -ErrorVariable er |
| 202 | + if ($? -eq $false) |
| 203 | + { |
| 204 | + throw $er |
| 205 | + } |
| 206 | + } |
| 207 | + |
| 208 | + Sleep 60 # seconds |
| 209 | + $remainingApps = Get-AzureRemoteAppProgram $Collection | % Alias |
| 210 | + |
| 211 | + $failedToUnpublish = $remainingApps | ? {$applications -contains $_} |
| 212 | + Assert -Condition {$failedToUnpublish -eq $null} |
| 213 | + Write-Verbose "$($MyInvocation.MyCommand.name) completed succsssfully" |
| 214 | +} |
| 215 | + |
| 216 | +<# |
| 217 | + This delete the collection |
| 218 | +#> |
| 219 | +function DeleteRemoteAppCollection([string] $Collection) |
| 220 | +{ |
| 221 | + Write-Verbose "Entering $($MyInvocation.MyCommand.name)" |
| 222 | + $trackIdCollection = Remove-AzureRemoteAppCollection -CollectionName $Collection |
| 223 | + |
| 224 | + do |
| 225 | + { |
| 226 | + Write-Verbose "Waiting current time: $(Get-Date)" |
| 227 | + sleep -Seconds (PollingInterval) |
| 228 | + |
| 229 | + $collectionState = Get-AzureRemoteAppOperationResult -TrackingId $trackIdCollection.TrackingId -ErrorAction SilentlyContinue -ErrorVariable er |
| 230 | + if ($? -eq $false) |
| 231 | + { |
| 232 | + throw $er |
| 233 | + } |
| 234 | + |
| 235 | + Write-Verbose "Collection state: $($collectionState.Status)" |
| 236 | + } while ($collectionState.Status -eq 'InProgress' -or $collectionState.Status -eq 'Pending') |
| 237 | + |
| 238 | + Assert -Condition {$collectionState.Status -eq 'Success'} |
| 239 | + Write-Verbose "$($MyInvocation.MyCommand.name) completed succsssfully" |
| 240 | +} |
| 241 | + |
| 242 | + |
| 243 | +function TestRemoteAppEndToEnd() |
| 244 | +{ |
| 245 | + $collection = 'CICollection' |
| 246 | + |
| 247 | + |
| 248 | + Write-Verbose "Starting current time: $(Get-Date)" |
| 249 | + CreateCloudCollection $collection |
| 250 | + $applications = PublishRemoteApplications $collection |
| 251 | + AddRemoteAppUsers $collection $msaUsers |
| 252 | + RemoveRemoteAppUsers $collection $msaUsers |
| 253 | + UnpublishRemoteApplications $collection ($applications | % {$_.ApplicationAlias}) |
| 254 | + DeleteRemoteAppCollection $collection |
| 255 | + Write-Verbose "Done current time: $(Get-Date)" |
| 256 | +} |
0 commit comments