Exemple #1
0
        public void RubberStamp_Validator_InheritedValidator_Extended_Rule_WithWhen_Valid_Test()
        {
            var validator = new PersonValidator();

            validator.AddRule(p => p.City, con => con.IsEqual("Mexico City"), r => r.When(p => p.Firstname != "Ted"));
            var summary = validator.Validate(new Person("Taylor", "Ted", "New York"));

            Assert.IsTrue(summary.IsValid);
        }
Exemple #2
0
        public void RubberStamp_Validator_InheritedValidator_Extended_Rule_CustomMessage_Invalid_Test()
        {
            var validator = new PersonValidator();

            validator.AddRule(p => p.City, con => con.IsEqual("Mexico City"), r => r.SetMessage("The City has to be Mexico City"));
            var summary = validator.Validate(new Person("Taylor", "Ted", "New York"));

            Assert.IsFalse(summary.IsValid);
            Assert.AreEqual("The City has to be Mexico City", summary.ValidationResults.First().Message);
        }
Exemple #3
0
        public void RubberStamp_Validator_InheritedValidator_Extended_Rule_Invalid_Test()
        {
            var validator = new PersonValidator();

            validator.AddRule(p => p.City, con => con.IsEqual("Mexico City"));

            var summary = validator.Validate(new Person("Taylor", "Ted", "New York"));

            Assert.IsFalse(summary.IsValid);

            var expected = new StringBuilder();

            expected.Append("The Property City has to be equal to Mexico City");

            Assert.AreEqual(expected.ToString(), summary.ValidationMessage);
        }