Example #1
0
        public static void MergeVeeValidateAttributes_adds_attribute()
        {
            // Arrange
            var attributes = new Dictionary <string, string>();

            // Act
            VueHtmlAttributeHelper.MergeVeeValidateAttribute(attributes, "email", "true");
            VueHtmlAttributeHelper.MergeVeeValidateAttribute(attributes, "required", "true");

            // Assert
            attributes.Keys.FirstOrDefault().ShouldBe("v-validate");
            attributes.Values.FirstOrDefault().ShouldBe("{email:true,required:true}");
        }
Example #2
0
        public static void MergeVeeValidateAttributes_throws_when_validation_rules_in_string_format()
        {
            // Arrange
            var attributes = new Dictionary <string, string>
            {
                { "v-validate", "'required|email'" }
            };

            // Act

            // Assert
            Should.Throw <Exception>(() =>
                                     VueHtmlAttributeHelper.MergeVeeValidateAttribute(attributes, "credit_card", "true"));
        }
Example #3
0
        public static void MergeVeeValidateAttributes_concatenates_existing_rules()
        {
            // Arrange
            var attributes = new Dictionary <string, string>
            {
                { "v-validate", "{required:true}" }
            };

            // Act
            VueHtmlAttributeHelper.MergeVeeValidateAttribute(attributes, "email", "true");

            // Assert
            attributes.Keys.FirstOrDefault().ShouldBe("v-validate");
            attributes.Values.FirstOrDefault().ShouldBe("{required:true,email:true}");
        }
Example #4
0
        public static void MergeVeeValidateAttributes_preserves_any_modifiers()
        {
            // Arrange
            var attributes = new Dictionary <string, string>
            {
                { "v-validate.continue", "" }
            };

            // Act
            VueHtmlAttributeHelper.MergeVeeValidateAttribute(attributes, "email", "true");
            VueHtmlAttributeHelper.MergeVeeValidateAttribute(attributes, "required", "true");

            // Assert
            attributes.Keys.FirstOrDefault().ShouldBe("v-validate.continue");
            attributes.Values.FirstOrDefault().ShouldBe("{email:true,required:true}");
        }
 public static ClientModelValidationContext AddValidationRule(this ClientModelValidationContext context, string ruleName, string value)
 {
     VueHtmlAttributeHelper.MergeVeeValidateAttribute(context.Attributes, ruleName, value.ToString());
     return(context);
 }