tests added

pull/4524/head
Ahmet Çotur 5 years ago
parent 4d3a54f4a3
commit 56cf234a6e

@ -13,7 +13,7 @@ namespace Volo.Abp.Validation
static DynamicMaxLengthAttribute()
{
MaximumLengthField = typeof(MaxLengthAttribute).GetField(
"<MaximumLength>k__BackingField",
"<Length>k__BackingField",
BindingFlags.Instance | BindingFlags.NonPublic
);
Debug.Assert(MaximumLengthField != null, nameof(MaximumLengthField) + " != null");

@ -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;
}
}

@ -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<RemoteServiceErrorResponse>("/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<RemoteServiceErrorResponse>("/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<RemoteServiceErrorResponse>("/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);
}
}
}

Loading…
Cancel
Save