public void Validate_Exclusive() { IntegerValidator v = new IntegerValidator(5000, 10000, true); v.Validate(1000); v.Validate(15000); }
public void Validate_Inclusive() { IntegerValidator v = new IntegerValidator(5000, 10000, false); v.Validate(5000); v.Validate(10000); }
public void Integer_Validator_Test() { var sut = new IntegerValidator(); var col1 = new ColumnTypeInfo() { AllowNull = true }; var col2 = new ColumnTypeInfo() { AllowNull = false }; Assert_Valid(sut.Validate(col1, "10")); Assert_Valid(sut.Validate(col1, "-10")); Assert_Valid(sut.Validate(col1, DBNull.Value)); Assert_Valid(sut.Validate(col1, null)); Assert_Invalid(sut.Validate(col1, "Foo")); Assert_Invalid(sut.Validate(col1, "10.1")); Assert_Invalid_Replaced(sut.Validate(col2, "Foo"), 0); Assert_Invalid_Replaced(sut.Validate(col2, "10.1"), 0); Assert_Invalid_Replaced(sut.Validate(col2, DBNull.Value), 0); }
public void ShouldReturnTrueForIntAndHasToBeEqualToInputDate() { IntegerValidator integerValidator = new IntegerValidator(testValueInt); Assert.IsTrue(integerValidator.Validate()); Assert.AreEqual(testValueInt, integerValidator.Digit); }
public void ShouldReturnFalseForIncorrectStringAndHasToBeEqualZero() { IntegerValidator integerValidator = new IntegerValidator(incorrectTestString); Assert.IsFalse(integerValidator.Validate()); Assert.AreEqual(0, integerValidator.Digit); }
public void ShouldReturnTrueForCorrectStringAndHasToBeEqualToInputDate() { IntegerValidator integerValidator = new IntegerValidator(correctTestString); Assert.IsTrue(integerValidator.Validate()); Assert.AreEqual(testValueDouble, integerValidator.Digit); }
public void ShouldReturnFalseForEmptyObjectAndHasToBeEqualZero() { object emptyObject = new object(); IntegerValidator integerValidator = new IntegerValidator(incorrectTestString); Assert.IsFalse(integerValidator.Validate()); Assert.AreEqual(0, integerValidator.Digit); }
public void Validate_Resolution() { IntegerValidator v = new IntegerValidator(20000, 50000, false, 3000); AssertExtensions.Throws <ArgumentException>(null, () => v.Validate(40000)); }
public void Validate_Resolution() { IntegerValidator v = new IntegerValidator(20000, 50000, false, 3000); v.Validate(40000); }
private static void ValidateInteger(IntegerValidator integerValidator, int valuetoValidate) { Console.Write("Validating integer value of {0}: ", valuetoValidate); try { integerValidator.Validate(valuetoValidate); Console.WriteLine("Validated."); } catch (ArgumentException e) { Console.WriteLine("Failed validation. Message: {0}", e.Message.ToString()); } }
public void ErrorMessage_MinFormat_AreEqual() { string column = "測試欄位"; IntegerValidator validator = IntegerValidator.CreateMinValue(column, "0", 1); validator.Validate(); Assert.AreEqual( string.Format(validator.MinValueErrorMessageFormat, column, 1), validator.ErrorMessage ); }
public void ErrorMessage_BasicFormat_AreEqual() { string column = "測試欄位"; IntegerValidator validator = new IntegerValidator(column, "error"); validator.Validate(); Assert.AreEqual( string.Format(validator.DefaultErrorMessageFormat, column), validator.ErrorMessage ); }
public void ErrorMessage_CustomFormat_AreEqual() { string column = "測試欄位"; IntegerValidator validator = new IntegerValidator(column, "error", "{0}Integer"); validator.Validate(); Assert.AreEqual( string.Format(validator.CustomErrorMessageFormat, column), validator.ErrorMessage ); }
public static void CheckTimezone(int timezone) { var timezoneValidate = new IntegerValidator(DomainConstraints.MinTimeZone, DomainConstraints.MaxTimeZone, false); try { timezoneValidate.Validate(timezone); } catch (ArgumentException) { throw new ArgumentOutOfRangeException(); } }
public void ErrorMessage_RangeCustomFormat_AreEqual() { string column = "測試欄位"; IntegerValidator validator = new IntegerValidator(column, "0", 1, 2, customRangeMessageFormat: "{0}_{1}_{2}Integer"); validator.Validate(); Assert.AreEqual( string.Format(validator.CustomRangeMessageFormat, column, 1, 2), validator.ErrorMessage ); }
public void ErrorMessage_RangeFormat_AreEqual() { string column = "測試欄位"; IntegerValidator validator = new IntegerValidator(column, "0", 1, 2); validator.Validate(); Assert.AreEqual( string.Format(validator.RangeErrorMessageFormat, column, 1, 2), validator.ErrorMessage ); }
public void ErrorMessage_MaxCustomFormat_AreEqual() { string column = "測試欄位"; IntegerValidator validator = IntegerValidator.CreateMaxValue(column, "1", 0, customRangeMessageFormat: "{0}_{1}Integer"); validator.Validate(); Assert.AreEqual( string.Format(validator.CustomRangeMessageFormat, column, 0), validator.ErrorMessage ); }
/// <summary> /// Validates all the items present in the game configuration file, setting them to a default value if /// possible when the user input values are not valid. /// </summary> private void ValidateConnectionFields() { // Vnc info validation IValidator <string> ipValidator = new TextValidator(_ipValidation); IValidator <string> textValidator = new TextValidator(); IValidator <int> vncPortValidator = new IntegerValidator(MinPortNumberAccepted, MaxPortNumberAccepted, 5900); connectionConfig.vncConnectionInfo.targetHost = ipValidator.Validate(connectionConfig.vncConnectionInfo.targetHost); connectionConfig.vncConnectionInfo.port = vncPortValidator.Validate(connectionConfig.vncConnectionInfo.port); connectionConfig.vncConnectionInfo.vncServerPassword = textValidator.Validate(connectionConfig.vncConnectionInfo.vncServerPassword); // Ssh info validation IValidator <int> sshPortValidator = new IntegerValidator(MinPortNumberAccepted, MaxPortNumberAccepted, 22); connectionConfig.sshConnectionInfo.username = textValidator.Validate(connectionConfig.sshConnectionInfo.username); connectionConfig.sshConnectionInfo.password = textValidator.Validate(connectionConfig.sshConnectionInfo.password); connectionConfig.sshConnectionInfo.port = sshPortValidator.Validate(connectionConfig.sshConnectionInfo.port); connectionConfig.sshConnectionInfo.publicKeyAuth.path = textValidator.Validate(connectionConfig.sshConnectionInfo.publicKeyAuth.path); connectionConfig.sshConnectionInfo.publicKeyAuth.passPhrase = textValidator.Validate(connectionConfig.sshConnectionInfo.publicKeyAuth.passPhrase); }
public void Validate_Format_AreEqual(string value, bool isValid) { IntegerValidator validator = new IntegerValidator("", value); Assert.AreEqual(validator.Validate(), isValid); }
/// <summary> /// The method validates whether a supplied object is a valid integer. /// </summary> /// <param name="objectToValidate">An object to be valdiated whether it is an integer.</param> /// <returns>True - if object is valid, false - if object is invalid.</returns> public static bool IsInteger(object objectToValidate) { Validator validator = new IntegerValidator(objectToValidate); return(validator.Validate()); }
public void Validate_Max_AreEqual(string value, long max, bool isValid) { IntegerValidator validator = IntegerValidator.CreateMaxValue("", value, max); Assert.AreEqual(validator.Validate(), isValid); }
public void Validate_inRange() { IntegerValidator v = new IntegerValidator(5000, 10000); v.Validate(7000); }
public void Validate_Range_AreEqual(string value, long min, long max, bool isValid) { IntegerValidator validator = new IntegerValidator("", value, min, max); Assert.AreEqual(validator.Validate(), isValid); }
public void Validate_Min_AreEqual(string value, long min, bool isValid) { IntegerValidator validator = IntegerValidator.CreateMinValue("", value, min); Assert.AreEqual(validator.Validate(), isValid); }
public void Validate_Exclusive_fail3() { IntegerValidator v = new IntegerValidator(5000, 10000, true); AssertExtensions.Throws <ArgumentException>(null, () => v.Validate(7000)); }
public void Validate_Exclusive_fail2() { IntegerValidator v = new IntegerValidator(5000, 10000, true); Assert.Throws <ArgumentException>(() => v.Validate(10000)); }