Пример #1
0
        public void IsValidReturnsFalseWhenGivenObjectToValidateIsNull()
        {
            IValidationRule <string> rule = new CannotBeNullRule <string, string>(s => "Bob", string.Empty);

            bool isValid = rule.IsValid(null);

            Assert.IsFalse(isValid, "Null object returned true.");
        }
Пример #2
0
        public void GetErrorMessageReturnsStringWithTypeAndPropertyName()
        {
            const string expectedPropertyName = "String";
            string       expectedString       = string.Format("{0} must be provided.", expectedPropertyName);

            var rule = new CannotBeNullRule <string, string>(s => s, expectedPropertyName);

            Assert.AreEqual(expectedString, rule.GetErrorMessage(string.Empty));
        }
Пример #3
0
        public void IsValidReturnsWhetherOrNotTheGivenPropertyIsNull()
        {
            IValidationRule <string> rule = new CannotBeNullRule <string, string>(s => s, string.Empty);

            bool isValid     = rule.IsValid(string.Empty);
            bool isNullValid = rule.IsValid(null);

            Assert.IsTrue(isValid);
            Assert.IsFalse(isNullValid);
        }