Exemplo n.º 1
0
        private void GivingRulesFor(string propertyName, out ITagableRule minAttribute, out ITagableRule maxAttribute)
        {
            IClassValidator         cv = ve.GetClassValidator(typeof(EntityXml));
            IEnumerable <Attribute> ma = cv.GetMemberConstraints(propertyName);

            minAttribute = (ITagableRule)ma.First(a => a.TypeId == minTypeId);
            maxAttribute = (ITagableRule)ma.First(a => a.TypeId == maxTypeId);
        }
Exemplo n.º 2
0
        public void GetMemberConstraints()
        {
            IClassValidator         cv = GetClassValidator(typeof(Address));
            IEnumerable <Attribute> ma = cv.GetMemberConstraints("country");

            Assert.That(ma.Count(), Is.EqualTo(2));
            Assert.That(ma.Count(x => x.TypeId == (new NotNullAttribute()).TypeId), Is.EqualTo(1));
            Assert.That(ma.Count(x => x.TypeId == (new LengthAttribute()).TypeId), Is.EqualTo(1));
        }
Exemplo n.º 3
0
        public void GetMemberConstraintsLoquacious()
        {
            var configure = new FluentConfiguration();

            configure.Register(
                Assembly.GetExecutingAssembly().ValidationDefinitions().Where(x => x.Equals(typeof(AddressDef))))
            .SetDefaultValidatorMode(ValidatorMode.UseExternal);
            var ve = new ValidatorEngine();

            ve.Configure(configure);

            IClassValidator         cv = ve.GetValidator <Address>();
            IEnumerable <Attribute> ma = cv.GetMemberConstraints("Country");

            Assert.That(ma.Count(), Is.EqualTo(2));
            Assert.That(ma.Count(x => x.TypeId == (new NotNullAttribute()).TypeId), Is.EqualTo(1));
            Assert.That(ma.Count(x => x.TypeId == (new LengthAttribute()).TypeId), Is.EqualTo(1));
        }