I have one class which is derived from ValidationAttribute (of DataAnnotation in MVC)
Following is the overridden method of this class:
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value == null)
return ValidationResult.Success;
var tagWithoutClosingRegex = new Regex(@"<[^>]+>");
var hasTags = tagWithoutClosingRegex.IsMatch(value.ToString());
if (!hasTags)
return ValidationResult.Success;
return new ValidationResult(String.Format("{0} cannot contain html tags", validationContext.DisplayName));
}
I want to write unit tests for this method. How can I fake ValidationContext using FakeItEasy to make this testable?
Any help on this much appreciated
Thanks