mirror of https://github.com/abpframework/abp.git
6 changed files with 138 additions and 0 deletions
@ -0,0 +1,22 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Features |
||||
|
{ |
||||
|
public class DefaultValueFeatureValueProvider : FeatureValueProvider |
||||
|
{ |
||||
|
public const string ProviderName = "Default"; |
||||
|
|
||||
|
public override string Name => ProviderName; |
||||
|
|
||||
|
public DefaultValueFeatureValueProvider(IFeatureStore settingStore) |
||||
|
: base(settingStore) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public override Task<string> GetOrNullAsync(FeatureDefinition setting) |
||||
|
{ |
||||
|
return Task.FromResult(setting.DefaultValue); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
using Shouldly; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Features |
||||
|
{ |
||||
|
public class FeatureChecker_Tests : AbpFeaturesTestBase |
||||
|
{ |
||||
|
private readonly IFeatureChecker _featureChecker; |
||||
|
private readonly ICurrentTenant _currentTenant; |
||||
|
|
||||
|
public FeatureChecker_Tests() |
||||
|
{ |
||||
|
_featureChecker = GetRequiredService<IFeatureChecker>(); |
||||
|
_currentTenant = GetRequiredService<ICurrentTenant>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task IsEnabledAsync() |
||||
|
{ |
||||
|
//Tenant is unknown
|
||||
|
(await _featureChecker.IsEnabledAsync("BooleanTestFeature1")).ShouldBeFalse(); |
||||
|
|
||||
|
using (_currentTenant.Change(TestFeatureStore.Tenant1Id)) |
||||
|
{ |
||||
|
(await _featureChecker.IsEnabledAsync("BooleanTestFeature1")).ShouldBeTrue(); |
||||
|
} |
||||
|
|
||||
|
using (_currentTenant.Change(TestFeatureStore.Tenant2Id)) |
||||
|
{ |
||||
|
(await _featureChecker.IsEnabledAsync("BooleanTestFeature1")).ShouldBeFalse(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetOrNullAsync() |
||||
|
{ |
||||
|
//Tenant is unknown
|
||||
|
(await _featureChecker.GetOrNullAsync("IntegerTestFeature1")).ShouldBe("1"); |
||||
|
|
||||
|
using (_currentTenant.Change(TestFeatureStore.Tenant1Id)) |
||||
|
{ |
||||
|
(await _featureChecker.GetOrNullAsync("IntegerTestFeature1")).ShouldBe("1"); |
||||
|
} |
||||
|
|
||||
|
using (_currentTenant.Change(TestFeatureStore.Tenant2Id)) |
||||
|
{ |
||||
|
(await _featureChecker.GetOrNullAsync("IntegerTestFeature1")).ShouldBe("34"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Features |
||||
|
{ |
||||
|
public class TestFeatureStore : IFeatureStore, ISingletonDependency |
||||
|
{ |
||||
|
public static Guid Tenant1Id = new Guid("f460fcf7-f944-469a-967b-3b2463323dfe"); |
||||
|
public static Guid Tenant2Id = new Guid("e10428ad-4608-4c34-a304-6f82502156f2"); |
||||
|
|
||||
|
private readonly List<SettingRecord> _settingRecords; |
||||
|
|
||||
|
public TestFeatureStore() |
||||
|
{ |
||||
|
_settingRecords = new List<SettingRecord> |
||||
|
{ |
||||
|
new SettingRecord("BooleanTestFeature1", TenantFeatureValueProvider.ProviderName, Tenant1Id.ToString(), "true"), |
||||
|
new SettingRecord("IntegerTestFeature1", TenantFeatureValueProvider.ProviderName, Tenant2Id.ToString(), "34") |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
public Task<string> GetOrNullAsync(string name, string providerName, string providerKey) |
||||
|
{ |
||||
|
return Task.FromResult( |
||||
|
_settingRecords.FirstOrDefault(sr => |
||||
|
sr.Name == name && |
||||
|
sr.ProviderName == providerName && |
||||
|
sr.ProviderKey == providerKey |
||||
|
)?.Value |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
private class SettingRecord |
||||
|
{ |
||||
|
public string Name { get; } |
||||
|
public string ProviderName { get; } |
||||
|
public string ProviderKey { get; } |
||||
|
public string Value { get; } |
||||
|
|
||||
|
public SettingRecord(string name, string providerName, string providerKey, string value) |
||||
|
{ |
||||
|
Name = name; |
||||
|
ProviderName = providerName; |
||||
|
ProviderKey = providerKey; |
||||
|
Value = value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue