diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicMaxLengthAttribute.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicMaxLengthAttribute.cs index c76a54bdc2..59d5bcfa47 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicMaxLengthAttribute.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Validation/DynamicMaxLengthAttribute.cs @@ -13,7 +13,7 @@ namespace Volo.Abp.Validation static DynamicMaxLengthAttribute() { MaximumLengthField = typeof(MaxLengthAttribute).GetField( - "k__BackingField", + "k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic ); Debug.Assert(MaximumLengthField != null, nameof(MaximumLengthField) + " != null"); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController.cs index df033c99b5..6ce47c4679 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController.cs @@ -56,12 +56,17 @@ namespace Volo.Abp.AspNetCore.Mvc.Validation [DynamicMaxLength(typeof(Consts), nameof(Consts.MaxValue2Length))] public string Value2 { get; set; } + [DynamicMaxLength(typeof(Consts), nameof(Consts.MaxValue3Length))] + public int[] Value3 { get; set; } + public static class Consts { public static int MinValue1Length { get; set; } = 2; public static int MaxValue1Length { get; set; } = 7; public static int MaxValue2Length { get; set; } = 4; + + public static int MaxValue3Length { get; set; } = 2; } } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController_Tests.cs index 6a16e8e899..9e22784ba7 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Validation/ValidationTestController_Tests.cs @@ -61,7 +61,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Validation [Fact] public async Task Should_Validate_Dynamic_Length_Object_Result_Success() { - var result = await GetResponseAsStringAsync("/api/validation-test/object-result-action-dynamic-length?value1=hello"); + var result = await GetResponseAsStringAsync("/api/validation-test/object-result-action-dynamic-length?value1=hello&value3[0]=53&value3[1]=54"); result.ShouldBe("hello"); } @@ -75,9 +75,11 @@ namespace Volo.Abp.AspNetCore.Mvc.Validation result = await GetResponseAsObjectAsync("/api/validation-test/object-result-action-dynamic-length?value1=12345678", HttpStatusCode.BadRequest); //value1 has max string length of 7 chars. result.Error.ValidationErrors.Length.ShouldBeGreaterThan(0); - result = await GetResponseAsObjectAsync("/api/validation-test/object-result-action-dynamic-length?value1=123458&value2=12345", HttpStatusCode.BadRequest); //value2 has max length of 5 chars. result.Error.ValidationErrors.Length.ShouldBeGreaterThan(0); + + result = await GetResponseAsObjectAsync("/api/validation-test/object-result-action-dynamic-length?value1=123458&value3[0]=53&value3[1]=54&value3[2]=55&value3[3]=56", HttpStatusCode.BadRequest); //value3 has max length of 2. + result.Error.ValidationErrors.Length.ShouldBeGreaterThan(0); } } }