diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreModule.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreModule.cs index f5fc6e2c84..4612a52e22 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreModule.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreModule.cs @@ -14,9 +14,9 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore { context.Services.AddAbpDbContext(options => { - /* Add custom repositories here. Example: - * options.AddRepository(); - */ + options.AddDefaultRepositories(); + + options.AddRepository(); }); } } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs new file mode 100644 index 0000000000..9545ac36b4 --- /dev/null +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.FeatureManagement.EntityFrameworkCore +{ + public class EfCoreFeatureValueRepository : EfCoreRepository, IFeatureValueRepository + { + public EfCoreFeatureValueRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + + public async Task FindAsync(string name, string providerName, string providerKey) + { + return await DbSet + .FirstOrDefaultAsync( + s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey + ); + } + + public async Task> GetListAsync(string providerName, string providerKey) + { + return await DbSet + .Where( + s => s.ProviderName == providerName && s.ProviderKey == providerKey + ).ToListAsync(); + } + } +} \ No newline at end of file diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContext.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContext.cs index 605192d01f..61452f178a 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContext.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContext.cs @@ -11,6 +11,8 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore public static string Schema { get; set; } = FeatureManagementConsts.DefaultDbSchema; + public DbSet FeatureValues { get; set; } + public FeatureManagementDbContext(DbContextOptions options) : base(options) { diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContextModelCreatingExtensions.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContextModelCreatingExtensions.cs index 13144a8851..19abd9d6a5 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContextModelCreatingExtensions.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureManagementDbContextModelCreatingExtensions.cs @@ -15,23 +15,17 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore optionsAction?.Invoke(options); - /* Configure all entities here. Example: - - builder.Entity(b => + builder.Entity(b => { - //Configure table & schema name - //b.ToTable(options.TablePrefix + "Questions", options.Schema); - - //Properties - //b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength); - - //Configure relations - //b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId); + b.ToTable(options.TablePrefix + "FeatureValues", options.Schema); + + b.Property(x => x.Name).HasMaxLength(FeatureValueConsts.MaxNameLength).IsRequired(); + b.Property(x => x.Value).HasMaxLength(FeatureValueConsts.MaxValueLength).IsRequired(); + b.Property(x => x.ProviderName).HasMaxLength(FeatureValueConsts.MaxProviderNameLength); + b.Property(x => x.ProviderKey).HasMaxLength(FeatureValueConsts.MaxProviderKeyLength); - //Configure indexes - //b.HasIndex(q => q.CreationTime); + b.HasIndex(x => new { x.Name, x.ProviderName, x.ProviderKey }); }); - */ } } } \ No newline at end of file diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/IFeatureManagementDbContext.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/IFeatureManagementDbContext.cs index fce0720ea2..e687c9f0f6 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/IFeatureManagementDbContext.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/IFeatureManagementDbContext.cs @@ -1,4 +1,5 @@ -using Volo.Abp.Data; +using Microsoft.EntityFrameworkCore; +using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; namespace Volo.Abp.FeatureManagement.EntityFrameworkCore @@ -6,8 +7,6 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore [ConnectionStringName("AbpFeatureManagement")] public interface IFeatureManagementDbContext : IEfCoreDbContext { - /* Add DbSet for each Aggregate Root here. Example: - * DbSet Questions { get; } - */ + DbSet FeatureValues { get; set; } } } \ No newline at end of file diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/FeatureManagementDomainTestBase.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/FeatureManagementDomainTestBase.cs index 43221f9722..a5307e711c 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/FeatureManagementDomainTestBase.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/FeatureManagementDomainTestBase.cs @@ -1,6 +1,4 @@ -using Abp.FeatureManagement; - -namespace Volo.Abp.FeatureManagement +namespace Volo.Abp.FeatureManagement { public abstract class FeatureManagementDomainTestBase : FeatureManagementTestBase { diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs index 9d0d365137..7a1eef410e 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs @@ -1,5 +1,4 @@ -using Abp.FeatureManagement; -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureValueRepositoryTests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureValueRepositoryTests.cs new file mode 100644 index 0000000000..8283d80a5f --- /dev/null +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/FeatureValueRepositoryTests.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.FeatureManagement.EntityFrameworkCore +{ + public class FeatureValueRepositoryTests : FeatureValueRepository_Tests + { + + } +} diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/MyEntityRepository_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/MyEntityRepository_Tests.cs deleted file mode 100644 index 3fb7ce94a2..0000000000 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/MyEntityRepository_Tests.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Abp.FeatureManagement; - -namespace Volo.Abp.FeatureManagement.EntityFrameworkCore -{ - public class MyEntityRepository_Tests : MyEntityRepository_Tests - { - - } -} diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Abp/FeatureManagement/MongoDB/MyEntityRepository_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Abp/FeatureManagement/MongoDB/MyEntityRepository_Tests.cs deleted file mode 100644 index b486522b80..0000000000 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Abp/FeatureManagement/MongoDB/MyEntityRepository_Tests.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Abp.FeatureManagement.MongoDB -{ - public class MyEntityRepository_Tests : MyEntityRepository_Tests - { - - } -} diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Abp/FeatureManagement/MongoDB/AbpFeatureManagementMongoDbTestModule.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/AbpFeatureManagementMongoDbTestModule.cs similarity index 88% rename from modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Abp/FeatureManagement/MongoDB/AbpFeatureManagementMongoDbTestModule.cs rename to modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/AbpFeatureManagementMongoDbTestModule.cs index bde5a3aac2..bc5dfa0b52 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Abp/FeatureManagement/MongoDB/AbpFeatureManagementMongoDbTestModule.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/AbpFeatureManagementMongoDbTestModule.cs @@ -1,10 +1,8 @@ using Mongo2Go; -using Volo.Abp; using Volo.Abp.Data; -using Volo.Abp.FeatureManagement.MongoDB; using Volo.Abp.Modularity; -namespace Abp.FeatureManagement.MongoDB +namespace Volo.Abp.FeatureManagement.MongoDB { [DependsOn( typeof(AbpFeatureManagementTestBaseModule), diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/FeatureValueRepositoryTests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/FeatureValueRepositoryTests.cs new file mode 100644 index 0000000000..6184e4c90f --- /dev/null +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.MongoDB.Tests/Volo/Abp/FeatureManagement/MongoDB/FeatureValueRepositoryTests.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.FeatureManagement.MongoDB +{ + public class FeatureValueRepositoryTests : FeatureValueRepository_Tests + { + + } +} diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestDataBuilder.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestDataBuilder.cs deleted file mode 100644 index d6da7b6ab0..0000000000 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestDataBuilder.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Volo.Abp.DependencyInjection; -using Volo.Abp.Guids; - -namespace Abp.FeatureManagement -{ - public class FeatureManagementTestDataBuilder : ITransientDependency - { - private readonly IGuidGenerator _guidGenerator; - private FeatureManagementTestData _testData; - - public FeatureManagementTestDataBuilder( - IGuidGenerator guidGenerator, - FeatureManagementTestData testData) - { - _guidGenerator = guidGenerator; - _testData = testData; - } - - public void Build() - { - - } - } -} \ No newline at end of file diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/MyEntityRepository_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/MyEntityRepository_Tests.cs deleted file mode 100644 index 67b7f258ec..0000000000 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/MyEntityRepository_Tests.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Threading.Tasks; -using Volo.Abp.Modularity; -using Xunit; - -namespace Abp.FeatureManagement -{ - public abstract class MyEntityRepository_Tests : FeatureManagementTestBase - where TStartupModule : IAbpModule - { - [Fact] - public async Task Test1() - { - - } - } -} diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/AbpFeatureManagementTestBaseModule.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/AbpFeatureManagementTestBaseModule.cs similarity index 71% rename from modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/AbpFeatureManagementTestBaseModule.cs rename to modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/AbpFeatureManagementTestBaseModule.cs index 6234c62978..0519d65855 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/AbpFeatureManagementTestBaseModule.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/AbpFeatureManagementTestBaseModule.cs @@ -1,11 +1,10 @@ -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; +using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Authorization; using Volo.Abp.Autofac; -using Volo.Abp.FeatureManagement; using Volo.Abp.Modularity; -namespace Abp.FeatureManagement +namespace Volo.Abp.FeatureManagement { [DependsOn( typeof(AbpAutofacModule), @@ -18,6 +17,14 @@ namespace Abp.FeatureManagement public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAlwaysAllowAuthorization(); + + Configure(options => + { + options.Providers.InsertBefore( + typeof(TenantFeatureManagementProvider), + typeof(EditionFeatureManagementProvider) + ); + }); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/EditionFeatureManagementProvider.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/EditionFeatureManagementProvider.cs new file mode 100644 index 0000000000..6e16f73dfa --- /dev/null +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/EditionFeatureManagementProvider.cs @@ -0,0 +1,14 @@ +namespace Volo.Abp.FeatureManagement +{ + public class EditionFeatureManagementProvider : FeatureManagementProvider + { + public const string ProviderName = "Edition"; + + public override string Name => ProviderName; + + public EditionFeatureManagementProvider(IFeatureManagementStore store) + : base(store) + { + } + } +} \ No newline at end of file diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestBase.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestBase.cs similarity index 80% rename from modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestBase.cs rename to modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestBase.cs index c13001f96a..66ab983ebe 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestBase.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestBase.cs @@ -1,7 +1,6 @@ -using Volo.Abp; -using Volo.Abp.Modularity; +using Volo.Abp.Modularity; -namespace Abp.FeatureManagement +namespace Volo.Abp.FeatureManagement { public abstract class FeatureManagementTestBase : AbpIntegratedTest where TStartupModule : IAbpModule diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestData.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestData.cs similarity index 76% rename from modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestData.cs rename to modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestData.cs index 272230d17e..e6d2273307 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Abp/FeatureManagement/FeatureManagementTestData.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestData.cs @@ -1,6 +1,6 @@ using Volo.Abp.DependencyInjection; -namespace Abp.FeatureManagement +namespace Volo.Abp.FeatureManagement { public class FeatureManagementTestData : ISingletonDependency { diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestDataBuilder.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestDataBuilder.cs new file mode 100644 index 0000000000..98c6218d8e --- /dev/null +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestDataBuilder.cs @@ -0,0 +1,186 @@ +using Volo.Abp.DependencyInjection; +using Volo.Abp.Features; +using Volo.Abp.Guids; + +namespace Volo.Abp.FeatureManagement +{ + public class FeatureManagementTestDataBuilder : ITransientDependency + { + private readonly IFeatureValueRepository _featureValueRepository; + private readonly IGuidGenerator _guidGenerator; + private readonly FeatureManagementTestData _testData; + + public FeatureManagementTestDataBuilder( + IGuidGenerator guidGenerator, + FeatureManagementTestData testData, + IFeatureValueRepository featureValueRepository) + { + _guidGenerator = guidGenerator; + _testData = testData; + _featureValueRepository = featureValueRepository; + } + + public void Build() + { + // "Regular" edition features ///////////////////////////////////// + + //SocialLogins + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.SocialLogins, + true.ToString().ToLowerInvariant(), + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Regular + ) + ); + + //UserCount + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.UserCount, + "10", + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Regular + ) + ); + + //ProjectCount + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.ProjectCount, + "1", + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Regular + ) + ); + + // "Enterprise" edition features ////////////////////////////////// + + //SocialLogins + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.SocialLogins, + true.ToString().ToLowerInvariant(), + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //EmailSupport + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.EmailSupport, + true.ToString().ToLowerInvariant(), + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //UserCount + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.UserCount, + "20", + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //ProjectCount + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.ProjectCount, + "3", + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //BackupCount + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.BackupCount, + "5", + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + // "Ultimate" edition features //////////////////////////////////// + + //SocialLogins + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.SocialLogins, + true.ToString().ToLowerInvariant(), + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //EmailSupport + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.EmailSupport, + true.ToString().ToLowerInvariant(), + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //EmailSupport + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.DailyAnalysis, + true.ToString().ToLowerInvariant(), + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //UserCount + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.UserCount, + "100", + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //ProjectCount + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.ProjectCount, + "10", + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + + //BackupCount + _featureValueRepository.Insert( + new FeatureValue( + _guidGenerator.Create(), + TestFeatureDefinitionProvider.BackupCount, + "10", + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ) + ); + } + } +} \ No newline at end of file diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs new file mode 100644 index 0000000000..ed32c8971d --- /dev/null +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs @@ -0,0 +1,60 @@ +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.Modularity; +using Xunit; + +namespace Volo.Abp.FeatureManagement +{ + public abstract class FeatureValueRepository_Tests : FeatureManagementTestBase + where TStartupModule : IAbpModule + { + protected IFeatureValueRepository Repository { get; set; } + + protected FeatureValueRepository_Tests() + { + Repository = GetRequiredService(); + } + + [Fact] + public async Task FindAsync() + { + //feature value does exists + + var featureValue = await Repository.FindAsync( + TestFeatureDefinitionProvider.ProjectCount, + EditionFeatureManagementProvider.ProviderName, + TestEditionNames.Enterprise + ); + + featureValue.ShouldNotBeNull(); + featureValue.Value.ShouldBe("3"); + + //feature value does not exists + featureValue = await Repository.FindAsync( + TestFeatureDefinitionProvider.ProjectCount, + EditionFeatureManagementProvider.ProviderName, + "undefined-edition-name" + ); + + featureValue.ShouldBeNull(); + } + + [Fact] + public async Task GetListAsync() + { + var featureValues = await Repository.GetListAsync(EditionFeatureManagementProvider.ProviderName, TestEditionNames.Enterprise); + + featureValues.Count.ShouldBeGreaterThan(0); + + featureValues.ShouldContain( + fv => fv.Name == TestFeatureDefinitionProvider.SocialLogins && + fv.Value == "true" + ); + + featureValues.ShouldContain( + fv => fv.Name == TestFeatureDefinitionProvider.ProjectCount && + fv.Value == "3" + ); + } + } +} diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/TestEditionNames.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/TestEditionNames.cs new file mode 100644 index 0000000000..d398ead4bb --- /dev/null +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/TestEditionNames.cs @@ -0,0 +1,9 @@ +namespace Volo.Abp.FeatureManagement +{ + public static class TestEditionNames + { + public const string Regular = "Regular"; + public const string Enterprise = "Enterprise"; + public const string Ultimate = "Ultimate"; + } +} \ No newline at end of file diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/TestFeatureDefinitionProvider.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/TestFeatureDefinitionProvider.cs new file mode 100644 index 0000000000..8c4dfdf06b --- /dev/null +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/TestFeatureDefinitionProvider.cs @@ -0,0 +1,54 @@ +using Volo.Abp.Features; +using Volo.Abp.Validation.StringValues; + +namespace Volo.Abp.FeatureManagement +{ + public class TestFeatureDefinitionProvider : FeatureDefinitionProvider + { + public const string SocialLogins = "SocialLogins"; + public const string EmailSupport = "EmailSupport"; + public const string DailyAnalysis = "DailyAnalysis"; + public const string UserCount = "UserCount"; + public const string ProjectCount = "ProjectCount"; + public const string BackupCount = "BackupCount"; + + public override void Define(IFeatureDefinitionContext context) + { + var group = context.AddGroup("TestGroup"); + + group.AddFeature( + SocialLogins, + valueType: new ToggleStringValueType() + ); + + group.AddFeature( + EmailSupport, + valueType: new ToggleStringValueType() + ); + + group.AddFeature( + DailyAnalysis, + defaultValue: false.ToString().ToLowerInvariant(), //Optional, it is already false by default + valueType: new ToggleStringValueType() + ); + + group.AddFeature( + UserCount, + defaultValue: "1", + valueType: new FreeTextStringValueType(new NumericValueValidator(1, 1000)) + ); + + group.AddFeature( + ProjectCount, + defaultValue: "1", + valueType: new FreeTextStringValueType(new NumericValueValidator(1, 10)) + ); + + group.AddFeature( + BackupCount, + defaultValue: "0", + valueType: new FreeTextStringValueType(new NumericValueValidator(0, 10)) + ); + } + } +} diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementDbContext.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementDbContext.cs deleted file mode 100644 index 7118aae6fe..0000000000 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementDbContext.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Volo.Abp.Data; -using Volo.Abp.EntityFrameworkCore; - -namespace Volo.Abp.SettingManagement.EntityFrameworkCore -{ - [ConnectionStringName("AbpSettingManagement")] - public class AbpSettingManagementDbContext : AbpDbContext, ISettingManagementDbContext - { - public static string TablePrefix { get; set; } = AbpSettingManagementConsts.DefaultDbTablePrefix; - - public static string Schema { get; set; } = AbpSettingManagementConsts.DefaultDbSchema; - - public DbSet Settings { get; set; } - - public AbpSettingManagementDbContext(DbContextOptions options) - : base(options) - { - - } - - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); - - builder.ConfigureSettingManagement(TablePrefix, Schema); - } - } -} diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementDbContextModelBuilderExtensions.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementDbContextModelBuilderExtensions.cs deleted file mode 100644 index 75de647690..0000000000 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.EntityFrameworkCore/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementDbContextModelBuilderExtensions.cs +++ /dev/null @@ -1,33 +0,0 @@ -using JetBrains.Annotations; -using Microsoft.EntityFrameworkCore; - -namespace Volo.Abp.SettingManagement.EntityFrameworkCore -{ - public static class AbpSettingManagementDbContextModelBuilderExtensions - { - public static void ConfigureSettingManagement( - [NotNull] this ModelBuilder builder, - [CanBeNull] string tablePrefix = AbpSettingManagementConsts.DefaultDbTablePrefix, - [CanBeNull] string schema = AbpSettingManagementConsts.DefaultDbSchema) - { - Check.NotNull(builder, nameof(builder)); - - if (tablePrefix == null) - { - tablePrefix = ""; - } - - builder.Entity(b => - { - b.ToTable(tablePrefix + "Settings", schema); - - b.Property(x => x.Name).HasMaxLength(SettingConsts.MaxNameLength).IsRequired(); - b.Property(x => x.Value).HasMaxLength(SettingConsts.MaxValueLength).IsRequired(); - b.Property(x => x.ProviderName).HasMaxLength(SettingConsts.MaxProviderNameLength); - b.Property(x => x.ProviderKey).HasMaxLength(SettingConsts.MaxProviderKeyLength); - - b.HasIndex(x => new {x.Name, x.ProviderName, x.ProviderKey}); - }); - } - } -} \ No newline at end of file