当前位置: 首页>>代码示例>>C#>>正文


C# ValidatorEngine.IsValid方法代码示例

本文整理汇总了C#中ValidatorEngine.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# ValidatorEngine.IsValid方法的具体用法?C# ValidatorEngine.IsValid怎么用?C# ValidatorEngine.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ValidatorEngine的用法示例。


在下文中一共展示了ValidatorEngine.IsValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateWithMultipleConditions

        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'"));
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:30,代码来源:StringConstraintsTests.cs

示例2: Engine_Validate

        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 }));
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:11,代码来源:EngineIntegrationTest.cs

示例3: IntegrationWithValidation

        public void IntegrationWithValidation()
        {
            ValidatorEngine ve = new ValidatorEngine();
            ve.AssertValid(new Foo(1));

            Assert.IsFalse(ve.IsValid(new Foo(3)));
        }
开发者ID:pruiz,项目名称:nhibernate-contrib-old,代码行数:7,代码来源:ValidatorClassFixture.cs

示例4: Validate

        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" } }));
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:16,代码来源:CollectionConstraintsTests.cs

示例5: InterpolatingMemberAndSubMembers

        public void InterpolatingMemberAndSubMembers()
        {
            var c = new Contractor
            {
                SubcontractorHourEntries = new List<SubcontractorHourEntry>
                                                       	{
                                                       		new SubcontractorHourEntry
                                                       			{
                                                       				Contrator = new SubContractor(1),
                                                       				Hour = 9
                                                       			},
                                                       		new SubcontractorHourEntry
                                                       			{
                                                       				Contrator = new SubContractor(2),
                                                       				Hour = 10
                                                       			}
                                                       	}
            };

            var vtor = new ValidatorEngine();
            Assert.IsFalse(vtor.IsValid(c));
            var values = vtor.Validate(c);
            Assert.AreEqual(1, values.Length);
            Assert.AreEqual("The min value in the SubContractor Id: 1 is invalid. Instead was found: 9", values[0].Message);
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:25,代码来源:InterpolatingValuesFixture.cs

示例6: ValidateWithSingleCondition

        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" }));
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:16,代码来源:StringConstraintsTests.cs

示例7: Validate

        public void Validate()
        {
            var configure = new FluentConfiguration();

            var validationDef = new ValidationDef<EntityWithDate>();
            validationDef.Define(e => e.Value).Satisfy(v => v.Year == DateTime.Today.Year).WithMessage("In this year");
            validationDef.Define(e => e.NullValue).Satisfy(v => v.HasValue).WithMessage("HasValue");

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

            ve.Configure(configure);

            Assert.That(ve.IsValid(new EntityWithDate { Value = DateTime.Today, NullValue = DateTime.Today }));
            Assert.That(!ve.IsValid(new EntityWithDate()));
            Assert.That(!ve.IsValid(new EntityWithDate { Value = DateTime.Today }));
            Assert.That(!ve.IsValid(new EntityWithDate { NullValue = DateTime.Today }));
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:18,代码来源:DateTimeConstraintsTests.cs

示例8: DelegatedValidate_WithoutMessageNotThrow

        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 }));
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:10,代码来源:EngineIntegrationTest.cs

示例9: LoadMappingsSpecific

 public void LoadMappingsSpecific()
 {
     var nhvc = new XmlConfiguration();
     nhvc.Properties[Environment.ValidatorMode] = "useExternal";
     nhvc.Properties[Environment.MappingLoaderClass] = "NHibernate.Validator.Cfg.Loquacious.FluentMappingLoader, NHibernate.Validator";
     nhvc.Mappings.Add(new MappingConfiguration("NHibernate.Validator.Tests",
                                                "NHibernate.Validator.Tests.Configuration.Loquacious.AddressValidationDef"));
     nhvc.Mappings.Add(new MappingConfiguration("NHibernate.Validator.Tests",
                                                                                          "NHibernate.Validator.Tests.Configuration.Loquacious.BooValidationDef"));
     var ve = new ValidatorEngine();
     ve.Configure(nhvc);
     var a = new Address {Country = string.Empty};
     var b = new Boo();
     Assert.That(ve.IsValid(a));
     Assert.That(!ve.IsValid(b));
     a.Country = "bigThan5Chars";
     Assert.That(!ve.IsValid(a));
     b.field = "whatever";
     Assert.That(ve.IsValid(b));
 }
开发者ID:spib,项目名称:nhcontrib,代码行数:20,代码来源:IntegrationFixture.cs

示例10: IsValid

        public void IsValid()
        {
            ve = new ValidatorEngine();

            Run(delegate
            {
                for (int i = 0; i < ITERATIONS; i++)
                {
                    Thread t = new Thread(delegate() { ve.IsValid(new Foo()); });

                    t.Start();
                }
            });
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:14,代码来源:ThreadSafeFixture.cs

示例11: Run_Example_With_Valid_Entity

        private static void Run_Example_With_Valid_Entity(ValidatorEngine vtor)
        {
            Console.WriteLine("==Entity with valid values==");
            var m = new Meeting
                        {
                            Name = "NHibernate Validator virtual meeting",
                            Description = "How to configure NHibernate Validator in different ways.",
                            Start = DateTime.Now,
                            End = DateTime.Now.AddHours(2) // 2 hours of meeting.
                        };

            if(vtor.IsValid(m))
                Console.WriteLine("The entity is valid.");
            else
                throw new Exception("Something was wrong in the NHV configuration, the entity should be invalid.");
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:16,代码来源:Program.cs

示例12: InitializeValidators

        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>());
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:19,代码来源:ValidatorEngineFixture.cs

示例13: ValidateHasValidElementsWithProxies

        public void ValidateHasValidElementsWithProxies()
        {
            var validatorConf = new FluentConfiguration();
            validatorConf.SetDefaultValidatorMode(ValidatorMode.UseExternal);

            var vDefSimple = new ValidationDef<SimpleWithCollection>();
            vDefSimple.Define(s => s.Relations).HasValidElements();
            validatorConf.Register(vDefSimple);

            var vDefRelation = new ValidationDef<Relation>();
            vDefRelation.Define(s => s.Description).MatchWith("OK");
            validatorConf.Register(vDefRelation);

            var engine = new ValidatorEngine();
            engine.Configure(validatorConf);

            object savedIdRelation;
            // fill DB
            using (ISession s = OpenSession())
            using (ITransaction tx = s.BeginTransaction())
            {
                var relation = new Relation { Description = "OK" };
                savedIdRelation = s.Save(relation);
                tx.Commit();
            }

            using (ISession s = OpenSession())
            {
                var proxy = s.Load<Relation>(savedIdRelation);
                var simpleWithCol = new SimpleWithCollection();
                simpleWithCol.Relations = new List<Relation> {proxy};

                Assert.DoesNotThrow(() => engine.Validate(simpleWithCol));

                proxy.Description = "No-o-k";
                Assert.IsFalse(engine.IsValid(simpleWithCol));

            }

            CleanDb();
        }
开发者ID:pruiz,项目名称:nhibernate-contrib-old,代码行数:41,代码来源:ValidatingProxyFixture.cs

示例14: ValidateNotInitializeProxyAtFirstLevel

        public void ValidateNotInitializeProxyAtFirstLevel()
        {
            var validatorConf = new FluentConfiguration();
            validatorConf.SetDefaultValidatorMode(ValidatorMode.UseExternal);

            var vDefSimple = new ValidationDef<SimpleWithRelation>();
            vDefSimple.Define(s => s.Name).MatchWith("OK");
            validatorConf.Register(vDefSimple);

            var engine = new ValidatorEngine();
            engine.Configure(validatorConf);

            object savedId;
            // fill DB
            using (ISession s = OpenSession())
            using (ITransaction tx = s.BeginTransaction())
            {
                savedId = s.Save(new SimpleWithRelation { Name = "OK" });
                tx.Commit();
            }

            using (ISession s = OpenSession())
            {
                var proxy = s.Load<SimpleWithRelation>(savedId);
                Assert.That(engine.IsValid(proxy));
                Assert.DoesNotThrow(() => engine.AssertValid(proxy));
                Assert.That(!NHibernateUtil.IsInitialized(proxy), "should not initialize the proxy");
            }

            CleanDb();
        }
开发者ID:pruiz,项目名称:nhibernate-contrib-old,代码行数:31,代码来源:ValidatingProxyFixture.cs

示例15: ValidateInitializedProxyAtDeepLevel

        public void ValidateInitializedProxyAtDeepLevel()
        {
            var validatorConf = new FluentConfiguration();
            validatorConf.SetDefaultValidatorMode(ValidatorMode.UseExternal);

            var vDefSimple = new ValidationDef<SimpleWithRelation>();
            vDefSimple.Define(s => s.Name).MatchWith("OK");
            vDefSimple.Define(s => s.Relation).IsValid();
            validatorConf.Register(vDefSimple);

            var vDefRelation = new ValidationDef<Relation>();
            vDefRelation.Define(s => s.Description).MatchWith("OK");
            validatorConf.Register(vDefRelation);

            var engine = new ValidatorEngine();
            engine.Configure(validatorConf);

            object savedIdRelation;
            // fill DB
            using (ISession s = OpenSession())
            using (ITransaction tx = s.BeginTransaction())
            {
                var relation = new Relation{ Description = "OK" };
                savedIdRelation = s.Save(relation);
                tx.Commit();
            }

            using (ISession s = OpenSession())
            {
                var proxy = s.Load<Relation>(savedIdRelation);
                NHibernateUtil.Initialize(proxy);
                Assert.That(engine.IsValid(new SimpleWithRelation { Name = "OK", Relation = proxy }));
                Assert.DoesNotThrow(() => engine.AssertValid(new SimpleWithRelation { Name = "OK", Relation = proxy }));
            }

            CleanDb();
        }
开发者ID:pruiz,项目名称:nhibernate-contrib-old,代码行数:37,代码来源:ValidatingProxyFixture.cs


注:本文中的ValidatorEngine.IsValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。