【发布时间】:2012-08-03 20:29:29
【问题描述】:
我正在参与一个使用 ASP.NET MVC 3 和 DataAnnotations 的项目。我们在 ViewModels 类中有 DataAnnotations。
您如何为这些验证编写单元测试?
ViewModel 示例:
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; }
}
谢谢!
【问题讨论】:
-
这个数据注解是做什么的?是验证还是别的什么?
-
它标记了一些要验证的组件。使用数据注释进行手动验证的实际示例:odetocode.com/blogs/scott/archive/2011/06/29/…
标签: asp.net-mvc unit-testing tdd data-annotations