Testing ModelState is always valid in asp.net mvc

后端 未结 7 1135
野趣味
野趣味 2020-12-09 16:29

When testing my controller\'s actions the ModelState is always valid.

public class Product
{
    public int Id { get; set; }

    [Required]
    [StringLengt         


        
7条回答
  •  醉话见心
    2020-12-09 16:44

    If you want to test your validation action's behavior you could simply add ModelStateError:

    ModelState.AddModelError("Password", "The Password field is required");
    

提交回复
热议问题