public void CanInitialezeValidatorEngine()
        {
            var fc = new FluentConfiguration();
            fc.SetDefaultValidatorMode(ValidatorMode.UseExternal)
                .Register<AddressValidationDef, Address>().Register<BooValidationDef, Boo>()
                .IntegrateWithNHibernate.AvoidingDDLConstraints().And.AvoidingListenersRegister();

            var ve = new ValidatorEngine();
            ve.Configure(fc);
            Assert.That(ve.GetValidator<Address>(), Is.Not.Null);
            Assert.That(ve.GetValidator<Boo>(), Is.Not.Null);
        }
        public void CanInitialezeValidatorEngine()
        {
            var fc = new FluentConfiguration();

            fc.SetDefaultValidatorMode(ValidatorMode.UseExternal)
            .Register <AddressValidationDef, Address>().Register <BooValidationDef, Boo>()
            .IntegrateWithNHibernate.AvoidingDDLConstraints().And.AvoidingListenersRegister();

            var ve = new ValidatorEngine();

            ve.Configure(fc);
            Assert.That(ve.GetValidator <Address>(), Is.Not.Null);
            Assert.That(ve.GetValidator <Boo>(), Is.Not.Null);
        }
        public void AddValidatorWithoutUseIt()
        {
            ValidatorEngine ve = new ValidatorEngine();

            ve.AddValidator <Boo>();
            Assert.IsNotNull(ve.GetValidator <Boo>());
        }
        public void InitializeValidators()
        {
            ValidatorEngine  ve   = new ValidatorEngine();
            XmlConfiguration nhvc = new XmlConfiguration();

            nhvc.Properties[Environment.ApplyToDDL]               = "false";
            nhvc.Properties[Environment.AutoregisterListeners]    = "false";
            nhvc.Properties[Environment.ValidatorMode]            = "overrideattributewithExternal";
            nhvc.Properties[Environment.MessageInterpolatorClass] = typeof(PrefixMessageInterpolator).AssemblyQualifiedName;
            string an = Assembly.GetExecutingAssembly().FullName;

            nhvc.Mappings.Add(new MappingConfiguration(an, "NHibernate.Validator.Tests.Base.Address.nhv.xml"));
            ve.Configure(nhvc);
            Assert.IsNotNull(ve.GetValidator <Address>());

            Assert.IsNull(ve.GetValidator <Boo>());
            // Validate something and then its validator is initialized
            Boo b = new Boo();

            ve.IsValid(b);
            Assert.IsNotNull(ve.GetValidator <Boo>());
        }
        public void ValidateAnyClass()
        {
            ValidatorEngine ve = new ValidatorEngine();

            Assert.IsTrue(ve.IsValid(new AnyClass()));
            Assert.IsNotNull(ve.GetValidator <AnyClass>());
            ve.AssertValid(new AnyClass());             // not cause exception
            Assert.AreEqual(0, ve.Validate(new AnyClass()).Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue <AnyClass>("aprop", new AnyClass()).Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue(new AnyClass(), "aprop").Length);

            Assert.AreEqual(0, ve.Validate("always valid").Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue("always valid", "Length").Length);
        }
        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));
        }
Beispiel #7
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));
        }
 public void AddValidatorWithoutUseIt()
 {
     ValidatorEngine ve = new ValidatorEngine();
     ve.AddValidator<Boo>();
     Assert.IsNotNull(ve.GetValidator<Boo>());
 }
        public void ValidateAnyClass()
        {
            ValidatorEngine ve = new ValidatorEngine();
            Assert.IsTrue(ve.IsValid(new AnyClass()));
            Assert.IsNotNull(ve.GetValidator<AnyClass>());
            ve.AssertValid(new AnyClass()); // not cause exception
            Assert.AreEqual(0, ve.Validate(new AnyClass()).Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue<AnyClass>("aprop", new AnyClass()).Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue(new AnyClass(), "aprop").Length);

            Assert.AreEqual(0, ve.Validate("always valid").Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue("always valid", "Length").Length);
        }
        public void InitializeValidators()
        {
            ValidatorEngine ve = new ValidatorEngine();
            XmlConfiguration nhvc = new XmlConfiguration();
            nhvc.Properties[Environment.ApplyToDDL] = "false";
            nhvc.Properties[Environment.AutoregisterListeners] = "false";
            nhvc.Properties[Environment.ValidatorMode] = "overrideattributewithExternal";
            nhvc.Properties[Environment.MessageInterpolatorClass] = typeof(PrefixMessageInterpolator).AssemblyQualifiedName;
            string an = Assembly.GetExecutingAssembly().FullName;
            nhvc.Mappings.Add(new MappingConfiguration(an, "NHibernate.Validator.Tests.Base.Address.nhv.xml"));
            ve.Configure(nhvc);
            Assert.IsNotNull(ve.GetValidator<Address>());

            Assert.IsNull(ve.GetValidator<Boo>());
            // Validate something and then its validator is initialized
            Boo b = new Boo();
            ve.IsValid(b);
            Assert.IsNotNull(ve.GetValidator<Boo>());
        }