模型属性的单元测试 [英] Unit Testing for Model Property

查看:99
本文介绍了模型属性的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用模型验证为模型属性创建测试方法。

例如

Can we create test methods for model properties with model validations.
e.g.

public class PersonAccount
{
    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "New password")]
    public string NewPassword { get; set; }

}





如果是,那我们该怎么做呢,请帮我举个例子。 ...

如果没有,为什么?

请帮助



If yes, then how can we do it, please help me with an example....
And if not, why ?
Please help

推荐答案

这是相当直的在MVC中使用注释转发测试模型。 这个 [ ^ ]应该给你一个合适的基础开始。请特别注意 ValidationContext 上的部分,因为这是真正有助于它工作的伏都教。
It''s fairly straight forward testing a model with annotations in MVC. This[^] should give you a decent grounding in where to start. Pay particular attention to the section on the ValidationContext as this is the voodoo that really helps make it work.


这篇关于模型属性的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆