コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public override String GetErrorMessage(ModelValidationContextBase context)
        {
            Attribute.ErrorMessage = Validations.MinLength;

            return base.GetErrorMessage(context);
        }
コード例 #4
0
 private string GetErrorMessage(ModelValidationContextBase validationContext)
 {
     var adapter = _validationAttributeAdapterProvider.GetAttributeAdapter(Attribute, _stringLocalizer);
     return adapter?.GetErrorMessage(validationContext);
 }
コード例 #5
0
        public override String GetErrorMessage(ModelValidationContextBase context)
        {
            Attribute.ErrorMessage = Validations.Range;

            return GetErrorMessage(context.ModelMetadata);
        }