public void IsValidReturnsFalseForNullString() { IValidationRule <string> rule = new StringCannotBeNullOrEmptyRule <string>(s => null, "Property"); bool isValid = rule.IsValid("1"); Assert.IsFalse(isValid, "IsValid returned true for null string."); }
public void IsValidReturnsTrueForStringOfLengthOne() { IValidationRule <string> rule = new StringCannotBeNullOrEmptyRule <string>(s => s, "Property"); bool isValid = rule.IsValid("1"); Assert.IsTrue(isValid, "IsValid returned false for string of length 1."); }
public void GetErrorMessageReturnsMessageWhenGivenNonNullObject() { IValidationRule <string> rule = new StringCannotBeNullOrEmptyRule <string>(s => s, "Property"); string errorMessage = rule.GetErrorMessage(string.Empty); Assert.IsNotNull(errorMessage); Assert.IsNotEmpty(errorMessage); }
public void IsValidReturnsFalseWhenGivenNullObject() { IValidationRule <FakeObjectToValidate> rule = new StringCannotBeNullOrEmptyRule <FakeObjectToValidate>(f => f.ToString(), "Property"); bool isValid = rule.IsValid(null); Assert.IsFalse(isValid, "IsValid returned true for null object."); }
public void IsValidReturnsTrueForStringOfLengthGreaterThanOne() { string stringToCheck = "1"; IValidationRule <string> rule = new StringCannotBeNullOrEmptyRule <string>(s => s, "Property"); for (int i = 2; i < 10; i++) { stringToCheck += i; Assert.IsTrue(rule.IsValid(stringToCheck), "IsValid returned false for string of length {0}.", i); } }