mirror of https://github.com/abpframework/abp.git
6 changed files with 4 additions and 205 deletions
@ -1,18 +0,0 @@ |
|||||
<Project Sdk="Microsoft.NET.Sdk"> |
|
||||
|
|
||||
<PropertyGroup> |
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework> |
|
||||
|
|
||||
<IsPackable>false</IsPackable> |
|
||||
</PropertyGroup> |
|
||||
|
|
||||
<ItemGroup> |
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> |
|
||||
</ItemGroup> |
|
||||
|
|
||||
<ItemGroup> |
|
||||
<ProjectReference Include="..\..\src\Volo.Abp.PermissionManagement.Application\Volo.Abp.PermissionManagement.Application.csproj" /> |
|
||||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Tests\Volo.Abp.PermissionManagement.Tests.csproj" /> |
|
||||
</ItemGroup> |
|
||||
|
|
||||
</Project> |
|
||||
@ -1,27 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Text; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using NSubstitute; |
|
||||
using Volo.Abp.Users; |
|
||||
|
|
||||
namespace Volo.Abp.PermissionManagement |
|
||||
{ |
|
||||
public class AbpPermissionManagementApplicationTestBase : PermissionManagementTestBase<AbpPermissionManagementApplicationTestModule> |
|
||||
{ |
|
||||
protected Guid? CurrentUserId { get; set; } |
|
||||
|
|
||||
protected AbpPermissionManagementApplicationTestBase() |
|
||||
{ |
|
||||
CurrentUserId = Guid.NewGuid(); |
|
||||
} |
|
||||
protected override void AfterAddApplication(IServiceCollection services) |
|
||||
{ |
|
||||
var currentUser = Substitute.For<ICurrentUser>(); |
|
||||
//currentUser.Id.Returns(ci => CurrentUserId);
|
|
||||
currentUser.IsAuthenticated.Returns(true); |
|
||||
|
|
||||
services.AddSingleton(currentUser); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,28 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Text; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Volo.Abp.Authorization.Permissions; |
|
||||
using Volo.Abp.Modularity; |
|
||||
|
|
||||
namespace Volo.Abp.PermissionManagement |
|
||||
{ |
|
||||
[DependsOn( |
|
||||
typeof(AbpPermissionManagementApplicationModule), |
|
||||
typeof(AbpPermissionManagementTestModule) |
|
||||
)] |
|
||||
public class AbpPermissionManagementApplicationTestModule : AbpModule |
|
||||
{ |
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
context.Services.AddAlwaysAllowAuthorization(); |
|
||||
|
|
||||
context.Services.Configure<PermissionManagementOptions>(options => |
|
||||
{ |
|
||||
options.ProviderPolicies["Test"] = "Test"; |
|
||||
options.ManagementProviders.Add<TestPermissionManagementProvider>(); |
|
||||
|
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,96 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using System.Text; |
|
||||
using System.Threading.Tasks; |
|
||||
using Shouldly; |
|
||||
using Volo.Abp.Authorization.Permissions; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Volo.Abp.PermissionManagement.Application.Tests.Volo.Abp.PermissionManagement |
|
||||
{ |
|
||||
public class PermissionAppService_Tests : AbpPermissionManagementApplicationTestBase |
|
||||
{ |
|
||||
private readonly IPermissionAppService _permissionAppService; |
|
||||
private readonly IPermissionGrantRepository _permissionGrantRepository; |
|
||||
|
|
||||
public PermissionAppService_Tests() |
|
||||
{ |
|
||||
_permissionAppService = GetRequiredService<IPermissionAppService>(); |
|
||||
_permissionGrantRepository = GetRequiredService<IPermissionGrantRepository>(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task GetAsync() |
|
||||
{ |
|
||||
var permissionListResultDto = await _permissionAppService.GetAsync(UserPermissionValueProvider.ProviderName, |
|
||||
PermissionTestDataBuilder.User1Id.ToString()); |
|
||||
|
|
||||
permissionListResultDto.ShouldNotBeNull(); |
|
||||
permissionListResultDto.EntityDisplayName.ShouldBe(PermissionTestDataBuilder.User1Id.ToString()); |
|
||||
permissionListResultDto.Groups.Count.ShouldBe(1); |
|
||||
permissionListResultDto.Groups.ShouldContain(x => x.Name == "TestGroup"); |
|
||||
|
|
||||
permissionListResultDto.Groups.First().Permissions.Count.ShouldBe(4); |
|
||||
permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission1"); |
|
||||
permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission2"); |
|
||||
permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission2.ChildPermission1"); |
|
||||
permissionListResultDto.Groups.First().Permissions.ShouldContain(x => x.Name == "MyPermission3"); |
|
||||
|
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task UpdateAsync() |
|
||||
{ |
|
||||
(await _permissionGrantRepository.FindAsync("MyPermission1", "Test", |
|
||||
PermissionTestDataBuilder.User1Id.ToString())).ShouldBeNull(); |
|
||||
|
|
||||
await _permissionAppService.UpdateAsync("Test", |
|
||||
PermissionTestDataBuilder.User1Id.ToString(), new UpdatePermissionsDto() |
|
||||
{ |
|
||||
Permissions = new UpdatePermissionDto[] |
|
||||
{ |
|
||||
new UpdatePermissionDto() |
|
||||
{ |
|
||||
IsGranted = true, |
|
||||
Name = "MyPermission1" |
|
||||
} |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
(await _permissionGrantRepository.FindAsync("MyPermission1", "Test", |
|
||||
PermissionTestDataBuilder.User1Id.ToString())).ShouldNotBeNull(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task Update_Revoke_Test() |
|
||||
{ |
|
||||
_permissionGrantRepository.Insert( |
|
||||
new PermissionGrant( |
|
||||
Guid.NewGuid(), |
|
||||
"MyPermission1", |
|
||||
"Test", |
|
||||
PermissionTestDataBuilder.User1Id.ToString() |
|
||||
) |
|
||||
); |
|
||||
(await _permissionGrantRepository.FindAsync("MyPermission1", "Test", |
|
||||
PermissionTestDataBuilder.User1Id.ToString())).ShouldNotBeNull(); |
|
||||
|
|
||||
await _permissionAppService.UpdateAsync("Test", |
|
||||
PermissionTestDataBuilder.User1Id.ToString(), new UpdatePermissionsDto() |
|
||||
{ |
|
||||
Permissions = new UpdatePermissionDto[] |
|
||||
{ |
|
||||
new UpdatePermissionDto() |
|
||||
{ |
|
||||
IsGranted = false, |
|
||||
Name = "MyPermission1" |
|
||||
} |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
(await _permissionGrantRepository.FindAsync("MyPermission1", "Test", |
|
||||
PermissionTestDataBuilder.User1Id.ToString())).ShouldBeNull(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,25 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Text; |
|
||||
using Volo.Abp.Guids; |
|
||||
using Volo.Abp.MultiTenancy; |
|
||||
|
|
||||
namespace Volo.Abp.PermissionManagement |
|
||||
{ |
|
||||
public class TestPermissionManagementProvider : PermissionManagementProvider |
|
||||
{ |
|
||||
public override string Name => "Test"; |
|
||||
|
|
||||
public TestPermissionManagementProvider( |
|
||||
IPermissionGrantRepository permissionGrantRepository, |
|
||||
IGuidGenerator guidGenerator, |
|
||||
ICurrentTenant currentTenant) |
|
||||
: base( |
|
||||
permissionGrantRepository, |
|
||||
guidGenerator, |
|
||||
currentTenant) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue