I am using DataAnnotations for my model validation
using System.ComponentModel.DataAnnotations;
namespace MvcApplication2.Models
{
public class Fiz
{
[Required]
public string Name { get; set; }
[Required]
[RegularExpression(".+@..+")]
public string Email { get; set; }
[Required]
public string adress { get; set; }
[Required]
public string city { get; set; }
[Required]
public string gold { get; set; }
[Required]
public string father { get; set; }
}
}
// test class
[TestMethod]
public void EmailRequired()
{
var fiz = new Fiz
{
Email = "exemple"
};
Assert.IsTrue(ValidateModel(fiz).Count > 0);
}
private IList<ValidationResult> ValidateModel(object model)
{
var validationResults = new List<ValidationResult>();
var ctx = new ValidationContext(model, null, null);
Validator.TryValidateObject(model, ctx, validationResults, true);
return validationResults;
}
the problem that i want to test just the Email but in this case i have to give a values to fiz.Name;fiz.adress;.....
any solutions? thinks