diff --git a/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation.Redis/LINGYUN/Abp/Features/LimitValidation/Redis/Lua/process.lua b/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation.Redis/LINGYUN/Abp/Features/LimitValidation/Redis/Lua/process.lua index fc8ef5307..869093094 100644 --- a/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation.Redis/LINGYUN/Abp/Features/LimitValidation/Redis/Lua/process.lua +++ b/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation.Redis/LINGYUN/Abp/Features/LimitValidation/Redis/Lua/process.lua @@ -1,6 +1,6 @@ if (redis.call('EXISTS',KEYS[1]) ~= 0) then redis.call('INCRBY',KEYS[1], 1) else - redis.call('SETEX',KEYS[1],ARGV[1],1) + redis.call('SET',KEYS[1],1, 'EX', ARGV[1]) end return tonumber(redis.call('GET',KEYS[1])) \ No newline at end of file diff --git a/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/AbpFeaturesLimitValidationOptions.cs b/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/AbpFeaturesLimitValidationOptions.cs index 97f9c3308..f7d158b50 100644 --- a/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/AbpFeaturesLimitValidationOptions.cs +++ b/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/AbpFeaturesLimitValidationOptions.cs @@ -50,7 +50,7 @@ internal void MapDefaultEffectPolicys() MapEffectPolicy(LimitPolicy.Days, (now, tick) => { // 按天计算应取当天 - return (long)(now.Date.AddDays(tick) - DateTime.UtcNow).TotalSeconds; + return (long)(now.Date.AddDays(tick) - now).TotalSeconds; }); MapEffectPolicy(LimitPolicy.Weeks,(now, tick) => @@ -64,7 +64,7 @@ internal void MapDefaultEffectPolicys() } var utcOnceDayOfWeek = nowDate.AddDays(-dayOfWeek); - return (long)(utcOnceDayOfWeek.AddDays(tick * 7) - DateTime.UtcNow).TotalSeconds; + return (long)(utcOnceDayOfWeek.AddDays(tick * 7) - now).TotalSeconds; }); MapEffectPolicy(LimitPolicy.Month, (now, tick) => diff --git a/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/RequiresLimitFeatureContext.cs b/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/RequiresLimitFeatureContext.cs index d5cf3c1f4..bef6ea518 100644 --- a/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/RequiresLimitFeatureContext.cs +++ b/aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/RequiresLimitFeatureContext.cs @@ -1,4 +1,5 @@ using System; +using Volo.Abp; namespace LINGYUN.Abp.Features.LimitValidation { @@ -29,11 +30,11 @@ public RequiresLimitFeatureContext( int interval = 1, int limit = 1) { - Limit = limit; Policy = policy; - Interval = interval; - LimitFeature = limitFeature; Options = options; + LimitFeature = limitFeature; + Limit = Check.Positive(limit, nameof(limit)); + Interval = Check.Positive(interval, nameof(interval)); } /// diff --git a/aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Redis.Tests/LINGYUN/Abp/Features/LimitValidation/Redis/AbpFeaturesLimitValidationRedisTestModule.cs b/aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Redis.Tests/LINGYUN/Abp/Features/LimitValidation/Redis/AbpFeaturesLimitValidationRedisTestModule.cs index 0a03e7df7..469dd19f1 100644 --- a/aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Redis.Tests/LINGYUN/Abp/Features/LimitValidation/Redis/AbpFeaturesLimitValidationRedisTestModule.cs +++ b/aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Redis.Tests/LINGYUN/Abp/Features/LimitValidation/Redis/AbpFeaturesLimitValidationRedisTestModule.cs @@ -1,6 +1,4 @@ using LINGYUN.Abp.Tests; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; namespace LINGYUN.Abp.Features.LimitValidation.Redis @@ -11,15 +9,5 @@ namespace LINGYUN.Abp.Features.LimitValidation.Redis typeof(AbpTestsBaseModule))] public class AbpFeaturesLimitValidationRedisTestModule : AbpModule { - public override void PreConfigureServices(ServiceConfigurationContext context) - { - var configurationOptions = new AbpConfigurationBuilderOptions - { - BasePath = @"D:\Projects\Development\Abp\FeaturesValidation\Redis", - EnvironmentName = "Development" - }; - - context.Services.ReplaceConfiguration(ConfigurationHelper.BuildConfiguration(configurationOptions)); - } } } diff --git a/aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Tests/LINGYUN/Abp/Features/LimitValidation/FeaturesLimitValidationTests.cs b/aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Tests/LINGYUN/Abp/Features/LimitValidation/FeaturesLimitValidationTests.cs index 1f29da6a9..360ee3613 100644 --- a/aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Tests/LINGYUN/Abp/Features/LimitValidation/FeaturesLimitValidationTests.cs +++ b/aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Tests/LINGYUN/Abp/Features/LimitValidation/FeaturesLimitValidationTests.cs @@ -27,10 +27,7 @@ public async Task Should_Not_Allow_To_Call_Method_If_Has_Limit_Feature_Async(str // it's ok await TestValidationFeatureClass.Test1MinuteAsync(); await TestValidationFeatureClass.Test1MinuteAsync(); - await Assert.ThrowsAsync(async () => - { - await TestValidationFeatureClass.Test1MinuteAsync(); - }); + await Assert.ThrowsAsync(TestValidationFeatureClass.Test1MinuteAsync); Thread.Sleep(61000); await TestValidationFeatureClass.Test1MinuteAsync();