Skip to content

Instantly share code, notes, and snippets.

@linuxbender
Created February 10, 2012 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuxbender/1786130 to your computer and use it in GitHub Desktop.
Save linuxbender/1786130 to your computer and use it in GitHub Desktop.
How to Unit Test Data Annotation Validators
[TestMethod]
public void Description_Should_Be_Required()
{
Expression<Func<MenuCategoryBusinessObject, object>> expression =
o => o.Description;
var me = expression.Body as MemberExpression;
var att = (RequiredAttribute[])me.Member
.GetCustomAttributes(typeof(RequiredAttribute), false);
att.Length.ShouldEqual(1);
}
ModelBinders.Binders.DefaultBinder = new DataAnnotationsModelBinder();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment