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


C# ValidatorEngine.AssertValid方法代码示例

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


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

示例1: AssertValid

 public void AssertValid()
 {
     ValidatorEngine ve = new ValidatorEngine();
     ve.AssertValid(new AnyClass()); // not cause exception
     try
     {
         Boo b = new Boo();
         ve.AssertValid(b);
         Assert.Fail("An invalid entity not throw exception.");
     }
     catch (InvalidStateException)
     {
         // OK
     }
 }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:15,代码来源:ValidatorEngineFixture.cs

示例2: 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

示例3: Main

        private static void Main(string[] args)
        {
            ///Configuration at Application Start-up.
            var container = new WindsorContainer();
            IoC.Container = container;
            //registering NHV out-of-the-box constraint validators
            WindsorConstraintValidatorFactory.RegisteringValidators(container);

            //registering your own constraint validators
            container.AddComponent(typeof (PersonNameValidator).Name.ToLower(), typeof (PersonNameValidator));
            ///End of IoC Configuration.

            var vtor = new ValidatorEngine();
            vtor.Configure();

            //Validating a valid entity 'Contact'
            var validCustomer = new Contact
                                    {
                                        FirstName = "Dario",
                                        LastName = "Quintana",
                                        Address = "2nd Street at 34",
                                        Description = "Some description"
                                    };

            vtor.AssertValid(validCustomer);

            //Validating an invalid entity 'Contact'
            var invalidCustomer = new Contact
                                  	{
                                  		FirstName = "dario" /*INVALID*/,
                                  		LastName = "Quintana",
                                  		Address = "2nd Street at 34",
                                  		Description = "Some description"
                                  	};

            Debug.Assert(vtor.Validate(invalidCustomer).Length == 1);
            Console.WriteLine("Done.");
            Console.ReadKey(true);
        }
开发者ID:spib,项目名称:nhcontrib,代码行数:39,代码来源:Program.cs

示例4: 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

示例5: 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

示例6: 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

示例7: NullIsAllwaysValid

 public void NullIsAllwaysValid()
 {
     ValidatorEngine ve = new ValidatorEngine();
     Assert.IsTrue(ve.IsValid(null));
     Assert.AreEqual(0, ve.Validate(null).Length);
     ve.AssertValid(null); // not cause exception
 }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:7,代码来源:ValidatorEngineFixture.cs


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