.NET フレームワークには、検証ロジックを分離して実行できるValidatorクラスが付属しています。テストするコードは次のようになります。
var achievement = new AchievementVM();
var context = new ValidationContext(achievement,
serviceProvider: null, items: null);
var results = new List<ValidationResult>();
var isValid = Validator.TryValidateObject(achievement, context, results, true);
Assert.IsTrue(results.Any(vr => vr.ErrorMessage == "The title field is required."));
achievement.Title = "Really really long title that violates "
+ "the range constraint and should not be accepted as "
+ "valid input if this has been done correctly.";
Validator.TryValidateObject(achievement, context, results, true);
Assert.IsTrue(results.Any(vr => vr.ErrorMessage == "Title must be 100 characters or less."));
カスタム ユーティリティで属性の存在を検索する必要はありません。Validator クラスが作業を行い、MVC インフラストラクチャと同じように ValidationResult コレクションを設定します。
この方法に関する優れた記事は、K. Scott Allen のブログにあります。