Ejemplo n.º 1
0
        public void RuleInBothAttributesAndValidationDefsAppliedToChildOfRootEntity()
        {
            var configuration = new FluentConfiguration();

            configuration.SetDefaultValidatorMode(ValidatorMode.OverrideAttributeWithExternal).Register(
                new[] { typeof(ChildEntityWithAttributeRulesDef) });
            var engine = new ValidatorEngine();

            engine.Configure(configuration);

            var child = new ChildEntityWithAttributeRules {
                NotNullProperty = null, IsWordMonkeyAllowedInName = false, Name = "the monkey, monkey, monkey, monkety monk"
            };
            var parent = new ParentEntityWithAttributeRules {
                Child = child
            };

            var invalidValues = engine.Validate(parent);

            Assert.That(invalidValues.SingleOrDefault(i => i.Message == ChildEntityWithAttributeRulesDef.Message), Is.Not.Null, "Rule in def not applied");
            Assert.That(invalidValues.SingleOrDefault(i => i.PropertyName == "NotNullProperty"), Is.Not.Null, "Rule on attribute not applied");
        }
Ejemplo n.º 2
0
        public void RuleInBothAttributesAndValidationDefsAppliedToChildOfRootEntity()
        {
            var configuration = new FluentConfiguration();
            configuration.SetDefaultValidatorMode(ValidatorMode.OverrideAttributeWithExternal).Register(
                new[] { typeof(ChildEntityWithAttributeRulesDef) });
            var engine = new ValidatorEngine();
            engine.Configure(configuration);

            var child = new ChildEntityWithAttributeRules { NotNullProperty = null, IsWordMonkeyAllowedInName = false, Name = "the monkey, monkey, monkey, monkety monk" };
            var parent = new ParentEntityWithAttributeRules { Child = child };

            var invalidValues = engine.Validate(parent);
            Assert.That(invalidValues.SingleOrDefault(i => i.Message == ChildEntityWithAttributeRulesDef.Message), Is.Not.Null, "Rule in def not applied");
            Assert.That(invalidValues.SingleOrDefault(i => i.PropertyName == "NotNullProperty"), Is.Not.Null, "Rule on attribute not applied");
        }