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);
        }
        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);
        }
        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);
        }
        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);
        }