public MaxValueAdapterTests() { attributes = new Dictionary<String, String>(); adapter = new MaxValueAdapter(new MaxValueAttribute(128)); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "MaxValue"); context = new ClientModelValidationContext(new ActionContext(), metadata, provider, attributes); }
public MaxValueAdapterTests() { attributes = new Dictionary <String, String>(); adapter = new MaxValueAdapter(new MaxValueAttribute(128)); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AllTypesView), nameof(AllTypesView.Int32Field)); context = new ClientModelValidationContext(new ActionContext(), metadata, provider, attributes); }
public void GetClientValidationRules_ReturnsMaxRangeValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "MaxValue"); MaxValueAdapter adapter = new MaxValueAdapter(metadata, new ControllerContext(), new MaxValueAttribute(128)); String expectedMessage = new MaxValueAttribute(128).FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal(128M, actual.ValidationParameters["max"]); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("range", actual.ValidationType); Assert.Single(actual.ValidationParameters); }
public void GetClientValidationRules_ReturnsMaxRangeValidationRule() { IServiceProvider services = Substitute.For <IServiceProvider>(); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); MaxValueAdapter adapter = new MaxValueAdapter(new MaxValueAttribute(128)); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "MaxValue"); ClientModelValidationContext context = new ClientModelValidationContext(metadata, provider, services); ModelClientValidationRule actual = adapter.GetClientValidationRules(context).Single(); String expectedMessage = new MaxValueAttribute(128).FormatErrorMessage("MaxValue"); Assert.Equal(128M, actual.ValidationParameters["max"]); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("range", actual.ValidationType); Assert.Single(actual.ValidationParameters); }