Exemplo n.º 1
0
        public void CanPerformValidationWithSuppliedValidationResults()
        {
            MockValidator <string> subValidator1 = new MockValidator <string>(true, "validator1");
            MockValidator <string> subValidator2 = new MockValidator <string>(true, "validator2");
            MockValidator <string> subValidator3 = new MockValidator <string>(true, "validator3");
            Validator validator = new OrCompositeValidator(subValidator1, subValidator2, subValidator3);

            validator.Tag = "tag";
            string            target            = new string('a', 10); // just any string, but a new one
            ValidationResults validationResults = new ValidationResults();

            validator.Validate(target, validationResults);

            Assert.IsFalse(validationResults.IsValid);
            IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);

            Assert.AreEqual(1, resultsList.Count);
            Assert.IsTrue(TemplateStringTester.IsMatch(Resources.OrCompositeValidatorDefaultMessageTemplate, resultsList[0].Message));
            Assert.AreEqual("tag", resultsList[0].Tag);
            IList <ValidationResult> nestedResultsList = ValidationTestHelper.GetResultsList(resultsList[0].NestedValidationResults);

            Assert.AreEqual(3, nestedResultsList.Count);
            Assert.AreEqual("validator1", nestedResultsList[0].Message);
            Assert.AreEqual("validator2", nestedResultsList[1].Message);
            Assert.AreEqual("validator3", nestedResultsList[2].Message);
            Assert.AreSame(target, subValidator1.ValidatedTargets[0]);
            Assert.AreSame(target, subValidator2.ValidatedTargets[0]);
            Assert.AreSame(target, subValidator3.ValidatedTargets[0]);
        }
Exemplo n.º 2
0
        public void ReturnsFailureForStringLongerThanMaxLengthForMaxLengthOnlyValidator()
        {
            Validator <string> validator = new StringLengthValidator(10);

            ValidationResults validationResults = validator.Validate(new StringBuilder().Append('a', 11).ToString());

            Assert.IsFalse(validationResults.IsValid);
            IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);

            Assert.AreEqual(1, resultsList.Count);
            Assert.IsTrue(TemplateStringTester.IsMatch(Resources.StringLengthValidatorNonNegatedDefaultMessageTemplate, resultsList[0].Message));
        }
Exemplo n.º 3
0
        public void ReturnsFailureForValueOutsideRange()
        {
            Validator <string> validator = new RangeValidator <string>("aaaa", RangeBoundaryType.Exclusive, "zzzz", RangeBoundaryType.Inclusive);

            ValidationResults validationResults = validator.Validate("0000");

            Assert.IsFalse(validationResults.IsValid);
            IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);

            Assert.AreEqual(1, resultsList.Count);
            Assert.IsTrue(TemplateStringTester.IsMatch(Resources.RangeValidatorNonNegatedDefaultMessageTemplate, resultsList[0].Message));
        }
        public void NegatedReturnFailureForNullString()
        {
            Validator <string> validator = new RegexValidator(RegexPattern, true);

            ValidationResults validationResults = validator.Validate(null);

            Assert.IsFalse(validationResults.IsValid);
            IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);

            Assert.AreEqual(1, resultsList.Count);
            Assert.IsTrue(TemplateStringTester.IsMatch(Resources.RegexValidatorNegatedDefaultMessageTemplate, resultsList[0].Message));
        }
        public void ReturnFailureForNonMatchingStringUsingResourceRegex()
        {
            Validator <string> validator = new RegexValidator(RegexResourceName1, typeof(Properties.Resources));

            ValidationResults validationResults = validator.Validate("asdfg");

            Assert.IsFalse(validationResults.IsValid);
            IList <ValidationResult> resultsList = ValidationTestHelper.GetResultsList(validationResults);

            Assert.AreEqual(1, resultsList.Count);
            Assert.IsTrue(TemplateStringTester.IsMatch(Resources.RegexValidatorNonNegatedDefaultMessageTemplate, resultsList[0].Message));
        }
Exemplo n.º 6
0
        public void ValueRequestForNonMappedPropertyReturnsFailure()
        {
            Page page = TestContext.RequestedPage;
            PropertyProxyValidator validator = (PropertyProxyValidator)page.FindControl("NameValidator1");

            ValueAccess valueAccess = new PropertyMappedValidatorValueAccess("InvalidProperty");
            object      value;
            string      valueAccessFailureMessage;

            bool accessStatus = valueAccess.GetValue(validator, out value, out valueAccessFailureMessage);

            Assert.IsFalse(accessStatus);
            Assert.IsTrue(TemplateStringTester.IsMatch(Resources.ErrorNonMappedProperty, valueAccessFailureMessage));
        }
Exemplo n.º 7
0
        public void GetValueConvertedWithDefaultConversionReturnsFailureIfConversionIsNotPossible()
        {
            object value = "00012345abc";
            MockIntegrationProxy integrationProxy = new MockIntegrationProxy(value,
                                                                             "",
                                                                             ValidationSpecificationSource.Attributes,
                                                                             "IntProperty",
                                                                             typeof(MockValidatedType));
            ValidationIntegrationHelper integrationHelper = new ValidationIntegrationHelper(integrationProxy);

            object retrievedValue;
            string valueRetrievalFailureMessage;

            bool status = integrationHelper.GetValue(out retrievedValue, out valueRetrievalFailureMessage);

            Assert.IsFalse(status);
            Assert.AreEqual(null, retrievedValue);
            Assert.IsTrue(TemplateStringTester.IsMatch(Resources.ErrorCannotPerfomDefaultConversion, valueRetrievalFailureMessage));
            Assert.AreEqual(null, originalConvertedValue);
            Assert.AreEqual(null, valueToConvert);
        }