Example #1
0
        public void Test_Validate_Should_Regex_Error()
        {
            var myClass = new MyClass()
            {
                Email = "notEmail"
            };

            var validator = new Validator();
            var validationErrors = validator.Validate(myClass);

            Assert.IsNotNull(validationErrors.Errors.FirstOrDefault(d => d.Key == "Email"));
        }
Example #2
0
        public void Test_Validate_Should_Return_Errors()
        {
            var myClass =
                new MyClass
                {
                    Id = -1, // Invalid
                    Text = "Some text", // Valid
                    MyValue = // Valid
                        new MyValueClass
                        {
                            Value = null // Invalid
                        }
                };

            var validator = new Validator();
            var validationErrors = validator.Validate(myClass);

            Assert.AreSame(myClass, validationErrors.Object);
            Assert.AreEqual(2, validationErrors.Errors.Length);

            Assert.AreEqual("Id", validationErrors.Errors[0].Key);
            Assert.AreEqual("Id must be greater than 0.", validationErrors.Errors[0].Message);

            Assert.AreEqual("Value", validationErrors.Errors[1].Key);
            Assert.AreEqual("Value must be specified.", validationErrors.Errors[1].Message);
        }