public DigitsAdapterTests()
 {
     attributes = new Dictionary<String, String>();
     adapter = new DigitsAdapter(new DigitsAttribute());
     IModelMetadataProvider provider = new EmptyModelMetadataProvider();
     ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "Digits");
     context = new ClientModelValidationContext(new ActionContext(), metadata, provider, attributes);
 }
Esempio n. 2
0
        public DigitsAdapterTests()
        {
            attributes = new Dictionary <String, String>();
            adapter    = new DigitsAdapter(new DigitsAttribute());
            IModelMetadataProvider provider = new EmptyModelMetadataProvider();
            ModelMetadata          metadata = provider.GetMetadataForProperty(typeof(AllTypesView), nameof(AllTypesView.StringField));

            context = new ClientModelValidationContext(new ActionContext(), metadata, provider, attributes);
        }
        public void GetClientValidationRules_ReturnsDigitsValidationRule()
        {
            ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "Digits");
            DigitsAdapter adapter  = new DigitsAdapter(metadata, new ControllerContext(), new DigitsAttribute());

            String expectedMessage           = new DigitsAttribute().FormatErrorMessage(metadata.GetDisplayName());
            ModelClientValidationRule actual = adapter.GetClientValidationRules().Single();

            Assert.Equal(expectedMessage, actual.ErrorMessage);
            Assert.Equal("digits", actual.ValidationType);
            Assert.Empty(actual.ValidationParameters);
        }
        public void GetClientValidationRules_ReturnsDigitsValidationRule()
        {
            ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "Digits");
            DigitsAdapter adapter = new DigitsAdapter(metadata, new ControllerContext(), new DigitsAttribute());

            String expectedMessage = new DigitsAttribute().FormatErrorMessage(metadata.GetDisplayName());
            ModelClientValidationRule actual = adapter.GetClientValidationRules().Single();

            Assert.Equal(expectedMessage, actual.ErrorMessage);
            Assert.Equal("digits", actual.ValidationType);
            Assert.Empty(actual.ValidationParameters);
        }
        public void GetClientValidationRules_ReturnsDigitsValidationRule()
        {
            IServiceProvider       services = Substitute.For <IServiceProvider>();
            IModelMetadataProvider provider = new EmptyModelMetadataProvider();
            ModelMetadata          metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "Digits");

            ClientModelValidationContext context = new ClientModelValidationContext(metadata, provider, services);

            ModelClientValidationRule actual = new DigitsAdapter(new DigitsAttribute()).GetClientValidationRules(context).Single();
            String expectedMessage           = new DigitsAttribute().FormatErrorMessage(metadata.GetDisplayName());

            Assert.Equal(expectedMessage, actual.ErrorMessage);
            Assert.Equal("digits", actual.ValidationType);
            Assert.Empty(actual.ValidationParameters);
        }