Browse Source

authorization tests with role

pull/2659/head
Mehmet Perk 7 years ago
parent
commit
5016ba69a3
  1. 9
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/Authorization_Tests.cs
  2. 2
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/IMyAuthorizedService1.cs
  3. 6
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/MyAuthorizedService1.cs

9
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/Authorization_Tests.cs

@ -52,5 +52,14 @@ namespace Volo.Abp.Authorization
{
_permissionDefinitionManager.GetGroups().Count.ShouldBe(1);
}
[Fact]
public async Task Should_Not_Allow_To_Call_Method_If_Has_No_Role_ProtectedByRole_Async()
{
await Assert.ThrowsAsync<AbpAuthorizationException>(async () =>
{
await _myAuthorizedService1.ProtectedByRole().ConfigureAwait(false);
}).ConfigureAwait(false);
}
}
}

2
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/IMyAuthorizedService1.cs

@ -11,5 +11,7 @@ namespace Volo.Abp.Authorization.TestServices
Task<int> ProtectedByClass();
Task<int> ProtectedByClassAsync();
Task<int> ProtectedByRole();
}
}

6
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/MyAuthorizedService1.cs

@ -30,5 +30,11 @@ namespace Volo.Abp.Authorization.TestServices
await Task.Delay(10).ConfigureAwait(false);
return 42;
}
[Authorize(Roles = "MyRole")]
public virtual Task<int> ProtectedByRole()
{
return Task.FromResult(42);
}
}
}
Loading…
Cancel
Save