public RangeAdapterTests() { attributes = new Dictionary <String, String>(); CultureInfo.CurrentCulture = new CultureInfo("lt"); adapter = new RangeAdapter(new RangeAttribute(4.3, 128.4)); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AllTypesView), nameof(AllTypesView.DoubleField)); context = new ClientModelValidationContext(new ActionContext(), metadata, provider, attributes); }
public void GetErrorMessage_Range() { IModelMetadataProvider provider = new EmptyModelMetadataProvider(); RangeAdapter adapter = new RangeAdapter(new RangeAttribute(4, 128)); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AllTypesView), "Int32Field"); ModelValidationContextBase context = new ModelValidationContextBase(new ActionContext(), metadata, provider); String expected = Validation.For("Range", context.ModelMetadata.PropertyName, 4, 128); String actual = adapter.GetErrorMessage(context); Assert.Equal(Validation.For("Range"), adapter.Attribute.ErrorMessage); Assert.Equal(expected, actual); }
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); }