I asked the same question in the nhibernate message group. Here is my
latest test code that doesn't work. If someone see's the problem it
will help us all.
using NHibernate.Validator.Cfg;
using Environment = NHibernate.Validator.Cfg.Environment;
namespace TestValidator
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestValidator()
{
var customer = new Customer();
ClassValidator classValidator = new
ClassValidator(customer.GetType());
InvalidValue[] validationMessages =
classValidator.GetInvalidValues(customer);
Assert.IsTrue(validationMessages.Length == 1);
Assert.IsTrue(validationMessages[0].Message == "may not be
null or empty");
}
[TestMethod]
public void TestCustomInterpolator()
{
ValidatorEngine ve = new ValidatorEngine();
NHVConfiguration nhvc = new NHVConfiguration();
nhvc.Properties[Environment.MessageInterpolatorClass] =
typeof(CustomMessageInterpolator).AssemblyQualifiedName;
ve.Configure(nhvc);
var customer = new Customer();
ClassValidator classValidator = new
ClassValidator(customer.GetType());
InvalidValue[] validationMessages =
classValidator.GetInvalidValues(customer);
Assert.IsTrue(validationMessages.Length == 1);
Assert.IsTrue(validationMessages[0].Message ==
"CustomMessageInterpolator");
}
}
public class Customer
{
public virtual int CustomerId { get; set; }
[NotNullNotEmpty]
public string CustomerName { get; set; }
}
public class CustomMessageInterpolator : IMessageInterpolator
{
public CustomMessageInterpolator()
{
}
public string Interpolate(string message, IValidator validator,
IMessageInterpolator defaultInterpolator)
{
return "CustomMessageInterpolator";
}
}
}
On Wed, May 27, 2009 at 6:19 AM, tjbsb <[email protected]> wrote:
>
> How do I go about configuring a custom message interpolator?
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---