title: Unit Testing MetadataType
body: <p>I'm working on a ASP.NET MVC 2 application and i test my Viewmodels Like this</p>
  
  <pre><code>[TestMethod]
  public void EmailNeedsToBeSet()
  {
      var pvm = new ProfileViewModel {Email = ""};
      var validationResults = new ValidationResults();
      var result = Validator.TryValidateObject(pvm, new ValidationContext(pvm, null, null), validationResults, true);
      Assert.IsFalse(result);
      Assert.IsTrue(validationResults.ContainsField&lt;ProfileViewModel&gt;(m =&gt; m.Email));
  }
  </code></pre>
  
  <p>The Email Property is required and this testmethod works fine</p>
  
  <p>My Question is now: How can i test a MetaData Class like in the test before? the validation results are always true. Or isn't this possible?</p>
  
  <p>Example of my MetaData-Class:</p>
  
  <pre><code>[MetadataType(typeof (UserMetaData))]
  public partial class User
  {
     public class UserMetaData
     {
        [Required(ErrorMessageResourceName = "Required",
        ErrorMessageResourceType = typeof (ValidationStrings))]
        [LocalizedDisplayName("LoginName", NameResourceType = typeof (Fields))]
        [StringLength(64)]
        public string Login { get; set; }
     }
  }
  </code></pre>