Esempio n. 1
0
        public void Validate_WithLetters_ReturnFalse()
        {
            IntValidator validator = new IntValidator();

            bool result = validator.Validate("ABC");

            Assert.AreEqual(false, result);
        }
Esempio n. 2
0
        public void Validate_WithFloat_ReturnFalse()
        {
            IntValidator validator = new IntValidator();

            bool result = validator.Validate("12.5");

            Assert.AreEqual(false, result);
        }
Esempio n. 3
0
        public void Validate_WithOverFlowNegative_ReturnFalse()
        {
            IntValidator validator = new IntValidator();

            bool result = validator.Validate("-9999999999999999999999");

            Assert.AreEqual(false, result);
        }
Esempio n. 4
0
        public void Validate_WithInteger_ReturnTrue()
        {
            IntValidator validator = new IntValidator();

            bool result = validator.Validate("1");

            Assert.AreEqual(true, result);
        }
Esempio n. 5
0
        public void Validate_WithNegativeNumber_ReturnFalse()
        {
            IntValidator validator = new IntValidator();

            bool result = validator.Validate("-1");

            Assert.AreEqual(false, result);
        }
Esempio n. 6
0
        public void Validate_Empty_ReturnFalse()
        {
            IntValidator validator = new IntValidator();

            bool result = validator.Validate("");

            Assert.AreEqual(false, result);
        }
Esempio n. 7
0
        public static void TestIntCalculator()
        {
            Console.Clear();
            ICalculator <int>      calc = new IntCalculator();
            INumberValidator <int> validator = new IntValidator();
            int value1, value2, result;

            while (true)
            {
                try
                {
                    Console.Write("Введите операцию (+ - * /): ");
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        return;
                    }
                    char operation = key.KeyChar;
                    if (operations.IndexOf(operation) == -1)
                    {
                        Console.WriteLine("\r\nА вот и не правильно");
                        continue;
                    }
                    Console.Write("\r\nВведите 2 целых числа разделенных пробелом: ");
                    if (!validator.ValidateTwoNumbers(Console.ReadLine(), out value1, out value2))
                    {
                        Console.WriteLine("Неверный ввод. Придется повторить");
                        continue;
                    }
                    switch (operation)
                    {
                    case '+':
                        result = calc.Add(value1, value2);
                        break;

                    case '-':
                        result = calc.Add(value1, value2);
                        break;

                    case '*':
                        result = calc.Multiply(value1, value2);
                        break;

                    case '/':
                        result = calc.Divide(value1, value2);
                        break;

                    default:
                        continue;
                    }
                    Console.WriteLine($"{ value1}{ operation}{ value2}={ result}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Exception {e.GetType().Name}: {e.Message}");
                }
            }
        }
Esempio n. 8
0
        public void IsHigherThan_ValueIsLower_ThrowsException()
        {
            IntValidator validator = new IntValidator("test", 1);

            ExceptionAssert.ThrowsHigherThanValidationException("test", 2, () =>
            {
                validator.IsHigherThan(2);
            });
        }
Esempio n. 9
0
        public void IsLowerThan_ValueEqual_ThrowsException()
        {
            IntValidator validator = new IntValidator("test", 1);

            ExceptionAssert.ThrowsLowerThanValidationException("test", 1, () =>
            {
                validator.IsLowerThan(1);
            });
        }
Esempio n. 10
0
        public async Task Inherited_Basic()
        {
            var iv = new IntValidator();
            var vr = await iv.ValidateAsync(8);

            Assert.IsTrue(vr.HasError);
            Assert.AreEqual(1, vr.Messages.Count);
            Assert.AreEqual("Count must be greater than or equal to 10.", vr.Messages[0].Text);
            Assert.AreEqual("Value", vr.Messages[0].Property);
        }
Esempio n. 11
0
        public async Task Inherited_OnValidate()
        {
            var iv = new IntValidator();
            var vr = await iv.ValidateAsync(11);

            Assert.IsTrue(vr.HasError);
            Assert.AreEqual(1, vr.Messages.Count);
            Assert.AreEqual("Count is not allowed to be eleven.", vr.Messages[0].Text);
            Assert.AreEqual("Value", vr.Messages[0].Property);
        }
        public void ValidateIntegerToBeBetweenValues()
        {
            // Given
            var validator = new IntValidator(42);

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

            // Then
            Assert.True(true);
        }
        public void ValidateIntegerToBeGreaterThanOrEqualToSmallerValue()
        {
            // Given
            var validator = new IntValidator(42);

            // When
            validator.BeGreaterThanOrEqualTo(13);

            // Then
            Assert.True(true);
        }
        public void ValidateIntegerToBePositive()
        {
            // Given
            var validator = new IntValidator(0);

            // When
            validator.BePositive();

            // Then
            Assert.True(true);
        }
        public void ValidateIntegerToBeOneOfExpectedValues()
        {
            // Given
            var validator = new IntValidator(42);

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

            // Then
            Assert.True(true);
        }
        public void ValidateIntegerToBeLessThanOrEqualToEqualValue()
        {
            // Given
            var validator = new IntValidator(42);

            // When
            validator.BeLessThanOrEqualTo(42);

            // Then
            Assert.True(true);
        }
        public void ValidateIntegerToBeValue()
        {
            // Given
            var validator = new IntValidator(42);

            // When
            validator.Be(42);

            // Then
            Assert.True(true);
        }
Esempio n. 18
0
        }     //end btnsubmit click

        private bool ValidateTextBoxes()
        {
            return(StringValidator.IsNotEmptySpaceOrNull(txtName.Text) &&
                   StringValidator.IsNotEmptySpaceOrNull(txtState.Text) &&
                   IntValidator.IsInteger(txtPop.Text) &&
                   StringValidator.IsDecimal(txtMedHI.Text) &&
                   StringValidator.IsDecimal(txtPercOwn.Text) &&
                   StringValidator.IsDecimal(txtRent.Text) &&
                   IntValidator.IsInteger(txtMaleMedAge.Text) &&
                   IntValidator.IsInteger(txtFemaleMedAge.Text) &&
                   StringValidator.IsDecimal(txtUnemploymentRate.Text) &&
                   StringValidator.IsDecimal(txtBurgRate.Text) &&
                   StringValidator.IsDecimal(txtVehTheftRate.Text));
        }
        public void SumNumbers()
        {
            IntValidator validator = new IntValidator();

            Console.WriteLine("\nEnter the number of numbers you want to sum\n ");

            bool canParse;

            var userSize = Console.ReadLine();

            canParse = validator.Validate(userSize);

            int sum = 0;

            if (canParse)
            {
                int   size     = Int32.Parse(userSize);
                int[] arr      = new int[size];
                bool  loopFalg = true;

                for (int i = 0; i < size; i++)
                {
                    bool isInt = false;
                    loopFalg = true;

                    while (loopFalg)
                    {
                        Console.WriteLine("\nPlease enter your number\n");
                        var userNumber = Console.ReadLine();
                        isInt = validator.Validate(userNumber);
                        if (isInt)
                        {
                            sum     += Int32.Parse(userNumber);
                            loopFalg = false;
                        }
                        else
                        {
                            Console.WriteLine("\nYou entered invalid number!!! please try again\n");
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("You entered invalid number!!!");
                return;
            }

            Console.WriteLine($"\nThe sum is: {sum}\n");
        }
        public void ValidateIntegerToBeLessThanOrEqualToValueViolated()
        {
            // Given
            var validator = new IntValidator(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);
        }
        public void ValidateIntegerToBeOneOfViolated()
        {
            // Given
            var validator = new IntValidator(42);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeOneOf(new[] { 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 ValidateIntegerToBePositiveViolated()
        {
            // Given
            var validator = new IntValidator(-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 ValidateIntegerToBeBetweenValuesMaximumViolated()
        {
            // Given
            var validator = new IntValidator(42);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeBetween(13, 39, "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 \"13\" and \"39\"{rn}because that's the bottom line",
                exception.UserMessage);
        }
Esempio n. 24
0
        private int getValues()
        {
            bool canParse;

            while (true)
            {
                Console.WriteLine("\nPlease enter the number you want to print\n");
                var          userNumber = Console.ReadLine();
                IntValidator validator  = new IntValidator();
                canParse = validator.Validate(userNumber);

                if (canParse)
                {
                    return(Int32.Parse(userNumber));
                }
                else
                {
                    Console.WriteLine("\nYou entered invalid number! please try again\n");
                }
            }
        }
Esempio n. 25
0
        public void IsHigherThan_ValueIsHigher_NoException()
        {
            IntValidator validator = new IntValidator("test", 1);

            validator.IsHigherThan(0);
        }