From 07b04e7af1b31a7901e376439611204ca66eebae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 16 Feb 2018 16:19:21 +0300 Subject: [PATCH] Added more tests for user permission management. --- .../Abp/Identity/PermissionManager_Tests.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/PermissionManager_Tests.cs b/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/PermissionManager_Tests.cs index 51a2419aca..29a5e9280b 100644 --- a/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/PermissionManager_Tests.cs +++ b/test/Volo.Abp.Identity.Tests/Volo/Abp/Identity/PermissionManager_Tests.cs @@ -41,7 +41,7 @@ namespace Volo.Abp.Identity } [Fact] - public async Task User_Should_Have_Configured_Values() + public async Task Users_Should_Have_Configured_Values() { //administrator var user = GetUserAsync("administrator"); @@ -49,6 +49,20 @@ namespace Volo.Abp.Identity UserShouldHavePermission(grantInfos, user.Id, TestPermissionNames.MyPermission1, "admin"); UserShouldHavePermission(grantInfos, user.Id, TestPermissionNames.MyPermission2, "admin"); UserShouldHavePermission(grantInfos, user.Id, TestPermissionNames.MyPermission2_ChildPermission1, "admin"); + + //john.nash + user = GetUserAsync("john.nash"); + grantInfos = await _permissionManager.GetAllForUserAsync(user.Id); + UserShouldHavePermission(grantInfos, user.Id, TestPermissionNames.MyPermission1, "moderator", "supporter"); + UserShouldHavePermission(grantInfos, user.Id, TestPermissionNames.MyPermission2, "moderator"); + ShouldNotHavePermission(grantInfos, TestPermissionNames.MyPermission2_ChildPermission1); + + //john.nash + user = GetUserAsync("david"); + grantInfos = await _permissionManager.GetAllForUserAsync(user.Id); + UserShouldHavePermission(grantInfos, user.Id, TestPermissionNames.MyPermission1); + ShouldNotHavePermission(grantInfos, TestPermissionNames.MyPermission2); + ShouldNotHavePermission(grantInfos, TestPermissionNames.MyPermission2_ChildPermission1); } private static void RoleShouldHavePermission(List grantInfos, string roleName, string permissionName) @@ -64,20 +78,20 @@ namespace Volo.Abp.Identity ); } - private static void ShouldNotHavePermission(List grantInfos, string permissionName) + private static void UserShouldHavePermission(List grantInfos, Guid userId, string permissionName, params string[] inheritedRolesForThisPermission) { grantInfos.ShouldContain( p => p.Name == permissionName && - !p.IsGranted && - p.Providers.Count == 0 + p.IsGranted ); } - private static void UserShouldHavePermission(List grantInfos, Guid userId, string permissionName, params string[] inheritedRolesForThisPermission) + private static void ShouldNotHavePermission(List grantInfos, string permissionName) { grantInfos.ShouldContain( p => p.Name == permissionName && - p.IsGranted + !p.IsGranted && + p.Providers.Count == 0 ); } }