public void Add_NegativeNumber_ReturnDecimal(string number, decimal expected) { decimal?result = DecimalValidator.Validate(number); Assert.IsNotNull(result); Assert.AreEqual(expected, (decimal)result); }
public void Decimal_Validator_Test() { var sut = new DecimalValidator(); var col1 = new ColumnTypeInfo() { AllowNull = true, Precision = 3, Scale = 1 }; var col2 = new ColumnTypeInfo() { AllowNull = false, Precision = 3, Scale = 1 }; Assert_Valid(sut.Validate(new ColumnTypeInfo() { Precision = 5, Scale = 2 }, 123.45)); Assert_Valid(sut.Validate(new ColumnTypeInfo() { Precision = 9, Scale = 4 }, 12345.6789)); Assert_Invalid(sut.Validate(col1, "Foo")); Assert_Invalid(sut.Validate(col1, 12345.6789)); Assert_Invalid_Replaced(sut.Validate(col2, "Foo"), 0d); Assert_Invalid_Replaced(sut.Validate(col2, 12345.6789), 0d); Assert_Invalid_Replaced(sut.Validate(col2, DBNull.Value), 0d); }
public void Add_NumberWithThousandSeparators_ReturnDecimal(string number, decimal expected) { decimal?result = DecimalValidator.Validate(number); Assert.IsNotNull(result); Assert.AreEqual(expected, (decimal)result); }
public void DecimalValidator_IsValid_AllowsStringWithOnlyNumbers() { var input = "99"; var result = DecimalValidator.IsValid(input); Assert.IsTrue(result); }
public void DecimalValidator_IsValid_AllowsStringWithPeriod() { var input = "10.44"; var result = DecimalValidator.IsValid(input); Assert.IsTrue(result); }
public void DecimalValidatorValidTest() { DecimalValidator dv = new DecimalValidator(); String s = "5,0"; CultureInfo ci = new CultureInfo("pl-PL", false); Assert.AreEqual(dv.Validate(s, ci), ValidationResult.ValidResult); }
public void Init() { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); validator = new DecimalValidator(); validator.Initialize(new CachedValidationRegistry(), typeof(TestTarget).GetProperty("TargetField")); target = new TestTarget(); }
private static void NumericOnly_OnPaste(object sender, DataObjectPastingEventArgs e) { var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string; if (string.IsNullOrEmpty(text) || !DecimalValidator.IsValid(text)) { e.CancelCommand(); } }
public void DecimalValidatorInValidTest() { DecimalValidator dv = new DecimalValidator(); String s = "-5,0"; CultureInfo ci = new CultureInfo("pl-PL", false); Assert.AreEqual(dv.Validate(s, ci), new ValidationResult(false, $"Please enter positive decimal ")); }
public void ValidateDecimalToBeValue() { // Given var validator = new DecimalValidator(42); // When validator.Be(42); // Then Assert.True(true); }
public void ValidateDecimalToBeGreaterThanOrEqualToSmallerValue() { // Given var validator = new DecimalValidator(42); // When validator.BeGreaterThanOrEqualTo(13); // Then Assert.True(true); }
public void ValidateDecimalToBeBetweenValues() { // Given var validator = new DecimalValidator(42); // When validator.BeBetween(13, 130); // Then Assert.True(true); }
public void ValidateDecimalToBeApproximatelyValue() { // Given var validator = new DecimalValidator(42.12345m); // When validator.BeApproximately(42.123m, 0.1m); // Then Assert.True(true); }
public void ValidateDecimalToBePositive() { // Given var validator = new DecimalValidator(0); // When validator.BePositive(); // Then Assert.True(true); }
public void ValidateDecimalToBeOneOfExpectedValues() { // Given var validator = new DecimalValidator(42); // When validator.BeOneOf(new decimal[] { 10, 42 }); // Then Assert.True(true); }
public void ValidateDecimalToBeLessThanOrEqualToEqualValue() { // Given var validator = new DecimalValidator(42); // When validator.BeLessThanOrEqualTo(42); // Then Assert.True(true); }
protected void SubmitDataAction(object sender, EventArgs e) { string numberAsWords = String.Empty; decimal?decimalNumber = DecimalValidator.Validate(NumberTextBox.Text); if (NameValidator.NameValidate(NameTextBox.Text)) { try { Name.Text = Server.HtmlEncode(NameTextBox.Text); } catch { WordNumberForm.Visible = false; ErrorMessage.Visible = true; } } else { ValidationErrorName.Visible = true; ValidationErrorName.Text = "Please enter a valid Name."; } if ((decimalNumber != null && decimalNumber < 1000000000000000000m)) { decimal number = (decimal)decimalNumber; try { numberAsWords = NumberToWordsConverter.Convert(number); Number.Text = numberAsWords; WordNumberForm.Visible = false; SuccessMessage.Visible = true; ValidationSuccess.Visible = true; ValidationSuccess.Text = "Number Converted Successfully."; } catch { WordNumberForm.Visible = false; ErrorMessage.Visible = true; } } else { ValidationErrorNumber.Visible = true; ValidationErrorNumber.Text = "Please enter a valid Number."; } }
public void ValidateDecimalToBeOneOfViolated() { // Given var validator = new DecimalValidator(42); // When var exception = Assert.Throws <XunitException>(() => validator.BeOneOf(new decimal[] { 13, 39 }, because: "that's the bottom line")); // Then Assert.NotNull(exception); var rn = Environment.NewLine; Assert.Equal( $"{rn}validator{rn}is \"42\"{rn}but was expected to be one of the following values: \"13\", \"39\"{rn}because that's the bottom line", exception.UserMessage); }
public void ValidateDecimalToBeBetweenValuesMinimumViolated() { // Given var validator = new DecimalValidator(42); // When var exception = Assert.Throws <XunitException>(() => validator.BeBetween(65, 130, "that's the bottom line")); // Then Assert.NotNull(exception); var rn = Environment.NewLine; Assert.Equal( $"{rn}validator{rn}is \"42\"{rn}but was expected to be between \"65\" and \"130\"{rn}because that's the bottom line", exception.UserMessage); }
public void ValidateDecimalToBeApproximatelyValueViolated() { // Given var validator = new DecimalValidator(42.12345m); // When var exception = Assert.Throws <XunitException>(() => validator.BeApproximately(42m, 0.01m, "that's the bottom line")); // Then Assert.NotNull(exception); var rn = Environment.NewLine; Assert.Equal( $"{rn}validator{rn}is \"42,12345\"{rn}but was expected to be approximately \"42\" (+/- 0,01){rn}because that's the bottom line", exception.UserMessage); }
public void ValidateDecimalToBePositiveViolated() { // Given var validator = new DecimalValidator(-42); // When var exception = Assert.Throws <XunitException>(() => validator.BePositive(because: "that's the bottom line")); // Then Assert.NotNull(exception); var rn = Environment.NewLine; Assert.Equal( $"{rn}validator{rn}is \"-42\"{rn}but was expected to have a positive value{rn}because that's the bottom line", exception.UserMessage); }
public void ValidateDecimalToBeLessThanOrEqualToValueViolated() { // Given var validator = new DecimalValidator(42); // When var exception = Assert.Throws <XunitException>(() => validator.BeLessThanOrEqualTo(13, "that's the bottom line")); // Then Assert.NotNull(exception); var rn = Environment.NewLine; Assert.Equal( $"{rn}validator{rn}is \"42\"{rn}but was expected to be less than or equal to \"13\"{rn}because that's the bottom line", exception.UserMessage); }
private void NumericOnly_OnPreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = string.IsNullOrEmpty(e.Text) || !DecimalValidator.IsValid(e.Text); }
public void Add_String_ReturnNull(string number, decimal?expected) { decimal?result = DecimalValidator.Validate(number); Assert.AreEqual(expected, result); }