Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Changed min/max parameter order in StringLengthAttributeAdapter #4899

Merged
merged 3 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public override string GetErrorMessage(ModelValidationContextBase validationCont
return GetErrorMessage(
validationContext.ModelMetadata,
validationContext.ModelMetadata.GetDisplayName(),
Attribute.MinimumLength,
Attribute.MaximumLength);
Attribute.MaximumLength,
Attribute.MinimumLength);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public static TheoryData Validate_AttributesIncludeValues
{
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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public class StringLengthAttributeAdapterTest
{
[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<IStringLocalizer>();
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));
Expand Down