Esempio n. 1
0
        public void NegativeNumber_When_NumberValidatorIsOnlyPositive()
        {
            var numberValidator = new NumberValidator(5, 1, true);

            numberValidator.IsValidNumber("1").Should().BeTrue();
            numberValidator.IsValidNumber("-1").Should().BeFalse();
        }
Esempio n. 2
0
        public void MinusSymbolsIncludeInPrecisionValue()
        {
            var numberValidator = new NumberValidator(4, 2, false);

            numberValidator.IsValidNumber("-1.23").Should().BeTrue();
            numberValidator.IsValidNumber("-12.23").Should().BeFalse();
        }
Esempio n. 3
0
        public void DefaultNumberValidatorIsNotOnlyPositive()
        {
            var numberValidator = new NumberValidator(5, 1);

            numberValidator.IsValidNumber("1").Should().BeTrue();
            numberValidator.IsValidNumber("-1").Should().BeTrue();
        }
Esempio n. 4
0
        public void CheckingThatClassNotStatic(int precision1, int scale1, bool onlyPositive1, int precision2, int scale2, bool onlyPositive2, string number)
        {
            var val1 = new NumberValidator(precision1, scale1, onlyPositive1);
            var val2 = new NumberValidator(precision2, scale2, onlyPositive2);

            val1.IsValidNumber(number).Should().BeFalse();
        }
Esempio n. 5
0
        public void IsValidNumber_ReturnResult_When(
            string number, int precision, int scale, bool onlyPositive, bool testResult)
        {
            var numberValidator = new NumberValidator(precision, scale, onlyPositive);

            numberValidator.IsValidNumber(number).Should().Be(testResult);
        }
Esempio n. 6
0
        public void IsValid_WorksCorrect_WithMoreThanOneValidatorCreated()
        {
            var validator1 = new NumberValidator(2, 1, true);
            var validator2 = new NumberValidator(10, 5);

            validator2.IsValidNumber("-0.22").Should().BeTrue();
        }
Esempio n. 7
0
        public void IsValid_ReturnsTrue_OnMoreThanOneNumbers()
        {
            var validator = new NumberValidator(10, 5);

            validator.IsValidNumber("0.2").Should().BeTrue();
            validator.IsValidNumber("-0.2").Should().BeTrue();
        }
Esempio n. 8
0
        public void IsValidNumber_ReturnTrue(
            int precision, int scale, bool onlyPositive, string value)
        {
            var numberValidator = new NumberValidator(precision, scale, onlyPositive);

            numberValidator.IsValidNumber(value).Should().BeTrue();
        }
                public void ReturnFalse_WhenInputIsNegative()
                {
                    var validator = new NumberValidator(6, 0, true);
                    Func <string, bool> checker = (number) => validator.IsValidNumber(number);

                    checker("-1").Should().BeFalse();
                }
Esempio n. 10
0
        public void ScaleDefaultValueIsZero()
        {
            var numberValidator = new NumberValidator(5);

            numberValidator.IsValidNumber("1").Should().BeTrue();
            numberValidator.IsValidNumber("1.0").Should().BeFalse();
        }
        public void IsValidNumber(int precision, int scale, bool onlyPositive, string value, bool expectedResult)
        {
            var validator    = new NumberValidator(precision, scale, onlyPositive);
            var actualResult = validator.IsValidNumber(value);

            actualResult.Should().Be(expectedResult);
        }
Esempio n. 12
0
            public void NonZeroPrecision_NonZeroScale_NotOnlyPositive_ReturnFalse_When(string value)
            {
                var numberValidator = new NumberValidator(3, 2);

                numberValidator.IsValidNumber(value)
                .Should()
                .BeFalse();
            }
Esempio n. 13
0
        public void IsValidNumber_NegativeExcluded_ReturnsFalseOnNegative(int precision, int scale, string value)
        {
            var validator = new NumberValidator(precision, scale, true);

            validator.IsValidNumber(value)
            .Should()
            .BeFalse();
        }
Esempio n. 14
0
        public void IsValidNumber_NotValidNumber_ReturnsFalse(int precision, int scale, string value)
        {
            var validator = new NumberValidator(precision, scale, false);

            validator.IsValidNumber(value)
            .Should()
            .BeFalse();
        }
Esempio n. 15
0
        public void IsValidNumber_WithNegative_ReturnsTrueOnNegative(int precision, int scale, string value)
        {
            var validator = new NumberValidator(precision, scale, false);

            validator.IsValidNumber(value)
            .Should()
            .BeTrue();
        }
Esempio n. 16
0
        public void IsValidNumber_CorrectNumber_ReturnsTrue(int precision, int scale, string value)
        {
            var validator = new NumberValidator(precision, scale, true);

            validator.IsValidNumber(value)
            .Should()
            .BeTrue();
        }
Esempio n. 17
0
        public void IsValidNumber_ShouldBeFalse(int precision, int scale, bool onlyPositive, string numberLine)
        {
            var validator = new NumberValidator(precision, scale, onlyPositive);

            var isValidNumber = validator.IsValidNumber(numberLine);

            isValidNumber.Should().BeFalse();
        }
Esempio n. 18
0
        public void IsValidNumber_InvalidNumberFormat_ReturnsFalse(string value)
        {
            var validator = new NumberValidator(7, 4);

            validator.IsValidNumber(value)
            .Should()
            .BeFalse();
        }
Esempio n. 19
0
        public void IsValidNumber_ShouldBeFalse_IfFormat(
            string number, string message, int precision = 3, int scale = 2, bool onlyPositive = false)
        {
            var validator    = new NumberValidator(precision, scale, onlyPositive);
            var validatorStr = $"{(onlyPositive?"positive-only ":"")}N({precision},{scale})";

            validator.IsValidNumber(number).Should().BeFalse(
                $"{message} (on {validatorStr} validator for \"{number}\")");
        }
Esempio n. 20
0
        public bool IsValidNumber(string value, bool onlyPositive = false)
        {
            var precision = 6;
            var scale     = 4;
            var res       = new NumberValidator(precision, scale, onlyPositive).
                            IsValidNumber(value);

            return(res);
        }
        public void IsValidNumber_ReturnsTrueOnNewValidator_WhenNewValidatorAcceptsNumberButOldDoesNot()
        {
            var oldValidator = new NumberValidator(3, 1);
            var newValidator = new NumberValidator(100, 99);
            var number       = "1111.0";

            newValidator.IsValidNumber(number)
            .Should()
            .BeTrue();
        }
        public void IsValidNumber_ReturnsTrue_WhenValidatorGetsCorrectNumber(String number,
                                                                             int precision,
                                                                             int scale,
                                                                             bool onlyPositive)
        {
            var validator = new NumberValidator(precision, scale, onlyPositive);

            validator.IsValidNumber(number)
            .Should()
            .BeTrue();
        }
        public void IsValidNumber_ReturnsFalse_WhenValidatorGetsWrongNumber(String number,
                                                                            int precision,
                                                                            int scale,
                                                                            bool onlyPositive)
        {
            var validator = new NumberValidator(precision, scale, true);

            validator
            .IsValidNumber(number)
            .Should()
            .BeFalse();
        }
Esempio n. 24
0
        public void NumberValidationMultiTest()
        {
            Assert.Multiple(() =>
            {
                Assert.IsTrue(new NumberValidator(4, 2, true).IsValidNumber("+1.23"),
                              "IsValidNumber_NumberWith3DigitsAndInsignificantSign_True");


                var validator = new NumberValidator(17, 2, true);

                Assert.IsFalse(validator.IsValidNumber(string.Empty), "IsValidNumber_EmptyString_False");
                Assert.IsFalse(validator.IsValidNumber(null), "IsValidNumber_Null_False");
                Assert.IsFalse(validator.IsValidNumber("     "), "IsValidNumber_Spaces_False");
                Assert.True(validator.IsValidNumber("0"), "IsValidNumber_NumberWithoutFractionalPart_True");
                Assert.IsFalse(validator.IsValidNumber("0.000"), "IsValidNumber_FractionalPartMoreThanScale_False");

                Assert.IsTrue(validator.IsValidNumber("0.0"), "IsValidNumber_FractionalPartIs0_True");
                Assert.IsTrue(validator.IsValidNumber("1"),
                              "IsValidNumber_PositiveIntegerWithOnlyPositiveValidator_True");
                Assert.IsTrue(new NumberValidator(4, 1, false).IsValidNumber("1"),
                              "IsValidNumber_PositiveIntegerWhenValidatorNotOnlyPositive_True");
                Assert.IsFalse(validator.IsValidNumber("-1"),
                               "IsValidNumber_NegativeIntegerWhenValidatorOnlyPositive_False");
                Assert.IsFalse(validator.IsValidNumber(".1"), "IsValidNumber_BeginWithDot_False");
                Assert.IsFalse(validator.IsValidNumber("1."),
                               "IsValidNumber_NumberWithDotButWithoutFractionalPart_False");
                Assert.IsTrue(validator.IsValidNumber("1,2"), "IsValidNumber_NumberWithComma_True");
                Assert.IsTrue(validator.IsValidNumber("౦౧౨"), "IsValidNumber_TeluguNumbers_True");
                Assert.IsTrue(validator.IsValidNumber("๑๒๓"), "IsValidNumber_ThaiNumbers_True");
                Assert.IsTrue(validator.IsValidNumber("٦٧"), "IsValidNumber_ArabicNumbers_True");
                Assert.IsTrue(validator.IsValidNumber("१०"), "IsValidNumber_DevanagariNumbers_True");

                validator = new NumberValidator(3, 2, true);


                Assert.IsFalse(validator.IsValidNumber("+0.00"),
                               "IsValidNumber_DigitsAndSignLengthMoreThanPrecision_False");

                Assert.IsFalse(validator.IsValidNumber("-0.00"),
                               "IsValidNumber_DigitsAndSignLengthMoreThanPrecision_False");

                Assert.IsFalse(validator.IsValidNumber("00.00"), "IsValidNumber_InsignificantZerosWithDot_False");
                Assert.IsFalse(validator.IsValidNumber("-a.sd"), "IsValidNumber_LettersWithSignAndDot_False");
                Assert.IsFalse(validator.IsValidNumber("1.a"), "IsValidNumber_DigitWithDotAndLetter_False");
                Assert.IsFalse(validator.IsValidNumber(" 1"), "IsValidNumber_NumberWithSpaceInBegin_False");
                Assert.IsFalse(validator.IsValidNumber("1 "), "IsValidNumber_SpaceAfterNumber_False");
                Assert.IsFalse(validator.IsValidNumber("-+1"), "IsValidNumber_PlusAndMinusBeforeNumber_False");
            });
        }
Esempio n. 25
0
        public void FluentTests()
        {
            new NumberValidator(3, 2).IsValidNumber("-1.1").Should().BeTrue();
            new NumberValidator(3, 2).IsValidNumber("-1.11").Should().BeFalse();
            NumberValidator nv = new NumberValidator(5, 2, true);

            nv.IsValidNumber("1.1").Should().BeTrue();
            nv.IsValidNumber(" 1.1").Should().BeFalse();
            nv.IsValidNumber(".").Should().BeFalse();
            nv.IsValidNumber("1.2.4").Should().BeFalse();
            nv.IsValidNumber("1..2").Should().BeFalse();
            nv.IsValidNumber("1.").Should().BeFalse();
            nv.IsValidNumber("").Should().BeFalse();
            nv.IsValidNumber("null").Should().BeFalse();
            nv.IsValidNumber("a.sd").Should().BeFalse();
            nv.IsValidNumber("000.00").Should().BeTrue();
            nv.IsValidNumber("1,33").Should().BeTrue();
            nv.IsValidNumber("1.333").Should().BeFalse();
            nv.IsValidNumber("1111.11").Should().BeFalse();
            nv.IsValidNumber("+661.98").Should().BeFalse();
            nv.IsValidNumber("-2").Should().BeFalse();
        }
Esempio n. 26
0
        public void IsValidNumber_ValidValues_IsTrue(int precision, int scale, bool onlyPositive, string value)
        {
            var isValidNumber = new NumberValidator(precision, scale, onlyPositive).IsValidNumber(value);

            isValidNumber.Should().BeTrue();
        }
Esempio n. 27
0
        public void IsValidNumber_BeFalse_WhenInvalidValue(string number, int precision, int scale, bool onlyPositive)
        {
            var numberValidator = new NumberValidator(precision, scale, onlyPositive);

            numberValidator.IsValidNumber(number).Should().BeFalse();
        }
Esempio n. 28
0
        public void IsValid_ReturnsFalse_OnWrongNumber(int precision, int scale, bool onlyPositive, string value)
        {
            var validator = new NumberValidator(precision, scale, onlyPositive);

            validator.IsValidNumber(value).Should().BeFalse();
        }
Esempio n. 29
0
 public void InitEvery()
 {
     defaultNumberValidator = new NumberValidator(int.MaxValue, int.MaxValue - 1, false);
 }
Esempio n. 30
0
        public void ShouldBeFalse_WhenNumberIsInvalid(int precision, int scale, bool onlyPositive, string number)
        {
            var result = new NumberValidator(precision, scale, onlyPositive).IsValidNumber(number);

            result.Should().BeFalse();
        }