Skip to content

Commit bfda718

Browse files
Adding tests
1 parent aaef0a2 commit bfda718

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleAssignmentTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ public void RaDeletionByScope()
103103
ResourcesController.NewInstance.RunPsTest("Test-RaDeletionByScope");
104104
}
105105

106+
[Fact]
107+
[Trait(Category.AcceptanceType, Category.CheckIn)]
108+
public void RaDeletionByScopeAtRootScope()
109+
{
110+
ResourcesController.NewInstance.RunPsTest("Test-RaDeletionByScopeAtRootScope");
111+
}
112+
106113
[Fact]
107114
[Trait(Category.AcceptanceType, Category.CheckIn)]
108115
public void RaByUpn()

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleAssignmentTests.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,75 @@ function Test-RaDeletionByScope
345345
VerifyRoleAssignmentDeleted $newAssignment
346346
}
347347

348+
<#
349+
.SYNOPSIS
350+
Tests verifies creation and deletion of a RoleAssignments by Scope irrespective of the case
351+
#>
352+
function Test-RaDeletionByScope
353+
{
354+
# Setup
355+
$definitionName = 'Reader'
356+
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
357+
$subscription = Get-AzureRmSubscription
358+
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
359+
$scope = '/subscriptions/'+ $subscription[0].Id +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
360+
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
361+
362+
# Test
363+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
364+
$newAssignment = New-AzureRmRoleAssignment `
365+
-ObjectId $users[0].Id.Guid `
366+
-RoleDefinitionName $definitionName `
367+
-Scope $scope
368+
$newAssignment.Scope = $scope.toUpper()
369+
370+
# cleanup
371+
DeleteRoleAssignment $newAssignment
372+
373+
# Assert
374+
Assert-NotNull $newAssignment
375+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
376+
Assert-AreEqual $scope $newAssignment.Scope
377+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
378+
379+
VerifyRoleAssignmentDeleted $newAssignment
380+
}
381+
382+
<#
383+
.SYNOPSIS
384+
Tests verifies creation and deletion of a RoleAssignments by Scope irrespective of the case
385+
#>
386+
function Test-RaDeletionByScopeAtRootScope
387+
{
388+
# Setup
389+
$definitionName = 'Reader'
390+
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
391+
$subscription = Get-AzureRmSubscription
392+
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
393+
$scope = '/'
394+
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
395+
396+
# Test
397+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
398+
$newAssignment = New-AzureRmRoleAssignment `
399+
-ObjectId $users[0].Id.Guid `
400+
-RoleDefinitionName $definitionName `
401+
-Scope $scope
402+
$newAssignment.Scope = $scope.toUpper()
403+
404+
# cleanup
405+
DeleteRoleAssignment $newAssignment
406+
407+
# Assert
408+
Assert-NotNull $newAssignment
409+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
410+
Assert-AreEqual $scope $newAssignment.Scope
411+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
412+
413+
VerifyRoleAssignmentDeleted $newAssignment
414+
}
415+
416+
348417
<#
349418
.SYNOPSIS
350419
Creates role assignment

0 commit comments

Comments
 (0)