public void IsValidReturnsFalseForStringWhoseLengthDoesNotEqualMinAndMax() { const string stringLessThanMin = "1234"; const string stringMoreThanMax = "123456"; const int length = 5; IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", length, length); bool isMinStringValid = rule.IsValid(stringLessThanMin); bool isMaxStringValid = rule.IsValid(stringMoreThanMax); Assert.IsFalse(isMinStringValid, "'{0}' returned true even though it was less than min/max length {1}.", stringLessThanMin, length); Assert.IsFalse(isMaxStringValid, "'{0}' returned true even though it was more than min/max length {1}.", stringMoreThanMax, length); }
public void IsValidReturnsFalseWhenGivenNullObjectToValidate() { IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", 0); bool isValid = rule.IsValid(null); Assert.IsFalse(isValid, "Null object evaluated to true when validated."); }
public void IsValidReturnsFalseForEmptyStringWhenMinimumLengthIs1() { const int minimumLength = 1; IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", minimumLength); bool isValid = rule.IsValid(string.Empty); Assert.IsFalse(isValid, "Empty string evaluated to true when minimum length was 1."); }
public void IsValidReturnsTrueForStringWhoseLengthEqualsMinAndMax() { const string stringToValidate = "12345"; const int length = 5; IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", length, length); bool isValid = rule.IsValid(stringToValidate); Assert.IsTrue(isValid, "'{0}' returned false even though it matched min/max length {1}.", stringToValidate, length); }
public void IsValidReturnsTrueForStringWhoseLengthMatchesMaximumLength() { const string stringToValidate = "1"; const int maximumLength = 1; IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", 0, maximumLength); bool isValid = rule.IsValid(stringToValidate); Assert.IsTrue(isValid, "'{0}' returned false even though it matched maximum length {1}.", stringToValidate, maximumLength); }
public void IsValidReturnsFalseWhenPropertyToCheckOfGivenObjectIsNull() { var medicalVendorInvoice = new FakeMedicalVendorInvoiceBase { MedicalVendorName = null }; IValidationRule <FakeMedicalVendorInvoiceBase> rule = new StringLengthMustBeInRangeRule <FakeMedicalVendorInvoiceBase>(s => s.MedicalVendorName, "MedicalVendorName", 0); bool isValid = rule.IsValid(medicalVendorInvoice); Assert.IsFalse(isValid, "Null object evaluated to true when validated."); }
public void IsValidReturnsFalseForStringWhoseLengthIsOneGreaterThanMaximumLength() { const string stringToValidate = "12"; const int maximumLength = 1; IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", 0, maximumLength); bool isValid = rule.IsValid(stringToValidate); Assert.IsFalse(isValid, "'{0}' returned true even though it exceeded maximum length {1}.", stringToValidate, maximumLength); }
public void IsValidReturnsTrueForStringWhoseLengthIsOneLessThanMax() { const string stringToValidate = "12"; const int maximumLength = 3; IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", 0, maximumLength); bool isValid = rule.IsValid(stringToValidate); Assert.IsTrue(isValid, "'{0}' returned false even though it was one less than maximum length {1}.", stringToValidate, maximumLength); }
public void IsValidReturnsTrueForStringWhoseLengthExceedsMinimumLength() { string stringToValidate = "123"; const int minimumLength = 3; IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", minimumLength); for (int i = 4; i < 10; i++) { stringToValidate += i; bool isValid = rule.IsValid(stringToValidate); Assert.IsTrue(isValid, "'{0}' returned false even though it matched minimum length {1}.", stringToValidate, minimumLength); } }