There are plenty of hacks you could do so that it does not run when
you are running your unit tests...
One way would be to create a new validation registry that mimics the
behavior of CachedValidationRegistry, but ignores that particular
validator. It is a little bit of cut and paste work becaused
CachedValidationRegistry's methods are not virtual. Then in your test
setup, you can do:
controller.Validator = new ValidatorRunner(new
MyValidationRegistry());
Another way would be to override the ValidateIsUniqueAttribute class
and have the constructor check a variable to see if if should create
the IsUniqueValidator or not. Pseudo code:
MyValidateIsUniqueAttribute : ValidateIsUniqueAttribute
public MyValidateIsUniqueAttribute()
validator = Local.Data["IsUnitTest"] ? new
AlwaysReturnsNoErrorsValidator() : new IsUniqueValidator();