Beispiel #1
0
        public void CanGetValidatorFromConfigurationOly()
        {
            var validator =
                ValidationFactory.CreateValidator <TestObjectWithMultipleSourceValidationAttributesOnProperties>(
                    ValidationSpecificationSource.Configuration);

            var instance =
                new TestObjectWithMultipleSourceValidationAttributesOnProperties
            {
                PropertyWithDataAnnotationsAttributes = "invalid",
                PropertyWithMixedAttributes           = "invalid",
                PropertyWithVABOnlyAttributes         = "invalid"
            };

            var results = validator.Validate(instance);

            Assert.IsFalse(results.IsValid);
            Assert.AreEqual(2, results.Count);
            Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithDataAnnotationsAttributes" && vr.Message == "configuration1"));
            Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithVABOnlyAttributes" && vr.Message == "configuration2"));
        }
Beispiel #2
0
        public void CanGetValidatorFromDataAnnotationsAndVABAttributes()
        {
            var validator =
                ValidationFactory.CreateValidator <TestObjectWithMultipleSourceValidationAttributesOnProperties>(
                    ValidationSpecificationSource.Attributes | ValidationSpecificationSource.DataAnnotations);

            var instance =
                new TestObjectWithMultipleSourceValidationAttributesOnProperties
            {
                PropertyWithDataAnnotationsAttributes = "invalid",
                PropertyWithMixedAttributes           = "invalid",
                PropertyWithVABOnlyAttributes         = "invalid"
            };

            var results = validator.Validate(instance);

            Assert.IsFalse(results.IsValid);
            Assert.AreEqual(4, results.Count);
            Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithMixedAttributes" && vr.Message == "vab-mixed"));
            Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithMixedAttributes" && vr.Message == "data annotations-mixed"));
            Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithVABOnlyAttributes" && vr.Message == "vab-only"));
            Assert.IsTrue(results.Any(vr => vr.Key == "PropertyWithDataAnnotationsAttributes" && vr.Message == "data annotations-only"));
        }