@@ -430,6 +430,55 @@ function Test-RaPropertiesValidation
430
430
VerifyRoleAssignmentDeleted $newAssignment
431
431
}
432
432
433
+ <#
434
+ . SYNOPSIS
435
+ Tests verifies get of RoleAssignment by Scope
436
+ #>
437
+ function Test-RaGetByScope
438
+ {
439
+ # Setup
440
+ $definitionName = ' Reader'
441
+ $users = Get-AzureRmADUser | Select-Object - First 1 - Wait
442
+ $subscription = Get-AzureRmSubscription
443
+ $resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 2 - Wait
444
+ $scope1 = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [0 ].ResourceGroupName
445
+ $scope2 = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [1 ].ResourceGroupName
446
+ Assert-AreEqual 1 $users.Count " There should be at least one user to run the test."
447
+
448
+ # Test
449
+ [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleAssignmentNames.Enqueue(" f747531e-da33-43b9-b726-04675abf1939" )
450
+ $newAssignment1 = New-AzureRmRoleAssignment `
451
+ - ObjectId $users [0 ].Id.Guid `
452
+ - RoleDefinitionName $definitionName `
453
+ - Scope $scope1
454
+
455
+ $newAssignment2 = New-AzureRmRoleAssignment `
456
+ - ObjectId $users [0 ].Id.Guid `
457
+ - RoleDefinitionName $definitionName `
458
+ - Scope $scope2
459
+
460
+ $ras = Get-AzureRmRoleAssignment - ObjectId $users [0 ].Id.Guid `
461
+ - RoleDefinitionName $definitionName `
462
+ - Scope $scope1
463
+
464
+ foreach ($assignment in $ras ){
465
+ Assert-NotNull $assignment
466
+ Assert-NotNull $assignment.Scope
467
+ Assert-AreNotEqual $assignment.Scope $scope2
468
+ }
469
+ # cleanup
470
+ DeleteRoleAssignment $newAssignment1
471
+ DeleteRoleAssignment $newAssignment2
472
+
473
+ # Assert
474
+ Assert-NotNull $newAssignment1
475
+ Assert-AreEqual $definitionName $newAssignment1.RoleDefinitionName
476
+ Assert-AreEqual $scope1 $newAssignment1.Scope
477
+ Assert-AreEqual $users [0 ].DisplayName $newAssignment1.DisplayName
478
+
479
+ VerifyRoleAssignmentDeleted $newAssignment1
480
+ }
481
+
433
482
<#
434
483
. SYNOPSIS
435
484
Creates role assignment
0 commit comments