mirror of https://github.com/abpframework/abp.git
13 changed files with 173 additions and 24 deletions
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.Features |
|||
{ |
|||
public static class AbpFeatureErrorCodes |
|||
{ |
|||
public const string FeatureIsNotEnabled = "Volo.Feature:010001"; |
|||
|
|||
public const string AllOfTheseFeaturesMustBeEnabled = "Volo.Feature:010002"; |
|||
|
|||
public const string AtLeastOneOfTheseFeaturesMustBeEnabled = "Volo.Feature:010003"; |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.Abp.Features.Localization |
|||
{ |
|||
[LocalizationResourceName("AbpFeature")] |
|||
public class AbpFeatureResource |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"Volo.Feature:010001": "Feature is not enabled: {FeatureName}", |
|||
"Volo.Feature:010002": "Required features are not enabled. All of these features must be enabled: {FeatureNames}", |
|||
"Volo.Feature:010003": "Required features are not enabled. At least one of these features must be enabled: {FeatureNames}" |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
{ |
|||
"culture": "tr", |
|||
"texts": { |
|||
"Volo.Feature:010001": "Özellik etkinleştirilmedi: {FeatureName}", |
|||
"Volo.Feature:010002": "Gerekli özellikler etkinleştirilmedi. Bu özelliklerin tümü etkinleştirilmelidir: {FeatureNames}", |
|||
"Volo.Feature:010003": "Gerekli özellikler etkinleştirilmedi. Bu özelliklerden en az birinin etkinleştirilmesi gerekir: {FeatureNames}" |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
{ |
|||
"culture": "zh-Hans", |
|||
"texts": { |
|||
"Volo.Feature:010001": "功能未启用: {FeatureName}", |
|||
"Volo.Feature:010002": "必要的功能未启用. 这些功能需要启用: {FeatureNames}", |
|||
"Volo.Feature:010003": "必要的功能未启用. 需要启用这些功能中的一项:{FeatureNames}" |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.AspNetCore.ExceptionHandling; |
|||
using Volo.Abp.Authorization; |
|||
using Volo.Abp.Localization; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Features |
|||
{ |
|||
public class FeatureCheckerExtensions_Tests : FeatureTestBase |
|||
{ |
|||
private readonly IFeatureChecker _featureChecker; |
|||
private readonly IExceptionToErrorInfoConverter _exceptionToErrorInfoConverter; |
|||
|
|||
public FeatureCheckerExtensions_Tests() |
|||
{ |
|||
_featureChecker = GetRequiredService<IFeatureChecker>(); |
|||
_exceptionToErrorInfoConverter = GetRequiredService<IExceptionToErrorInfoConverter>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CheckEnabledAsync() |
|||
{ |
|||
using (CultureHelper.Use("zh-Hans")) |
|||
{ |
|||
var ex = await Assert.ThrowsAsync<AbpAuthorizationException>(async () => |
|||
await _featureChecker.CheckEnabledAsync("BooleanTestFeature1")); |
|||
|
|||
var errorInfo = _exceptionToErrorInfoConverter.Convert(ex, false); |
|||
errorInfo.Message.ShouldBe("功能未启用: BooleanTestFeature1"); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CheckEnabled_RequiresAll() |
|||
{ |
|||
using (CultureHelper.Use("zh-Hans")) |
|||
{ |
|||
var ex = await Assert.ThrowsAsync<AbpAuthorizationException>(async () => |
|||
await _featureChecker.CheckEnabledAsync(true, "BooleanTestFeature1", "BooleanTestFeature2")); |
|||
|
|||
var errorInfo = _exceptionToErrorInfoConverter.Convert(ex, false); |
|||
errorInfo.Message.ShouldBe("必要的功能未启用. 这些功能需要启用: BooleanTestFeature1, BooleanTestFeature2"); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task CheckEnabled_Not_RequiresAll() |
|||
{ |
|||
using (CultureHelper.Use("zh-Hans")) |
|||
{ |
|||
var ex = await Assert.ThrowsAsync<AbpAuthorizationException>(async () => |
|||
await _featureChecker.CheckEnabledAsync(false, "BooleanTestFeature1", "BooleanTestFeature2")); |
|||
|
|||
var errorInfo = _exceptionToErrorInfoConverter.Convert(ex, false); |
|||
errorInfo.Message.ShouldBe("必要的功能未启用. 需要启用这些功能中的一项:BooleanTestFeature1, BooleanTestFeature2"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue