Exemplo n.º 1
0
        public void ValidateMultipleFieldsRule()
        {
            const string    errorMsg  = "The passwords must match";
            IFieldValidator validator = new FieldRulesValidator(new List <FieldValidationRule>
            {
                new FieldValidationRule {
                    Rule = "${value} == ${field:password1}", ErrorMessage = errorMsg
                }
            });

            var password1 = new SBSPasswordEditField {
                Name = "password1", Value = "123"
            };
            var password2 = new SBSPasswordEditField {
                Name = "password2", Value = "123"
            };
            SBSForm form = new SBSForm("Test Password Form", new List <ISBSFormField> {
                password1, password2
            });

            bool rc = validator.Validate(password2, form);

            Assert.IsTrue(rc, "The passwords should match");

            password2.Value = "456";
            rc = validator.Validate(password2, form);
            Assert.IsFalse(rc, "The passwords should not match");
            Assert.AreEqual(errorMsg, validator.ValidationFailedMessage);
        }
Exemplo n.º 2
0
        public void ValidateSingleFieldRule()
        {
            const string    errorMsg  = "The value must be no more than 50";
            IFieldValidator validator = new FieldRulesValidator(new List <FieldValidationRule>
            {
                new FieldValidationRule {
                    Rule = "${value} <= 50", ErrorMessage = errorMsg
                }
            });

            bool rc = validator.Validate(new SBSIntegerEditField {
                Value = 30
            });

            Assert.IsTrue(rc, "30 is less than 50");

            rc = validator.Validate(new SBSIntegerEditField {
                Value = 60
            });
            Assert.IsFalse(rc, "60 is not less than 50");
            Assert.AreEqual(errorMsg, validator.ValidationFailedMessage);
        }