From c319ae51a5a575d2bd6a100f6892ab269648a5f3 Mon Sep 17 00:00:00 2001 From: Crystal Qian Date: Mon, 27 Jun 2016 10:21:50 -0700 Subject: [PATCH] Changed min/max parameter order in StringLengthAttributeAdapter (#4899) Changed min/max parameter order in StringLengthAttributeAdapter. This fixes #4864. --- .../Internal/StringLengthAttributeAdapter.cs | 4 ++-- .../Internal/DataAnnotationsModelValidatorTest.cs | 2 +- .../Internal/StringLengthAttributeAdapterTest.cs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/StringLengthAttributeAdapter.cs b/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/StringLengthAttributeAdapter.cs index 02978ba975..f733d4470a 100644 --- a/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/StringLengthAttributeAdapter.cs +++ b/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/StringLengthAttributeAdapter.cs @@ -54,8 +54,8 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal return GetErrorMessage( validationContext.ModelMetadata, validationContext.ModelMetadata.GetDisplayName(), - Attribute.MinimumLength, - Attribute.MaximumLength); + Attribute.MaximumLength, + Attribute.MinimumLength); } } } diff --git a/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/Internal/DataAnnotationsModelValidatorTest.cs b/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/Internal/DataAnnotationsModelValidatorTest.cs index 27e8ab60fb..9475575c29 100644 --- a/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/Internal/DataAnnotationsModelValidatorTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/Internal/DataAnnotationsModelValidatorTest.cs @@ -417,7 +417,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal { new StringLengthAttribute(length) { ErrorMessage = LocalizationKey, MinimumLength = 1}, string.Empty, - new object[] { nameof(SampleModel), 1, length } + new object[] { nameof(SampleModel), length, 1 } }, { new RangeAttribute(0, length) { ErrorMessage = LocalizationKey }, diff --git a/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/Internal/StringLengthAttributeAdapterTest.cs b/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/Internal/StringLengthAttributeAdapterTest.cs index 7b27758794..87c820dfe8 100644 --- a/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/Internal/StringLengthAttributeAdapterTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.DataAnnotations.Test/Internal/StringLengthAttributeAdapterTest.cs @@ -16,19 +16,19 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal { [Fact] [ReplaceCulture] - public void AddValidation_WithMaxLength_AddsAttributes_Localize() + public void AddValidation_WithMaxLengthAndMinLength_AddsAttributes_Localize() { // Arrange var provider = TestModelMetadataProvider.CreateDefaultProvider(); var metadata = provider.GetMetadataForProperty(typeof(string), "Length"); 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(); - var expectedProperties = new object[] { "Length", 0, 8 }; + var expectedProperties = new object[] { "Length", 8, 0 }; stringLocalizer.Setup(s => s[attribute.ErrorMessage, expectedProperties]) .Returns(new LocalizedString(attribute.ErrorMessage, expectedMessage));