本文整理汇总了C#中ValidatorEngine类的典型用法代码示例。如果您正苦于以下问题:C# ValidatorEngine类的具体用法?C# ValidatorEngine怎么用?C# ValidatorEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidatorEngine类属于命名空间,在下文中一共展示了ValidatorEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NHibernateValidatorClientModelValidator
public NHibernateValidatorClientModelValidator(ModelMetadata metadata, ControllerContext controllerContext, IClassValidator validator, ValidatorEngine engine)
: base(metadata, controllerContext)
{
_engine = engine;
_validator = validator;
this.PropertyName = metadata.PropertyName;
}
示例2: 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);
}
示例3: GetValidatorEngine
private static ValidatorEngine GetValidatorEngine()
{
var cfg = GetNhvConfiguration();
var validatorEngine = new ValidatorEngine();
validatorEngine.Configure(cfg);
return validatorEngine;
}
示例4: ManuallyBuildValidatorSources
private static IValidatorEngine ManuallyBuildValidatorSources()
{
var scanSource = new ModelScanValidatorSource();
var customerValidatorSource = new CustomerValidatorSource();
var engine = new ValidatorEngine(new IValidatorSource[] { scanSource, customerValidatorSource });
return engine;
}
示例5: Configure
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);
}
示例6: CreateValidationEngine
///<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;
}
示例7: 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'"));
}
示例8: IntegrationWithValidation
public void IntegrationWithValidation()
{
ValidatorEngine ve = new ValidatorEngine();
ve.AssertValid(new Foo(1));
Assert.IsFalse(ve.IsValid(new Foo(3)));
}
示例9: ConfigureNHibernate
/// <summary>
/// Metodo responsavel por executar o mapeamento das classes com o banco de dados
/// </summary>
/// <param name="databaseConfigurer"></param>
/// <param name="validatorEngine"></param>
/// <returns></returns>
private static ISessionFactory ConfigureNHibernate(IPersistenceConfigurer databaseConfigurer,
out ValidatorEngine validatorEngine)
{
ValidatorEngine ve = null;
ISessionFactory factory = Fluently.Configure()
.Database(databaseConfigurer)
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<UsuarioMap>()
.Conventions.Add(typeof(CascadeAll))
)
.Cache(x =>
x.UseQueryCache()
.UseSecondLevelCache()
.ProviderClass<SysCacheProvider>()
)
.ExposeConfiguration(c =>
{
ve = ConfigureValidator(c);
c.SetProperty("adonet.batch_size", "5");
c.SetProperty("generate_statistics", "false");
//c.SetProperty("cache.use_second_level_cache", "true");
})
.BuildConfiguration().BuildSessionFactory();
validatorEngine = ve;
return factory;
}
示例10: NoEndlessLoop
public void NoEndlessLoop()
{
var john = new User("John", null);
john.Knows(john);
var validator = new ValidatorEngine();
InvalidValue[] constraintViolations = validator.Validate(john);
Assert.AreEqual(constraintViolations.Length, 1, "Wrong number of constraints");
Assert.AreEqual("LastName", constraintViolations.ElementAt(0).PropertyName);
var jane = new User("Jane", "Doe");
jane.Knows(john);
john.Knows(jane);
constraintViolations = validator.Validate(john);
Assert.AreEqual(constraintViolations.Length, 1, "Wrong number of constraints");
Assert.AreEqual("LastName", constraintViolations.ElementAt(0).PropertyName);
constraintViolations = validator.Validate(jane);
Assert.AreEqual(1, constraintViolations.Length, "Wrong number of constraints");
Assert.AreEqual(constraintViolations.ElementAt(0).PropertyPath, "knowsUser[0].LastName");
john.LastName = "Doe";
constraintViolations = validator.Validate(john);
Assert.AreEqual(0, constraintViolations.Length, "Wrong number of constraints");
}
示例11: ConfigureFile
public void ConfigureFile()
{
// This test is for .Configure(XmlReader) too
string tmpf = Path.GetTempFileName();
using (StreamWriter sw = new StreamWriter(tmpf))
{
sw.WriteLine("<?xml version='1.0' encoding='utf-8' ?>");
sw.WriteLine("<nhv-configuration xmlns='urn:nhv-configuration-1.0'>");
sw.WriteLine("<property name='apply_to_ddl'>false</property>");
sw.WriteLine("<property name='autoregister_listeners'>false</property>");
sw.WriteLine("<property name='default_validator_mode'>OverrideAttributeWithExternal</property>");
sw.WriteLine("<property name='message_interpolator_class'>"
+ typeof(PrefixMessageInterpolator).AssemblyQualifiedName + "</property>");
sw.WriteLine("</nhv-configuration>");
sw.Flush();
}
ValidatorEngine ve = new ValidatorEngine();
ve.Configure(tmpf);
Assert.AreEqual(false, ve.ApplyToDDL);
Assert.AreEqual(false, ve.AutoRegisterListeners);
Assert.AreEqual(ValidatorMode.OverrideAttributeWithExternal, ve.DefaultMode);
Assert.IsNotNull(ve.Interpolator);
Assert.AreEqual(typeof(PrefixMessageInterpolator), ve.Interpolator.GetType());
}
示例12: CreateEngine
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);
}
示例13: when_validate_customer_with_invalid_name_and_email_should_return_two_invalid_values
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);
}
示例14: ConfigureNHibernateValidator
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);
}
示例15: ViewValidator
public ViewValidator(ValidatorEngine validatorEngine, ErrorProvider errorProvider)
: this(errorProvider)
{
Check.NotNull(
validatorEngine,
"ve",
"The ValidatorEngine is null");
this.validatorEngine = validatorEngine;
}