How do I unit test ASP.NET MVC2 model validation?
I'm using Nunit as my unit testing framework and I've created a couple of L2S entities and validation classes. Now I want to unit test the validation, but I can't figure out how to do that.
This is my validation class:
[Bind(Exclude = "ProjectID")]
public class ProjectValidation {
[Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = "RequiredProjectName")]
[LocalizedDisplayName("ProjectName", NameResourceType = typeof(ValidationMessages))]
public string Name { get; set; }
[LocalizedDisplayName("StartDate", NameResourceType = typeof(ValidationMessag开发者_运维知识库es))]
public DateTime StartDate { get; set; }
[Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = "RequiredCustomer")]
[LocalizedDisplayName("Customer", NameResourceType = typeof(ValidationMessages))]
public int FK_CustomerId { get; set; }
[LocalizedDisplayName("StartDate", NameResourceType = typeof(ValidationMessages))]
public String Contact { get; set; }
}
And this is my Entity:
[MetadataType(typeof(ProjectValidation))]
public partial class Project : IEntity {
}
精彩评论