コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void AddValidatorWithoutUseIt()
        {
            ValidatorEngine ve = new ValidatorEngine();

            ve.AddValidator <Boo>();
            Assert.IsNotNull(ve.GetValidator <Boo>());
        }
コード例 #4
0
        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>());
        }
コード例 #5
0
        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);
        }
コード例 #6
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));
        }
コード例 #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));
        }
コード例 #8
0
 public void AddValidatorWithoutUseIt()
 {
     ValidatorEngine ve = new ValidatorEngine();
     ve.AddValidator<Boo>();
     Assert.IsNotNull(ve.GetValidator<Boo>());
 }
コード例 #9
0
        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);
        }
コード例 #10
0
        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>());
        }