本文整理汇总了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();
}
示例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);
}
示例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
}
}
示例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
}
}
示例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);
}