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


C# ValidatorEngine.ValidatePropertyValue方法代码示例

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


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

示例1: ValidateChangedPropertyOfProxy

        public void ValidateChangedPropertyOfProxy()
        {
            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);
                proxy.Description = "no";

                Assert.AreEqual(1, engine.ValidatePropertyValue(proxy, p => p.Description).Length);
                Assert.DoesNotThrow(() => engine.ValidatePropertyValue(proxy, p => p.Description));

                Assert.AreEqual(1, engine.ValidatePropertyValue(proxy, "Description").Length);
                Assert.DoesNotThrow(() => engine.ValidatePropertyValue(proxy, "Description"));
            }

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

示例2: ShouldAddAnothersMessagesUsingValidationProperties

        public void ShouldAddAnothersMessagesUsingValidationProperties()
        {
            var vtor = new ValidatorEngine();
            var mi = new MembershipInfo
            {
                Username = null,
                Password = "123X"
            };

            InvalidValue[] invalidValues = vtor.ValidatePropertyValue(mi, x => x.Password);
            Assert.AreEqual(2, invalidValues.Length);
            Assert.AreEqual(Messages.PasswordLength, invalidValues.ElementAt(0).Message);
            Assert.AreEqual(Messages.PasswordContent, invalidValues.ElementAt(1).Message);
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:14,代码来源:ConstraintContextIntegrationFixture.cs

示例3: ValidatePropertyValueOfInstance

        public void ValidatePropertyValueOfInstance()
        {
            var b = new BaseClass();
            var d = new DerivatedClass();

            var ve = new ValidatorEngine();
            Assert.AreEqual(1, ve.ValidatePropertyValue(b, "A").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue(d, "A").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue(b, e => e.A).Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue(d, e => e.A).Length);

            b.A = "1234";
            Assert.AreEqual(1, ve.ValidatePropertyValue(b, "A").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue(b, e => e.A).Length);
            d.A = "1234";
            Assert.AreEqual(1, ve.ValidatePropertyValue(d, "A").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue(d, e => e.A).Length);
            d.B = "123456";
            Assert.AreEqual(1, ve.ValidatePropertyValue(d, "B").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue(d, e => e.B).Length);
            d.B = null;
            Assert.AreEqual(0, ve.ValidatePropertyValue(d, "B").Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue(d, e => e.B).Length);

            try
            {
                ve.ValidatePropertyValue(d, "WrongName");
                Assert.Fail("Intent to validate a wrong property don't throw any exception.");
            }
            catch (TargetException)
            {
                //ok
            }

            // same behavior GetInvalidValues(object)
            Assert.AreEqual(0, ve.ValidatePropertyValue(null, "A").Length);

            try
            {
                ve.ValidatePropertyValue(d, "");
                Assert.Fail("Intent to validate a empty property name don't throw any exception.");
            }
            catch (ArgumentNullException)
            {
                //ok
            }
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:47,代码来源:ValidatorEngineFixture.cs

示例4: ValidatePropertyValue

        public void ValidatePropertyValue()
        {
            var ve = new ValidatorEngine();
            Assert.AreEqual(1, ve.ValidatePropertyValue<BaseClass>("A", null).Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue<DerivatedClass>("A", null).Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue<BaseClass>("A", "1234").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue<DerivatedClass>("A", "1234").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue<DerivatedClass>("B", "123456").Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue<DerivatedClass>("B", null).Length);

            Assert.AreEqual(1, ve.ValidatePropertyValue<BaseClass, string>(x => x.A, null).Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue<DerivatedClass, string>(x => x.A, null).Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue<BaseClass, string>(x => x.A, "1234").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue<DerivatedClass, string>(x => x.A, "1234").Length);
            Assert.AreEqual(1, ve.ValidatePropertyValue<DerivatedClass, string>(x => x.B, "123456").Length);
            Assert.AreEqual(0, ve.ValidatePropertyValue<DerivatedClass, string>(x => x.B, null).Length);

            try
            {
                ve.ValidatePropertyValue<DerivatedClass>("WrongName", null);
                Assert.Fail("Intent to validate a wrong property don't throw any exception.");
            }
            catch (TargetException)
            {
                //ok
            }
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:27,代码来源:ValidatorEngineFixture.cs

示例5: ValidateAnyClass

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


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