@@ -61,6 +61,44 @@ function Test-TagCreateOrUpdateWithResourceIdParamsForResource
61
61
Test-TagCreateOrUpdateWithResourceIdParams $resourceId
62
62
}
63
63
64
+ <#
65
+ . SYNOPSIS
66
+ Utility method to test async CreateOrUpdate for Tags within tracked resources and subscription.
67
+ #>
68
+ function Test-TagCreateOrUpdateAsyncWithResourceIdParams ($resourceId )
69
+ {
70
+ # Setup
71
+ $expected = @ {" key1" = " value1" ; " key2" = " value2" ;}
72
+
73
+ try
74
+ {
75
+ # Test
76
+ $newTagres = New-AzTag - ResourceId $resourceId - Tag $expected
77
+ Start-TestSleep - Seconds 120
78
+ $res = Get-AzTag - ResourceId $resourceId
79
+
80
+ [hashtable ]$actual = $res.Properties.TagsProperty
81
+ Assert-True { AreHashtableEqual $expected $actual }
82
+ }
83
+ finally
84
+ {
85
+ # Cleanup
86
+ Remove-AzTag - ResourceId $resourceId
87
+ }
88
+ }
89
+
90
+ <#
91
+ . SYNOPSIS
92
+ Tests creating or updating tags on tracked resource.
93
+ #>
94
+ function Test-TagCreateOrUpdateAsyncWithResourceIdParamsForResource
95
+ {
96
+ # Setup
97
+ $resourceId = NewTestResourcePurviewAccount
98
+
99
+ Test-TagCreateOrUpdateAsyncWithResourceIdParams $resourceId
100
+ }
101
+
64
102
65
103
<#
66
104
. SYNOPSIS
@@ -143,6 +181,77 @@ function Test-TagUpdateWithResourceIdParamsForResource
143
181
Test-UpdateWithResourceIdParams $resourceId
144
182
}
145
183
184
+ <#
185
+ . SYNOPSIS
186
+ Utility method to test async updating tags on subscription and tracked resource, including Merge, Replace, and Delete Operation.
187
+ #>
188
+ function Test-UpdateAsyncWithResourceIdParams ($resourceId )
189
+ {
190
+ # Setup
191
+ $original = @ {" key1" = " value1" ; " key2" = " value2" ;}
192
+ New-AzTag - ResourceId $resourceId - Tag $original
193
+ Start-TestSleep - Seconds 120
194
+
195
+ try
196
+ {
197
+ # Test
198
+ {
199
+ # merge operation
200
+ $merged = @ {" key1" = " value1" ; " key3" = " value3" ;}
201
+ $res = Update-AzTag - ResourceId $resourceId - Tag $merged - Operation Merge
202
+ Start-TestSleep - Seconds 120
203
+
204
+ $expected = @ {" key1" = " value1" ; " key2" = " value2" ; " key3" = " value3" ;}
205
+ [hashtable ]$actual = $res.Properties.TagsProperty
206
+
207
+ # Assert
208
+ Assert-True { AreHashtableEqual $expected $actual }
209
+ }
210
+
211
+ {
212
+ # replace operation
213
+ $replaced = @ {" key1" = " value1" ; " key3" = " value3" ;}
214
+ $res = Update-AzTag - ResourceId $resourceId - Tag $replaced - Operation Replace
215
+ Start-TestSleep - Seconds 120
216
+
217
+ $expected = $replaced
218
+ [hashtable ]$actual = $res.Properties.TagsProperty
219
+
220
+ # Assert
221
+ Assert-True { AreHashtableEqual $expected $actual }
222
+ }
223
+
224
+ {
225
+ # delete operation
226
+ $deleted = @ {" key1" = " value1" ; " key3" = " value3" ;}
227
+ $res = Update-AzTag - ResourceId $resourceId - Tag $deleted - Operation Delete
228
+ Start-TestSleep - Seconds 120
229
+
230
+ $expected = null
231
+ [hashtable ]$actual = $res.Properties.TagsProperty
232
+
233
+ # Assert
234
+ Assert-True { AreHashtableEqual $expected $actual }
235
+ }
236
+ }
237
+ finally
238
+ {
239
+ # Cleanup
240
+ Remove-AzTag - ResourceId $resourceId
241
+ }
242
+ }
243
+
244
+ <#
245
+ . SYNOPSIS
246
+ Tests async updating tags on tracked resource.
247
+ #>
248
+ function Test-TagUpdateAsyncWithResourceIdParamsForResource
249
+ {
250
+ # Setup
251
+ $resourceId = NewTestResourcePurviewAccount
252
+
253
+ Test-UpdateAsyncWithResourceIdParams $resourceId
254
+ }
146
255
147
256
<#
148
257
. SYNOPSIS
@@ -247,6 +356,46 @@ function Test-TagDeleteWithResourceIdParamsForResource
247
356
Test-TagDeleteWithResourceIdParams $resourceId
248
357
}
249
358
359
+ <#
360
+ . SYNOPSIS
361
+ Utility method to test Delete for Tags within tracked resources and subscription.
362
+ #>
363
+ function Test-TagDeleteAsyncWithResourceIdParams ($resourceId )
364
+ {
365
+ # Setup
366
+ $original = @ {" key1" = " value1" ; " key2" = " value2" ;}
367
+ New-AzTag - ResourceId $resourceId - Tag $original
368
+ Start-TestSleep - Seconds 120
369
+
370
+ try
371
+ {
372
+ # Test
373
+ Remove-AzTag - ResourceId $resourceId
374
+ Start-TestSleep - Seconds 120
375
+ $actual = Get-AzTag - ResourceId $resourceId
376
+
377
+ # Assert
378
+ Assert-AreEqual $actual.Properties.TagsProperty.Count 0
379
+ }
380
+ finally
381
+ {
382
+ # Cleanup
383
+ Remove-AzTag - ResourceId $resourceId
384
+ }
385
+ }
386
+
387
+ <#
388
+ . SYNOPSIS
389
+ Tests getting tags on tracked resource.
390
+ #>
391
+ function Test-TagDeleteAsyncWithResourceIdParamsForResource
392
+ {
393
+ # Setup
394
+ $resourceId = NewTestResourcePurviewAccount
395
+
396
+ Test-TagDeleteAsyncWithResourceIdParams $resourceId
397
+ }
398
+
250
399
<#
251
400
. SYNOPSIS
252
401
utility method to get default subscriptionId
@@ -265,13 +414,13 @@ utility method to create resource group
265
414
#>
266
415
function NewTestResourceGroup
267
416
{
268
- $rgName = " RG-Test05 "
417
+ $rgName = Get-ResourceGroupName
269
418
$location = " Central US"
270
419
271
- $existed = Get-AzureRmResourceGroup - Name $rgName - ErrorVariable notPresent - ErrorAction SilentlyContinue
420
+ $existed = Get-AzResourceGroup - Name $rgName - ErrorVariable notPresent - ErrorAction SilentlyContinue
272
421
273
422
if ($notPresent ) {
274
- $existed = New-AzureRmResourceGroup - Name $rgName - Location $location
423
+ $existed = New-AzResourceGroup - Name $rgName - Location $location
275
424
}
276
425
277
426
return $existed
@@ -285,18 +434,40 @@ function NewTestResource
285
434
{
286
435
$rg = NewTestResourceGroup
287
436
288
- $resourceName = " RS-Test05 "
437
+ $resourceName = Get-ResourceName
289
438
$resourceId = $rg.ResourceId + " /providers/microsoft.web/sites/" + $resourceName
290
439
291
- $location = " Central US"
440
+ $location = " West Central US"
292
441
$property = @ {test = " test-tag" }
293
442
$resourceType = " microsoft.web/sites"
294
443
295
- $existed = Get-AzureRmResource - ResourceId $resourceId - ErrorVariable notPresent - ErrorAction SilentlyContinue
444
+ $existed = Get-AzResource - ResourceId $resourceId - ErrorVariable notPresent - ErrorAction SilentlyContinue
296
445
297
446
if ($notPresent ) {
298
- $existed = New-AzureRmResource - Location $location - Properties $property - ResourceName $resourceName - ResourceType $resourceType - ResourceGroupName $rg.ResourceGroupName - Force
447
+ $existed = New-AzResource - Location $location - Properties $property - ResourceName $resourceName - ResourceType $resourceType - ResourceGroupName $rg.ResourceGroupName - Force
299
448
}
300
449
301
450
return $resourceId
302
451
}
452
+
453
+ <#
454
+ . SYNOPSIS
455
+ utility method to creare resource
456
+ #>
457
+ function NewTestResourcePurviewAccount
458
+ {
459
+ $rg = NewTestResourceGroup
460
+ $resourceName = Get-ResourceName
461
+ $resourceId = $rg.ResourceId + " /providers/Microsoft.Purview/accounts/" + $resourceName
462
+
463
+ $location = " westus"
464
+ $property = @ {test = " test-tag" }
465
+ $resourceType = " microsoft.purview/accounts"
466
+
467
+ $existed = Get-AzResource - ResourceId $resourceId - ErrorVariable notPresent - ErrorAction SilentlyContinue
468
+ if ($notPresent ) {
469
+ $existed = New-AzPurviewAccount - Name $resourceName - ResourceGroupName $rg.ResourceGroupName - IdentityType SystemAssigned - Location $location - Tag $property - SkuCapacity 4 - SkuName Standard
470
+ }
471
+
472
+ return $resourceId
473
+ }
0 commit comments