I'm participating in a project using ASP.NET MVC 3 and DataAnnotations. We have DataAnnotations in ViewModels classes.
How do you write unit tests for these validations?
ViewModel example:
public class AchievementVM
{
[Required(ErrorMessage = "The title field is required.")]
[StringLength(100, ErrorMessage = "Title must be 100 characters or less.")]
public string Title { get; set; }
}
MVC3 data annotation works in two part, one is at client side by jquery unabstrusive validation and another one is at server wity default model binder.
With unit test you can not do first one but second one is doable. You can refer
this article, it talks about it in later part.
ygorthomaz
Member
1 Points
1 Post
TDD: What is best practice to test DataAnnotations in ASP.NET MVC 3?
Aug 07, 2012 11:31 PM|LINK
I'm participating in a project using ASP.NET MVC 3 and DataAnnotations. We have DataAnnotations in ViewModels classes.
How do you write unit tests for these validations?
ViewModel example:
public class AchievementVM { [Required(ErrorMessage = "The title field is required.")] [StringLength(100, ErrorMessage = "Title must be 100 characters or less.")] public string Title { get; set; } }Thanks!
CPrakash82
All-Star
18270 Points
2839 Posts
Re: TDD: What is best practice to test DataAnnotations in ASP.NET MVC 3?
Aug 08, 2012 01:28 AM|LINK
MVC3 data annotation works in two part, one is at client side by jquery unabstrusive validation and another one is at server wity default model binder.
With unit test you can not do first one but second one is doable. You can refer this article, it talks about it in later part.