Пример #1
0
        public void ValidateUrl()
        {
            var classWithUrl      = new ClassWithUrl();
            var context           = new ValidationContext(classWithUrl);
            var validationResults = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(classWithUrl, context, validationResults, true);

            Assert.IsFalse(isValid);
        }
Пример #2
0
        public void ValidateUrlWhenNullTest()
        {
            var classWithUrl      = new ClassWithUrl();
            var context           = new ValidationContext(classWithUrl);
            var validationResults = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(classWithUrl, context, validationResults, true);

            Assert.IsFalse(isValid);
            Assert.AreEqual("'Url' can't be null.", validationResults.First().ErrorMessage);
        }
Пример #3
0
        public void ValidateUrlTest()
        {
            var classWithUrl = new ClassWithUrl()
            {
                Url = "http://google.com"
            };
            var context           = new ValidationContext(classWithUrl);
            var validationResults = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(classWithUrl, context, validationResults, true);

            Assert.IsTrue(isValid);
        }
Пример #4
0
        public void ValidateEmptyStringAsUrlTest()
        {
            var classWithUrl = new ClassWithUrl()
            {
                Url = ""
            };
            var context           = new ValidationContext(classWithUrl);
            var validationResults = new List <ValidationResult>();

            bool isValid = Validator.TryValidateObject(classWithUrl, context, validationResults, true);

            Assert.IsFalse(isValid);
            Assert.AreEqual("'' is not a valid URL.", validationResults.First().ErrorMessage);
        }