コード例 #1
0
        public void Add_NegativeNumber_ReturnDecimal(string number, decimal expected)
        {
            decimal?result = DecimalValidator.Validate(number);

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, (decimal)result);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Add_NumberWithThousandSeparators_ReturnDecimal(string number, decimal expected)
        {
            decimal?result = DecimalValidator.Validate(number);

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, (decimal)result);
        }
コード例 #4
0
        public void DecimalValidator_IsValid_AllowsStringWithOnlyNumbers()
        {
            var input = "99";

            var result = DecimalValidator.IsValid(input);

            Assert.IsTrue(result);
        }
コード例 #5
0
        public void DecimalValidator_IsValid_AllowsStringWithPeriod()
        {
            var input = "10.44";

            var result = DecimalValidator.IsValid(input);

            Assert.IsTrue(result);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
		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();
		}
コード例 #8
0
        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();
            }
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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 "));
        }
コード例 #11
0
        public void ValidateDecimalToBeValue()
        {
            // Given
            var validator = new DecimalValidator(42);

            // When
            validator.Be(42);

            // Then
            Assert.True(true);
        }
コード例 #12
0
        public void ValidateDecimalToBeGreaterThanOrEqualToSmallerValue()
        {
            // Given
            var validator = new DecimalValidator(42);

            // When
            validator.BeGreaterThanOrEqualTo(13);

            // Then
            Assert.True(true);
        }
コード例 #13
0
        public void ValidateDecimalToBeBetweenValues()
        {
            // Given
            var validator = new DecimalValidator(42);

            // When
            validator.BeBetween(13, 130);

            // Then
            Assert.True(true);
        }
コード例 #14
0
        public void ValidateDecimalToBeApproximatelyValue()
        {
            // Given
            var validator = new DecimalValidator(42.12345m);

            // When
            validator.BeApproximately(42.123m, 0.1m);

            // Then
            Assert.True(true);
        }
コード例 #15
0
        public void ValidateDecimalToBePositive()
        {
            // Given
            var validator = new DecimalValidator(0);

            // When
            validator.BePositive();

            // Then
            Assert.True(true);
        }
コード例 #16
0
        public void ValidateDecimalToBeOneOfExpectedValues()
        {
            // Given
            var validator = new DecimalValidator(42);

            // When
            validator.BeOneOf(new decimal[] { 10, 42 });

            // Then
            Assert.True(true);
        }
コード例 #17
0
        public void ValidateDecimalToBeLessThanOrEqualToEqualValue()
        {
            // Given
            var validator = new DecimalValidator(42);

            // When
            validator.BeLessThanOrEqualTo(42);

            // Then
            Assert.True(true);
        }
コード例 #18
0
        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.";
            }
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
 private void NumericOnly_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
 {
     e.Handled = string.IsNullOrEmpty(e.Text) || !DecimalValidator.IsValid(e.Text);
 }
コード例 #25
0
        public void Add_String_ReturnNull(string number, decimal?expected)
        {
            decimal?result = DecimalValidator.Validate(number);

            Assert.AreEqual(expected, result);
        }