示例#1
0
        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);
        }
示例#2
0
        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.");
        }
示例#3
0
        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.");
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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.");
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
            }
        }