public StringLengthAdapterTests() { adapter = new StringLengthAdapter(new StringLengthAttribute(128)); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "StringLength"); context = new ModelValidationContextBase(new ActionContext(), metadata, provider); }
public void GetErrorMessage_Range() { IModelMetadataProvider provider = new EmptyModelMetadataProvider(); RangeAdapter adapter = new RangeAdapter(new RangeAttribute(4, 128)); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "Range"); ModelValidationContextBase context = new ModelValidationContextBase(new ActionContext(), metadata, provider); String expected = String.Format(Validations.Range, "Range", 4, 128); String actual = adapter.GetErrorMessage(context); Assert.Equal(Validations.Range, adapter.Attribute.ErrorMessage); Assert.Equal(expected, actual); }
public override String GetErrorMessage(ModelValidationContextBase context) { Attribute.ErrorMessage = Validations.MinLength; return base.GetErrorMessage(context); }
private string GetErrorMessage(ModelValidationContextBase validationContext) { var adapter = _validationAttributeAdapterProvider.GetAttributeAdapter(Attribute, _stringLocalizer); return adapter?.GetErrorMessage(validationContext); }
public override String GetErrorMessage(ModelValidationContextBase context) { Attribute.ErrorMessage = Validations.Range; return GetErrorMessage(context.ModelMetadata); }