public MinLengthAdapterTests() { attributes = new Dictionary <String, String>(); adapter = new MinLengthAdapter(new MinLengthAttribute(128)); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AllTypesView), nameof(AllTypesView.StringField)); context = new ClientModelValidationContext(new ActionContext(), metadata, provider, attributes); }
public void GetErrorMessage_MinLength() { IModelMetadataProvider provider = new EmptyModelMetadataProvider(); MinLengthAdapter adapter = new MinLengthAdapter(new MinLengthAttribute(128)); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AllTypesView), "StringField"); ModelValidationContextBase context = new ModelValidationContextBase(new ActionContext(), metadata, provider); String expected = String.Format(Validations.MinLength, context.ModelMetadata.PropertyName, 128); String actual = adapter.GetErrorMessage(context); Assert.Equal(Validations.MinLength, adapter.Attribute.ErrorMessage); Assert.Equal(expected, actual); }