开发者

How do I unit test ASP.NET MVC2 model validation?

开发者 https://www.devze.com 2023-01-09 18:49 出处:网络
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.

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 {
}
0

精彩评论

暂无评论...
验证码 换一张
取 消