mirror of https://github.com/abpframework/abp.git
3 changed files with 80 additions and 0 deletions
@ -0,0 +1,50 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.SimpleStateChecking; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Authorization |
|||
{ |
|||
public class RequirePermissionsSimpleBatchStateChecker_Tests : AuthorizationTestBase |
|||
{ |
|||
private readonly ISimpleStateCheckerManager<MyStateEntity> _simpleStateCheckerManager; |
|||
|
|||
public RequirePermissionsSimpleBatchStateChecker_Tests() |
|||
{ |
|||
_simpleStateCheckerManager = GetRequiredService<ISimpleStateCheckerManager<MyStateEntity>>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task RequirePermissionsSimpleBatchStateChecker_Test() |
|||
{ |
|||
var myStateEntities = new MyStateEntity[] |
|||
{ |
|||
new MyStateEntity().RequirePermissions(requiresAll: true, batchCheck:true, permissions: "MyPermission3"), |
|||
new MyStateEntity().RequirePermissions(requiresAll: true, batchCheck:true, permissions: "MyPermission4"), |
|||
new MyStateEntity().RequirePermissions(requiresAll: true, batchCheck:true, permissions: "MyPermission4"), |
|||
new MyStateEntity().RequirePermissions(requiresAll: true, batchCheck:true, permissions: "MyPermission5"), |
|||
}; |
|||
|
|||
var result = await _simpleStateCheckerManager.IsEnabledAsync(myStateEntities); |
|||
|
|||
result.Count.ShouldBe(myStateEntities.Length); |
|||
|
|||
result[myStateEntities[0]].ShouldBeTrue(); |
|||
result[myStateEntities[1]].ShouldBeFalse(); |
|||
result[myStateEntities[2]].ShouldBeFalse(); |
|||
result[myStateEntities[3]].ShouldBeTrue(); |
|||
} |
|||
|
|||
class MyStateEntity : IHasSimpleStateCheckers<MyStateEntity> |
|||
{ |
|||
public List<ISimpleStateChecker<MyStateEntity>> StateCheckers { get; } |
|||
|
|||
public MyStateEntity() |
|||
{ |
|||
StateCheckers = new List<ISimpleStateChecker<MyStateEntity>>(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Authorization.TestServices |
|||
{ |
|||
public class FakePermissionStore : IPermissionStore, ITransientDependency |
|||
{ |
|||
public Task<bool> IsGrantedAsync(string name, string providerName, string providerKey) |
|||
{ |
|||
return Task.FromResult(name == "MyPermission3" || name == "MyPermission5"); |
|||
} |
|||
|
|||
public Task<MultiplePermissionGrantResult> IsGrantedAsync(string[] names, string providerName, string providerKey) |
|||
{ |
|||
var result = new MultiplePermissionGrantResult(); |
|||
foreach (var name in names) |
|||
{ |
|||
result.Result.Add(name, name == "MyPermission3" || name == "MyPermission5" |
|||
? PermissionGrantResult.Granted |
|||
: PermissionGrantResult.Prohibited); |
|||
} |
|||
|
|||
return Task.FromResult(result); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue