Click here to Skip to main content
Sign Up to vote bad
good
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
Posted 4 Feb '13 - 20:17
Edited 5 Feb '13 - 1:24
Tadit Dash23.2K


1 solution

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.
  Permalink  
Comments
sarahnimy - 5 Feb '13 - 23:15
thanks a lot.... helped me a lot in unit testing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 198
1 Sergey Alexandrovich Kryukov 159
2 Richard MacCutchan 150
3 Maciej Los 136
4 Tadit Dash 110
0 Sergey Alexandrovich Kryukov 10,264
1 OriginalGriff 7,937
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,135


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid