public StringValidatorBuilder <T> ShouldHaveNotEmptyValidator() { const EValidatorRule validationRule = EValidatorRule.NotEmptyValidator; ShouldHaveValidationErrorFor(CreateModel(string.Empty), validationRule); ShouldNotHaveValidationErrorFor(CreateModel("Test"), validationRule); return(this); }
public IntValidatorBuilder <T> ShouldHaveGreaterThanValidator(int value) { const EValidatorRule validationRule = EValidatorRule.GreaterThanValidator; ShouldHaveValidationErrorFor(CreateModel(value - 1), validationRule); ShouldHaveValidationErrorFor(CreateModel(value), validationRule); ShouldNotHaveValidationErrorFor(CreateModel(value + 10), validationRule); return(this); }
public StringValidatorBuilder <T> ShouldHaveMaxLengthValidator(int length) { const EValidatorRule validationRule = EValidatorRule.MaximumLengthValidator; ShouldHaveValidationErrorFor(CreateModel(new string('t', length + 1)), validationRule); ShouldNotHaveValidationErrorFor(CreateModel(new string('t', length)), validationRule); ShouldNotHaveValidationErrorFor(CreateModel(new string('t', length - 1)), validationRule); return(this); }
protected void ShouldNotHaveValidationErrorFor(T objectToTest, EValidatorRule validatorRule) { var validationResults = validator.TestValidate(objectToTest); if (validationResults.Errors.Any(x => x.ErrorCode.Equals(validatorRule.ToString(), StringComparison.InvariantCultureIgnoreCase))) { throw new ValidationTestException($"{validatorRule} failed"); } }
public StringValidatorBuilder <T> ShouldHaveEmailValidator() { const EValidatorRule validationRule = EValidatorRule.EmailValidator; foreach (var email in EmailDictionary.ValidEmails) { ShouldNotHaveValidationErrorFor(CreateModel(email), validationRule); } foreach (var email in EmailDictionary.InvalidEmails) { ShouldHaveValidationErrorFor(CreateModel(email), validationRule); } return(this); }
public DateValidatorBuilder <T> ShouldHaveNotEmptyValidator() { const EValidatorRule validationRule = EValidatorRule.NotEmptyValidator; ShouldNotHaveValidationErrorFor(CreateModel(DateTime.Now), validationRule); ShouldHaveValidationErrorFor(CreateModel(default), validationRule);