public void GetClientValidationRules_ReturnsGreaterValidationRule()
        {
            ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "GreaterThan");
            GreaterThanAdapter adapter = new GreaterThanAdapter(metadata, new ControllerContext(), new GreaterThanAttribute(128));

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

            Assert.Equal(128M, actual.ValidationParameters["min"]);
            Assert.Equal(expectedMessage, actual.ErrorMessage);
            Assert.Equal("greater", actual.ValidationType);
            Assert.Single(actual.ValidationParameters);
        }
예제 #2
0
        public void GetClientValidationRules_ReturnsGreaterValidationRule()
        {
            ModelMetadata      metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "GreaterThan");
            GreaterThanAdapter adapter  = new GreaterThanAdapter(metadata, new ControllerContext(), new GreaterThanAttribute(128));

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

            Assert.Equal(128M, actual.ValidationParameters["min"]);
            Assert.Equal(expectedMessage, actual.ErrorMessage);
            Assert.Equal("greater", actual.ValidationType);
            Assert.Single(actual.ValidationParameters);
        }
        public void GetClientValidationRules_ReturnsGreaterValidationRule()
        {
            IServiceProvider       services = Substitute.For <IServiceProvider>();
            IModelMetadataProvider provider = new EmptyModelMetadataProvider();
            GreaterThanAdapter     adapter  = new GreaterThanAdapter(new GreaterThanAttribute(128));
            ModelMetadata          metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "GreaterThan");

            ClientModelValidationContext context = new ClientModelValidationContext(metadata, provider, services);
            String expectedMessage           = new GreaterThanAttribute(128).FormatErrorMessage("GreaterThan");
            ModelClientValidationRule actual = adapter.GetClientValidationRules(context).Single();

            Assert.Equal(128M, actual.ValidationParameters["min"]);
            Assert.Equal(expectedMessage, actual.ErrorMessage);
            Assert.Equal("greater", actual.ValidationType);
            Assert.Single(actual.ValidationParameters);
        }
        public void GetClientValidationRules_ReturnsMinRangeValidationRule()
        {
            ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "MinValue");
            GreaterThanAdapter adapter = new GreaterThanAdapter(metadata, new ControllerContext(), new GreaterThanAttribute(128));
            String errorMessage = new GreaterThanAttribute(128).FormatErrorMessage(metadata.GetDisplayName());

            ModelClientValidationRule actual = adapter.GetClientValidationRules().Single();
            ModelClientValidationRule expected = new ModelClientValidationRule();
            expected.ValidationParameters.Add("min", 128M);
            expected.ErrorMessage = errorMessage;
            expected.ValidationType = "greater";

            Assert.Equal(expected.ValidationParameters["min"], actual.ValidationParameters["min"]);
            Assert.Equal(expected.ValidationParameters.Count, actual.ValidationParameters.Count);
            Assert.Equal(expected.ValidationType, actual.ValidationType);
            Assert.Equal(expected.ErrorMessage, actual.ErrorMessage);
        }
예제 #5
0
        public void GetClientValidationRules_ReturnsMinRangeValidationRule()
        {
            ModelMetadata      metadata     = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "MinValue");
            GreaterThanAdapter adapter      = new GreaterThanAdapter(metadata, new ControllerContext(), new GreaterThanAttribute(128));
            String             errorMessage = new GreaterThanAttribute(128).FormatErrorMessage(metadata.GetDisplayName());

            ModelClientValidationRule actual   = adapter.GetClientValidationRules().Single();
            ModelClientValidationRule expected = new ModelClientValidationRule();

            expected.ValidationParameters.Add("min", 128M);
            expected.ErrorMessage   = errorMessage;
            expected.ValidationType = "greater";

            Assert.Equal(expected.ValidationParameters["min"], actual.ValidationParameters["min"]);
            Assert.Equal(expected.ValidationParameters.Count, actual.ValidationParameters.Count);
            Assert.Equal(expected.ValidationType, actual.ValidationType);
            Assert.Equal(expected.ErrorMessage, actual.ErrorMessage);
        }