public void RegularExpressionValidator_NotValidTheory(string s, string pattern) { var lessThanOrEqualToValidator = new RegularExpressionValidator <TestValidatableObject>(_ => pattern, ValidationMessageType.Error); var context = new ValidationContext <TestValidatableObject, string>(null, nameof(TestValidatableObject.Number), null, s); var validationMessage = lessThanOrEqualToValidator.ValidateProperty(context).FirstOrDefault(); AssertValidationMessage.NotEmptyMessage(validationMessage); }