public void CanCreateValidatorForValidatorAndValidationAttributes()
        {
            var validator =
                PropertyValidationFactory.GetPropertyValidator(
                    typeof(TestObjectWithMultipleSourceValidationAttributesOnProperties),
                    StaticReflection.GetPropertyInfo((TestObjectWithMultipleSourceValidationAttributesOnProperties t)
                                                     => t.PropertyWithMixedAttributes),
                    "",
                    ValidationSpecificationSource.DataAnnotations | ValidationSpecificationSource.Attributes,
                    new MemberAccessValidatorBuilderFactory());

            var invalidResults =
                validator.Validate(
                    new TestObjectWithMultipleSourceValidationAttributesOnProperties
            {
                PropertyWithMixedAttributes = "invalid"
            });

            Assert.IsFalse(invalidResults.IsValid);
            Assert.AreEqual(2, invalidResults.Count);
            Assert.IsTrue(
                invalidResults.Any(vr =>
                                   vr.Key == "PropertyWithMixedAttributes" && vr.Message == "data annotations-mixed"));
            Assert.IsTrue(
                invalidResults.Any(vr =>
                                   vr.Key == "PropertyWithMixedAttributes" && vr.Message == "vab-mixed"));
        }
Ejemplo n.º 2
0
 public void Setup()
 {
     this.validatedElement =
         new ValidationAttributeValidatedElement(
             StaticReflection.GetPropertyInfo((TypeWithValidationAttributes t)
                                              => t.PropertyWithSingleValidationAttribute));
 }
Ejemplo n.º 3
0
        public void ThenValidatedPropertiesContainTheExpectedDescriptors()
        {
            var validatedProperties = this.validatedType.GetValidatedProperties();

            Assert.AreEqual(
                0,
                validatedProperties
                .Where(vp => vp.MemberInfo ==
                       StaticReflection.GetPropertyInfo(
                           (TypeWithValidationAttributes t) => t.PropertyWithNoValidationAttributes))
                .First()
                .GetValidatorDescriptors()
                .Count());

            Assert.AreEqual(
                1,
                validatedProperties
                .Where(vp => vp.MemberInfo ==
                       StaticReflection.GetPropertyInfo(
                           (TypeWithValidationAttributes t) => t.PropertyWithSingleValidationAttribute))
                .First()
                .GetValidatorDescriptors()
                .Count());
        }
Ejemplo n.º 4
0
 public void ThenReturnsConfiguredMember()
 {
     Assert.AreSame(
         StaticReflection.GetPropertyInfo((TypeWithValidationAttributes t) => t.PropertyWithSingleValidationAttribute),
         this.validatedElement.MemberInfo);
 }