Beispiel #1
0
        public void GetErrorMessageReturnsStringWhenGivenNullObject()
        {
            IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name", 0, 0);

            string errorMessage = rule.GetErrorMessage(null);

            Assert.IsNotNull(errorMessage);
            Assert.IsNotEmpty(errorMessage);
        }
Beispiel #2
0
        public void GetErrorMessageReturnsMessageContainingMaximumStringLength()
        {
            const int expectedMaximumLength = 4;
            IValidationRule <string> rule   = new StringLengthMustBeInRangeRule <string>(s => s, "Name",
                                                                                         0, expectedMaximumLength);

            string errorMessage = rule.GetErrorMessage(string.Empty);

            Assert.IsTrue(errorMessage.Contains(expectedMaximumLength.ToString()),
                          "Message did not contain maximum string length.");
        }
Beispiel #3
0
        public void GetErrorMessageReturnsMessageContainingErrornousStringLength()
        {
            const string             stringToValidate = "123";
            int                      expectedLength   = stringToValidate.Length;
            IValidationRule <string> rule             = new StringLengthMustBeInRangeRule <string>(s => s, "Name", 0, 0);

            string errorMessage = rule.GetErrorMessage(stringToValidate);

            Assert.IsTrue(errorMessage.Contains(expectedLength.ToString()),
                          "Message did not contain string's length.");
        }
Beispiel #4
0
        public void GetErrorMessageReturnsStringWhenGivenObjectWithNullProperty()
        {
            var medicalVendorInvoice = new FakeMedicalVendorInvoiceBase {
                MedicalVendorName = null
            };
            IValidationRule <FakeMedicalVendorInvoiceBase> rule = new StringLengthMustBeInRangeRule
                                                                  <FakeMedicalVendorInvoiceBase>(s => s.MedicalVendorName, "MedicalVendorName", 0, 0);

            string errorMessage = rule.GetErrorMessage(medicalVendorInvoice);

            Assert.IsNotNull(errorMessage);
            Assert.IsNotEmpty(errorMessage);
        }
Beispiel #5
0
        public void GetErrorMessageReturnsMessageContainingStringLengthMinLengthAndMaxLengthWhenAllGiven()
        {
            const string             stringToValidate      = "123";
            int                      expectedLength        = stringToValidate.Length;
            const int                expectedMinimumLength = 64156;
            const int                expectedMaximumLength = 99591;
            IValidationRule <string> rule = new StringLengthMustBeInRangeRule <string>(s => s, "Name",
                                                                                       expectedMinimumLength, expectedMaximumLength);

            string errorMessage = rule.GetErrorMessage(stringToValidate);

            Assert.IsTrue(errorMessage.Contains(expectedMinimumLength.ToString()),
                          "Message did not contain minimum string length.");
            Assert.IsTrue(errorMessage.Contains(expectedMaximumLength.ToString()),
                          "Message did not contain maximum string length.");
            Assert.IsTrue(errorMessage.Contains(expectedLength.ToString()),
                          "Message did not contain string's length.");
        }