public string this[string columnName] { get { if (columnName == "Username") { StringValidationRule rule = new StringValidationRule { FieldName = columnName }; ValidationResult result = rule.Validate(Username, CultureInfo.InvariantCulture); return((string)result.ErrorContent); } if (columnName == "ServerAddress") { return(String.IsNullOrWhiteSpace(ServerAddress) ? "Server address cannot be empty" : null); } if (columnName == "ServerPort") { NumericValidationRule rule = new NumericValidationRule { Minimum = 1024, Maximum = 65535, PositiveOnly = true }; ValidationResult result = rule.Validate(ServerPort, CultureInfo.InvariantCulture); return((string)result.ErrorContent); } return(null); } }
public void wrong_values_result_in_errors(object value, int maxLength, int minLength) { var sut = new StringValidationRule(); sut.ErrorIfNull = true; sut.PropertyName = "Test"; sut.MaxLength = maxLength; sut.MinLength = minLength; var result = sut.Validate(value, out var errorText); Assert.IsFalse(result, "Validation error for null should be reported."); Assert.IsTrue(errorText.Contains(sut.PropertyName), "Error text was: " + errorText); }
public string this[string columnName] { get { if (columnName == "Team") { StringValidationRule rule = new StringValidationRule { FieldName = columnName, NullAccepted = true }; ValidationResult result = rule.Validate(Team, CultureInfo.InvariantCulture); return((string)result.ErrorContent); } return(null); } }