Changed min/max parameter order in StringLengthAttributeAdapter (#4899)

Changed min/max parameter order in StringLengthAttributeAdapter. This fixes #4864.
This commit is contained in:
Crystal Qian 2016-06-27 10:21:50 -07:00 committed by GitHub
parent 72dbda8804
commit c319ae51a5
3 changed files with 7 additions and 7 deletions

View File

@ -54,8 +54,8 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
return GetErrorMessage( return GetErrorMessage(
validationContext.ModelMetadata, validationContext.ModelMetadata,
validationContext.ModelMetadata.GetDisplayName(), validationContext.ModelMetadata.GetDisplayName(),
Attribute.MinimumLength, Attribute.MaximumLength,
Attribute.MaximumLength); Attribute.MinimumLength);
} }
} }
} }

View File

@ -417,7 +417,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{ {
new StringLengthAttribute(length) { ErrorMessage = LocalizationKey, MinimumLength = 1}, new StringLengthAttribute(length) { ErrorMessage = LocalizationKey, MinimumLength = 1},
string.Empty, string.Empty,
new object[] { nameof(SampleModel), 1, length } new object[] { nameof(SampleModel), length, 1 }
}, },
{ {
new RangeAttribute(0, length) { ErrorMessage = LocalizationKey }, new RangeAttribute(0, length) { ErrorMessage = LocalizationKey },

View File

@ -16,19 +16,19 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal
{ {
[Fact] [Fact]
[ReplaceCulture] [ReplaceCulture]
public void AddValidation_WithMaxLength_AddsAttributes_Localize() public void AddValidation_WithMaxLengthAndMinLength_AddsAttributes_Localize()
{ {
// Arrange // Arrange
var provider = TestModelMetadataProvider.CreateDefaultProvider(); var provider = TestModelMetadataProvider.CreateDefaultProvider();
var metadata = provider.GetMetadataForProperty(typeof(string), "Length"); var metadata = provider.GetMetadataForProperty(typeof(string), "Length");
var attribute = new StringLengthAttribute(8); var attribute = new StringLengthAttribute(8);
attribute.ErrorMessage = "Property must not be longer than '{1}' characters."; attribute.ErrorMessage = "Property must not be longer than '{1}' characters and not shorter than '{2}' characters.";
var expectedMessage = "Property must not be longer than '8' characters."; var expectedMessage = "Property must not be longer than '8' characters and not shorter than '0' characters.";
var stringLocalizer = new Mock<IStringLocalizer>(); var stringLocalizer = new Mock<IStringLocalizer>();
var expectedProperties = new object[] { "Length", 0, 8 }; var expectedProperties = new object[] { "Length", 8, 0 };
stringLocalizer.Setup(s => s[attribute.ErrorMessage, expectedProperties]) stringLocalizer.Setup(s => s[attribute.ErrorMessage, expectedProperties])
.Returns(new LocalizedString(attribute.ErrorMessage, expectedMessage)); .Returns(new LocalizedString(attribute.ErrorMessage, expectedMessage));