Throw localized ValidationException
See the question and my original answer on StackOverflowThe following should work, provided OurThing
points to the generated strongly-typed resource class, for looking up localized strings, etc, and "EmailUniqueError"
is one of the static properties of this class:
public class UniquenessAttribute : ValidationAttribute
{
public UniquenessAttribute()
{
ErrorMessageResourceName = "EmailUniqueError";
ErrorMessageResourceType = typeof (Resources.OurThing);
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (failure) // to implement
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
...
}
}
Also make sure you're validating all properties (if you use TryValidateObject for example, make sure the last parameter is set to true) when doing your tests.