Exemple #1
0
        ///<remarks>
        /// The output of this function should be either put into your IoC container or cached somewhere to prevent
        /// re-reading of the config files.
        ///</remarks>
        public static ValidatorEngine CreateValidationEngine()
        {
            var validator = new ValidatorEngine();
            validator.Configure();

            return validator;
        }
        public void Configure(IWindsorContainer container)
        {
            var ve = new ValidatorEngine();

            container.Register(Component.For<IEntityValidator>()
                                   .ImplementedBy<EntityValidator>());

            container.Register(Component.For<ValidatorEngine>()
                                   .Instance(ve)
                                   .LifeStyle.Singleton);

            //Register the service for ISharedEngineProvider
            container.Register(Component.For<ISharedEngineProvider>()
                                   .ImplementedBy<NHVSharedEngineProvider>());

            //Assign the shared engine provider for NHV.
            Environment.SharedEngineProvider =
                container.Resolve<ISharedEngineProvider>();

            //Configure validation framework fluently
            var configure = new FluentConfiguration();

            configure.Register(typeof (WorkerValidationDefenition).Assembly.ValidationDefinitions())
                .SetDefaultValidatorMode(ValidatorMode.OverrideAttributeWithExternal)
                .AddEntityTypeInspector<NHVTypeInspector>()
                .IntegrateWithNHibernate.ApplyingDDLConstraints().And.RegisteringListeners();

            ve.Configure(configure);
        }
Exemple #3
0
 private static ValidatorEngine GetValidatorEngine()
 {
     var cfg = GetNhvConfiguration();
       var validatorEngine = new ValidatorEngine();
       validatorEngine.Configure(cfg);
       return validatorEngine;
 }
        public void ValidateWithMultipleConditions()
        {
            var configure = new FluentConfiguration();

            var validationDef = new ValidationDef<EntityWithString>();
            validationDef.Define(e => e.Name)
                .Satisfy(name => name != null && name.StartsWith("ab")).WithMessage("Name should start with 'ab'")
                .And
                .Satisfy(name => name != null && name.EndsWith("zz")).WithMessage("Name should end with 'zz'");

            configure.Register(validationDef).SetDefaultValidatorMode(ValidatorMode.UseExternal);
            var ve = new ValidatorEngine();

            ve.Configure(configure);

            Assert.That(ve.IsValid(new EntityWithString { Name = "abczz" }));
            Assert.That(!ve.IsValid(new EntityWithString { Name = "bc" }));
            var iv = ve.Validate(new EntityWithString {Name = "abc"});
            Assert.That(iv.Length, Is.EqualTo(1));
            Assert.That(iv.Select(i => i.Message).First(), Is.EqualTo("Name should end with 'zz'"));

            iv = ve.Validate(new EntityWithString { Name = "zz" });
            Assert.That(iv.Length, Is.EqualTo(1));
            Assert.That(iv.Select(i => i.Message).First(), Is.EqualTo("Name should start with 'ab'"));

            iv = ve.Validate(new EntityWithString { Name = "bc" });
            Assert.That(iv.Length, Is.EqualTo(2));
            var messages = iv.Select(i => i.Message);
            Assert.That(messages, Has.Member("Name should start with 'ab'") & Has.Member("Name should end with 'zz'"));
        }
        public void when_validate_customer_with_invalid_name_and_email_should_return_two_invalid_values()
        {
            var validatorEngine = new ValidatorEngine();
            var notValidCustomer = GetNotValidCustomer();
            validatorEngine.Configure();

            validatorEngine.Validate(notValidCustomer).Should().Have.Count.EqualTo(2);
        }
 public void CreateEngine()
 {
     var conf = new XmlConfiguration();
     conf.Properties[Environment.ValidatorMode] = "UseExternal";
     conf.Mappings.Add(new MappingConfiguration("NHibernate.Validator.Tests", "NHibernate.Validator.Tests.Engine.Tagging.EntityXml.nhv.xml"));
     ve = new ValidatorEngine();
     ve.Configure(conf);
 }
Exemple #7
0
        public void CreateValidatorEngine()
        {
            var configure = new FluentConfiguration();
            configure.Register(new[] {typeof (UserValidation), typeof (GroupValidation)})
                .SetDefaultValidatorMode(ValidatorMode.UseExternal);
            validatorEngine = new ValidatorEngine();

            validatorEngine.Configure(configure);
        }
        private static void ConfigureNHibernateValidator(Configuration configuration)
        {
            INHVConfiguration nhvc = (INHVConfiguration)new NHibernate.Validator.Cfg.Loquacious.FluentConfiguration()
                .SetDefaultValidatorMode(ValidatorMode.UseAttribute);

            var validator = new ValidatorEngine();
            validator.Configure(nhvc);
            configuration.Initialize(validator);
        }
 protected override void Configure(NHibernate.Cfg.Configuration configuration)
 {
     base.Configure(configuration);
     var nhvc = new FluentConfiguration();
     nhvc.SetDefaultValidatorMode(ValidatorMode.UseAttribute).IntegrateWithNHibernate.ApplyingDDLConstraints().And.
         RegisteringListeners();
     var onlyToUseToInitializeNh_Engine = new ValidatorEngine();
     onlyToUseToInitializeNh_Engine.Configure(nhvc);
     configuration.Initialize(onlyToUseToInitializeNh_Engine);
 }
 public virtual ValidatorEngine GetValidatorEngine()
 {
     var ve = new ValidatorEngine();
     var cfg = new XmlConfiguration();
     cfg.Properties[Environment.ValidatorMode] = "UseAttribute";
     cfg.Properties[Environment.ConstraintValidatorFactoryClass] =
         typeof (TestConstraintValidatorFactory).AssemblyQualifiedName;
     ve.Configure(cfg);
     return ve;
 }
 protected ValidatorEngine ConfigureValidator(NHibernate.Cfg.Configuration configuration)
 {
     var nhvc = new FluentConfiguration();
     nhvc.SetDefaultValidatorMode(ValidatorMode.UseExternal).IntegrateWithNHibernate.ApplyingDDLConstraints();
     nhvc.Register<PersonValidation, Person>();
     nhvc.Register<NameValidation, Name>();
     var engine = new ValidatorEngine();
     engine.Configure(nhvc);
     return engine;
 }
Exemple #12
0
 public ValidatorEngine GetValidatorEngine()
 {
     var vtor = new ValidatorEngine();
     var cfg = new XmlConfiguration();
     cfg.Properties[Environment.ValidatorMode] = "UseExternal";
     string an = Assembly.GetExecutingAssembly().FullName;
     cfg.Mappings.Add(new MappingConfiguration(an, "NHibernate.Validator.Tests.Specifics.NHV29.Mappings.nhv.xml"));
     vtor.Configure(cfg);
     return vtor;
 }
        public void DelegatedValidate_WithoutMessageNotThrow()
        {
            var configure = new FluentConfiguration();
            configure.Register(new[] { typeof(RangeDefWithoutCustomMessage) })
                .SetDefaultValidatorMode(ValidatorMode.UseExternal);
            var ve = new ValidatorEngine();

            ve.Configure(configure);
            ActionAssert.NotThrow(()=>ve.IsValid(new Range { Start = 1, End = 4 }));
        }
        public void DelegatedValidate_WithoutMessageHasInvalidValue()
        {
            var configure = new FluentConfiguration();
            configure.Register(new[] { typeof(RangeDefWithoutCustomMessage) })
                .SetDefaultValidatorMode(ValidatorMode.UseExternal);
            var ve = new ValidatorEngine();

            ve.Configure(configure);
            var iv = ve.Validate(new Range {Start = 5, End = 4});
            iv.Should().Not.Be.Empty();
        }
        public void Configure()
        {
            ValidatorEngine ve = new ValidatorEngine();

            ve.Configure();
            Assert.AreEqual(true, ve.ApplyToDDL);
            Assert.AreEqual(true, ve.AutoRegisterListeners);
            Assert.AreEqual(ValidatorMode.UseAttribute, ve.DefaultMode);
            Assert.IsNotNull(ve.Interpolator);
            Assert.AreEqual(typeof(PrefixMessageInterpolator), ve.Interpolator.GetType());
        }
        public void Engine_Validate()
        {
            var configure = new FluentConfiguration();
            configure.Register(new[] {typeof (RangeDef)}).SetDefaultValidatorMode(ValidatorMode.UseExternal);
            var ve = new ValidatorEngine();

            ve.Configure(configure);

            Assert.That(!ve.IsValid(new Range { Start = 5, End = 4 }));
            Assert.That(ve.IsValid(new Range { Start = 1, End = 4 }));
        }
 public static ValidatorEngine Get_Engine_Configured_for_Xml()
 {
     var vtor = new ValidatorEngine();
     var nhvc = new XmlConfiguration();
     nhvc.Properties[Environment.ApplyToDDL] = "false";
     nhvc.Properties[Environment.AutoregisterListeners] = "false";
     nhvc.Properties[Environment.ValidatorMode] = "UseExternal";
     nhvc.Mappings.Add(new MappingConfiguration("NHibernate.Validator.Demo.Ev", null));
     vtor.Configure(nhvc);
     return vtor;
 }
 public static ValidatorEngine Get_Engine_Configured_for_Fluent()
 {
     var vtor = new ValidatorEngine();
     var configuration = new FluentConfiguration();
     configuration
             .Register(Assembly.GetExecutingAssembly().GetTypes().Where(t => t.Namespace.Equals("NHibernate.Validator.Demo.Ev.Validators"))
             .ValidationDefinitions())
             .SetDefaultValidatorMode(ValidatorMode.UseExternal);
     vtor.Configure(configuration);
     return vtor;
 }
        public ValidatorFixtureLoquacious()
        {
            var configure = new FluentConfiguration();
            configure.Register(
                Assembly.GetExecutingAssembly().GetTypes()
                .Where(t => t.Namespace.Equals("NHibernate.Validator.Tests.Base"))
                .ValidationDefinitions())
            .SetDefaultValidatorMode(ValidatorMode.UseExternal);
            ve = new ValidatorEngine();

            ve.Configure(configure);
        }
        public override ValidatorEngine GetValidatorEngine()
        {
            var ve = new ValidatorEngine();
            var configuration = new FluentConfiguration();
            configuration
                .SetConstraintValidatorFactory<TestConstraintValidatorFactory>()
                .SetDefaultValidatorMode(ValidatorMode.UseExternal)
                .Register(new [] { typeof(Foo) }) ;

            ve.Configure(configuration);
            return ve;
        }
        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 NHDataAccessContext()
        {
            if (_cfg == null)
            _cfg = new Configuration().Configure();

              FluentConfiguration fluentCfg = Fluently.Configure(_cfg);
              fluentCfg.Mappings(m => m.FluentMappings.AddFromAssemblyOf<OrderMap>().ExportTo(@"c:\temp"));
              _sessionFactory = fluentCfg.BuildSessionFactory();
              ValidatorEngine engine = new ValidatorEngine();
              engine.Configure();

              ValidatorInitializer.Initialize(_cfg, engine);
        }
        public LoquaciousInheritanceFixture()
        {
            var configure = new FluentConfiguration();
            configure.Register(
                Assembly.Load("NHibernate.Validator.Tests")
                .ValidationDefinitions()
                .Where(t => t.Namespace.Equals("NHibernate.Validator.Tests.Inheritance"))
                )
            .SetDefaultValidatorMode(ValidatorMode.UseExternal);

            ve = new ValidatorEngine();
            ve.Configure(configure);
        }
        protected override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            Environment.SharedEngineProvider = new NHibernateSharedEngineProvider();
            vtor = Environment.SharedEngineProvider.GetEngine();
            vtor.Clear();
            var nhvc = new XmlConfiguration();
            nhvc.Properties[Environment.ApplyToDDL] = "false";
            nhvc.Properties[Environment.AutoregisterListeners] = "true";
            nhvc.Properties[Environment.ValidatorMode] = "UseAttribute";
            vtor.Configure(nhvc);

            configuration.Initialize();
        }
Exemple #25
0
 private NHVHelper()
 {
     engine = new ValidatorEngine();
     //var nhvc = new XmlConfiguration();
     //nhvc.Properties[NHibernate.Validator.Cfg.Environment.ApplyToDDL] = "false";
     //nhvc.Properties[NHibernate.Validator.Cfg.Environment.AutoregisterListeners] = "false";
     //nhvc.Properties[NHibernate.Validator.Cfg.Environment.ValidatorMode] = "UseAttribute";
     //nhvc.Mappings.Add(new MappingConfiguration("WebApplication1", null));
     engine.Configure(
         HttpContext.Current.Server.MapPath(
             Path.Combine("~/App_Data/", "nhvalidator.cfg.xml")
         )
     );
 }
        public void can_validate_legs()
        {
            var validationDef = new ValidationDef<Cat>();
            validationDef.Define(c => c.Legs).GreaterThanOrEqualTo(2);

            var vc = new FluentConfiguration();
            vc.SetDefaultValidatorMode(ValidatorMode.UseExternal);
            vc.Register(validationDef);

            var ve = new ValidatorEngine();
            ve.Configure(vc);

            ve.Validate(new Cat {Legs = 0}).Should().Have.Count.EqualTo(1);
            ve.Validate(new Cat {Legs = 3}).Should().Be.Empty();
        }
 public static void Initialize(Configuration cfg)
 {
     if (cfg == null)
         throw new ArgumentNullException("cfg");
     ValidatorEngine ve;
     if (Environment.SharedEngineProvider != null)
     {
         ve = Environment.SharedEngineProvider.GetEngine();
     }
     else
     {
         ve = new ValidatorEngine();
         ve.Configure();
     }
     Initialize(cfg, ve);
 }
        protected override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            var configure = new FluentConfiguration();

            configure
                .SetDefaultValidatorMode(ValidatorMode.UseExternal)
                .IntegrateWithNHibernate
                .ApplyingDDLConstraints()
                .And
                .RegisteringListeners();

            var validatorEngine = new ValidatorEngine();
            validatorEngine.Configure(configure);

            configuration.Initialize(validatorEngine);
        }
        public void Validate()
        {
            var configure = new FluentConfiguration();

            var validationDef = new ValidationDef<EntityWithCollection>();
            validationDef.Define(e => e.Value).Satisfy(v => v != null && v.Any(e => e == "something")).WithMessage("Should contain 'something'");

            configure.Register(validationDef).SetDefaultValidatorMode(ValidatorMode.UseExternal);
            var ve = new ValidatorEngine();

            ve.Configure(configure);

            Assert.That(ve.IsValid(new EntityWithCollection { Value = new[]{"b", "something"} }));
            Assert.That(!ve.IsValid(new EntityWithCollection()));
            Assert.That(!ve.IsValid(new EntityWithCollection { Value = new[] { "b" } }));
        }
        public void ValidateWithSingleCondition()
        {
            var configure = new FluentConfiguration();

            var validationDef = new ValidationDef<EntityWithString>();
            validationDef.Define(e => e.Name).Satisfy(name => name != null && name.StartsWith("ab")).WithMessage(
                "Name should start with 'ab'");

            configure.Register(validationDef).SetDefaultValidatorMode(ValidatorMode.UseExternal);
            var ve = new ValidatorEngine();

            ve.Configure(configure);

            Assert.That(ve.IsValid(new EntityWithString {Name = "abc"}));
            Assert.That(!ve.IsValid(new EntityWithString { Name = "bc" }));
        }
        public void IntentWrongNHVConfig()
        {
            ValidatorEngine ve = new ValidatorEngine();

            Assert.That(() => ve.Configure((INHVConfiguration)null), Throws.TypeOf <ValidatorConfigurationException>());
        }