Example #1
0
        private void button_Search_Click(object sender, EventArgs e)
        {
            if (textBoxSeialNumber.Text.Equals("") ||
                !RegExValidator.Is12Digit(textBoxSeialNumber.Text))
            {
                MessageBox.Show("Please enter a valid value for serial number..!!");
                return;
            }
            Boolean found = false;

            listBoxDisplay.Items.Clear();
            if (bikeList.Count > 0)
            {
                foreach (Bike bike in bikeList)
                {
                    if (bike.SerialNumber.Equals(long.Parse(textBoxSearchBike.Text)))
                    {
                        listBoxDisplay.Items.Add(bike);
                        found = true;
                        MessageBox.Show("Bike found, Details");
                    }
                }
            }
            else
            {
                MessageBox.Show("\n" + "The list is empty");
            }
            if (!found)
            {
                MessageBox.Show("No Search Results..!!");
            }
        }
        public void Has_default_negated_message()
        {
            var validator = new RegExValidator<Person>("^[A-Z][a-z]{1,4}$");

            var message = validator.DefaultNegatedErrorMessage;
            Console.WriteLine(message);
            Assert.That(message, Is.Not.Null & Is.Not.Empty);
        }
        public void Has_default_negated_message()
        {
            var validator = new RegExValidator <Person>("^[A-Z][a-z]{1,4}$");

            var message = validator.DefaultNegatedErrorMessage;

            Console.WriteLine(message);
            Assert.That(message, Is.Not.Null & Is.Not.Empty);
        }
Example #4
0
        public void Validate_SuccessfullyIdentifiesNameThatMatchesRegex()
        {
            var validator = new RegExValidator(new RegExConfig()
            {
                Name = "badFormat", Pattern = "^((?!\\d)\\w+)$"
            });

            var result = validator.Validate("Blank1");

            Assert.True(result.IsValid);
            Assert.True(result.Errors.Count == 0);
        }
Example #5
0
        public void Validate_SuccessfullyIdentifiesNameThatDoesntMatchRegex()
        {
            var validator = new RegExValidator(new RegExConfig()
            {
                Name = "badFormat", Pattern = "^((?!\\d)\\w+)$"
            });

            var result = validator.Validate("Blank;");

            Assert.False(result.IsValid);
            Assert.True(result.Errors.Count == 1);
            Assert.Equal(ValidationErrorType.Regex, result.Errors.FirstOrDefault()?.ErrorType);
            Assert.Equal("badFormat", result.Errors.FirstOrDefault()?.ValidatorName);
        }
Example #6
0
        public static bool ValidateUser(PortalUserContract user, out string msg)
        {
            try
            {
                if (user == null)
                {
                    msg = "User object is null or empty";
                    return(false);
                }
                if (string.IsNullOrEmpty(user.UserName) || user.UserName.Length < 8)
                {
                    msg = "User name is null or empty / less than 8 character length";
                    return(false);
                }
                if (!RegExValidator.IsEmailValid(user.Email))
                {
                    msg = "Invalid email address";
                    return(false);
                }
                if (string.IsNullOrEmpty(user.FirstName))
                {
                    msg = "Invalid first name";
                    return(false);
                }
                if (string.IsNullOrEmpty(user.LastName))
                {
                    msg = "Invalid last name";
                    return(false);
                }

                msg = "";
                return(true);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(false);
            }
        }
Example #7
0
        private void button_Add_Click(object sender, EventArgs e)
        {
            int            gearNumber;
            long           serialNumber;
            double         price, warrenty, speed, gheight, sheight, bweight;
            string         make, input, msg = "";
            EnumSuspension suspensionType;
            EnumColor      color;
            bool           correct = false;

            Bike mountainBike = null;
            Bike roadBike     = null;

            if (bikeType.SelectedIndex == -1)
            {
                MessageBox.Show("\t Please Select Bike type \n");
                return;
            }

            input   = textBoxSeialNumber.Text;
            correct = RegExValidator.Is12Digit(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t Serial Number must 12 digit \n");
                return;
            }
            serialNumber = long.Parse(input);


            correct = false;
            input   = textBoxMake.Text;
            correct = RegExValidator.IsAlphabetLetter(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t  Must be in LETTER(S) and NOT EMPTY  \n");
                return;
            }
            make = input;

            correct = false;
            input   = textBoxSpeed.Text;
            correct = RegExValidator.IsDigit(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t Speed must not be zero AND Must be degit \n");
                return;
            }
            speed = Convert.ToDouble(input);


            Date made_date = new Date();

            made_date.Day   = Convert.ToInt32(textBoxDay.Text);
            made_date.Month = Convert.ToInt32(textBoxMonth.Text);
            made_date.Year  = Convert.ToInt32(textBoxYear.Text);
            suspensionType  = (EnumSuspension)positionsuspensioncombo;
            color           = (EnumColor)positioncolorcombo;
            price           = Convert.ToDouble(textBoxPrice.Text);
            warrenty        = Convert.ToDouble(textBoxWarrenty.Text);
            if (bikeType.SelectedIndex == 1)
            {
                correct = false;
                input   = textBoxSeatHeight.Text;
                correct = RegExValidator.IsDigit(input) &&
                          RegExValidator.IsEmpty(input);
                if (!correct)
                {
                    MessageBox.Show("\t Seat height must not be empty AND Must be degit \n");
                    return;
                }
                sheight  = Convert.ToDouble(input);
                bweight  = Convert.ToDouble(textBoxWeight.Text);
                roadBike = new RoadBike(serialNumber, make, speed, color, made_date, warrenty, price, sheight, bweight);
                bikeList.Add(roadBike);

                msg = "Bike successfully added as a road bike ";
            }
            else
            {
                gheight      = Convert.ToDouble(textBoxGroundHeight.Text);
                gearNumber   = Convert.ToInt32(textBoxGears.Text);
                mountainBike = new MountainBike(serialNumber, make, speed, color, made_date, warrenty, price, gheight, suspensionType, gearNumber);
                bikeList.Add(mountainBike);

                msg = "Bike successfully added as a mountain bike ";
            }


            msg += "with bikelist";
            MessageBox.Show(msg);
        }
        public void Should_be_valid_when_input_matches_pattern()
        {
            var validator = new RegExValidator<Person>("^[A-Z][a-z]{1,4}$");

            Assert.That(validator.Validate(null, "Hello"), Is.True);
        }
        public void Should_be_invalid_when_input_does_not_match_pattern()
        {
            var validator = new RegExValidator<Person>("^[A-Z][a-z]{1,4}$");

            Assert.That(validator.Validate(null, "world"), Is.False);
        }
Example #10
0
        public void Should_be_invalid_when_input_does_not_match_pattern()
        {
            var validator = new RegExValidator <Person>("^[A-Z][a-z]{1,4}$");

            Assert.That(validator.Validate(null, "world"), Is.False);
        }
Example #11
0
        public void Should_be_valid_when_input_matches_pattern()
        {
            var validator = new RegExValidator <Person>("^[A-Z][a-z]{1,4}$");

            Assert.That(validator.Validate(null, "Hello"), Is.True);
        }
Example #12
0
        static void Main(string[] args)
        {
            string input;
            long   serNum = 0; string make = "";
            double speed = 0, seatHeight = 0;
            bool   correct = false;

            do
            {
                Console.Write("Please enter serial number: ");
                input = Console.ReadLine();
                if (RegExValidator.Is12Digit(input) && RegExValidator.IsEmpty(input))
                {
                    correct = true;
                }
                if (!correct)
                {
                    Console.WriteLine("\t...The input must not be empty and must be 12 digit. Please try again...\n");
                }
            } while (!correct);

            serNum = long.Parse(input);


            correct = false;
            do
            {
                Console.Write(" Please enter the make:   ");
                input   = Console.ReadLine();
                correct = RegExValidator.IsAlphabetLetter(input);
                if (!correct)
                {
                    Console.WriteLine("\t...Not valid.. the input must be alphabets only. Try again.\n");
                }
            } while (!correct);

            make = input;

            correct = false;
            do
            {
                Console.Write("Please enter top speed:   ");
                input   = Console.ReadLine();
                correct = RegExValidator.IsDigit(input);
                if (!correct)
                {
                    Console.WriteLine("\t...Not valid.. the input must be digit only...\n");
                }
            } while (!correct);

            speed = Convert.ToDouble(input);

            correct = false;
            do
            {
                Console.Write("Please enter seat height(in inches):   ");
                input   = Console.ReadLine();
                correct = RegExValidator.IsDigit(input);
                if (!correct)
                {
                    Console.WriteLine("\t...Not valid. The input must be digits only...\n");
                }
            } while (!correct);

            seatHeight = Convert.ToInt32(input);

            Roadbike rBike = new Roadbike(serNum, make, speed, EnumColor.Black,
                                          new MyBikesStore.Date(1, 1, 1), seatHeight);

            Console.WriteLine("\n\n The Mountain Bike is:\n\t" + rBike);

            Console.ReadKey();
        }
Example #13
0
        private void Button_Add_Click(object sender, EventArgs e)
        {
            long           serialNumber;
            double         warrenty, speed, gheight, sheight, bweight;
            string         make, input, msg = "";
            EnumSuspension suspensionType;
            EnumColor      color;
            bool           correct = false;

            Bike mountainBike = null;
            Bike roadBike     = null;

            //Bike bike;
            if (bikeType.SelectedIndex == -1)
            {
                MessageBox.Show("\t...BAD INPUT..No bike type selected\n");
                return;
            }

            input   = textBoxSeialNumber.Text;
            correct = RegExValidator.Is12Digit(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t...BAD INPUT..Serial cant be empty and should be of 12 digits\n");
                return;
            }
            serialNumber = long.Parse(input);


            correct = false;
            input   = textBoxMake.Text;
            correct = RegExValidator.IsAlphabetLetter(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t...BAD INPUT..Make cannot be empty and should contain\n");
                return;
            }
            make = input;

            correct = false;
            input   = textBoxSpeed.Text;
            correct = RegExValidator.IsDigit(input) &&
                      RegExValidator.IsEmpty(input);
            if (!correct)
            {
                MessageBox.Show("\t...BAD INPUT..Speed cannot be empty and should contain only digits\n");
                return;
            }
            speed = Convert.ToDouble(input);


            Date made_date = new Date();

            made_date.Day   = Convert.ToInt32(textBoxDay.Text);
            made_date.Month = Convert.ToInt32(textBoxMonth.Text);
            made_date.Year  = Convert.ToInt32(textBoxYear.Text);
            suspensionType  = (EnumSuspension)positionsuspensioncombo;
            color           = (EnumColor)positioncolorcombo;

            warrenty = Convert.ToDouble(textBoxWarrenty.Text);
            if (bikeType.SelectedIndex == 1)
            {
                correct = false;
                input   = textBoxSeatHeight.Text;
                correct = RegExValidator.IsDigit(input) &&
                          RegExValidator.IsEmpty(input);
                if (!correct)
                {
                    MessageBox.Show("\t...BAD INPUT..Seat height cannot be empty and should contain only digits\n");
                    return;
                }
                sheight  = Convert.ToDouble(input);
                bweight  = Convert.ToDouble(textBoxWeight.Text);
                roadBike = new RoadBike(serialNumber, make, speed, color, made_date, warrenty, sheight, bweight);
                bikeList.Add(roadBike);

                msg = "Bike successfully added as a road bike ";
            }
            else
            {
                gheight      = Convert.ToDouble(textBoxGroundHeight.Text);
                mountainBike = new MountainBike(serialNumber, make, speed, color, made_date, warrenty, gheight, suspensionType);
                bikeList.Add(mountainBike);

                msg = "Bike successfully added as a mountain bike ";
            }


            msg += "with bikelist";
            MessageBox.Show(msg);
        }
Example #14
0
        public bool Validate()
        {
            IDictionary <string, ModelPropertyConfiguration> modelPropConfig = ControlLibraryConfig.ControlConfigReader.GetModelConfigurationSettings(TypeName, this.ConfigKey);

            if (modelPropConfig != null)
            {
                foreach (KeyValuePair <string, ModelPropertyConfiguration> keyValue in modelPropConfig)
                {
                    this.PropertyName = keyValue.Key;

                    if (keyValue.Value.IsComplexType)
                    {
                        if (keyValue.Value.IsEnumerable)
                        {
                            IEnumerable enumerable = GetNestedPropertyValue(this.data, keyValue.Key) as IEnumerable;
                            if (enumerable != null)
                            {
                                IEnumerator enumerator = enumerable.GetEnumerator();

                                int currentIndex = 0;

                                while (enumerator.MoveNext())
                                {
                                    if (enumerator.Current != null)
                                    {
                                        this.PropertyName = string.Format("{0}_{1}_", keyValue.Key, currentIndex);
                                        ObjectValidator validator = new ObjectValidator(enumerator.Current, this, ConfigKey);
                                        if (false == validator.Validate())
                                        {
                                            this.ErrorList.AddRange(validator.ErrorList);
                                        }
                                    }
                                    currentIndex++;
                                }
                            }
                        }
                        else
                        {
                            object data = GetNestedPropertyValue(this.data, keyValue.Key);
                            if (null != data)
                            {
                                ObjectValidator validator = new ObjectValidator(data, this, ConfigKey);
                                if (false == validator.Validate())
                                {
                                    this.ErrorList.AddRange(validator.ErrorList);
                                }
                            }
                        }
                    }
                    else
                    {
                        //PropertyInfo info = this.GetType().GetProperty(keyValue.Key);
                        object value = GetNestedPropertyValue(this.data, keyValue.Key);
                        IModelPropertyConfiguration imodel = modelPropConfig[keyValue.Key];
                        if (imodel != null && imodel.PropertyConfiguration != null && imodel.PropertyConfiguration.Validators != null && imodel.PropertyConfiguration.Validators.Count > 0)
                        {
                            foreach (IValidator item in imodel.PropertyConfiguration.Validators)
                            {
                                if (item.Type == ValidatorsType.Custom)
                                {
                                    CustomValidator validation = item as CustomValidator;
                                    CustomValidationExpressionConfiguration expressionConfig = ControlLibraryConfig.ControlConfigReader.GetCustomValidationExpressionConfiguration(validation.ValidationType.ToString());
                                    string _exression = string.Empty;
                                    if (expressionConfig != null)
                                    {
                                        _exression = expressionConfig.Expression;
                                    }
                                    if (item.Validate(value, _exression) == false)
                                    {
                                        if (ErrorList == null)
                                        {
                                            ErrorList = new List <KeyValuePair <string, string> >();
                                        }
                                        ErrorList.Add(new KeyValuePair <string, string>(this.GetCurrentPropertyName(), item.Message));
                                    }
                                }
                                else if (item.Type == ValidatorsType.RegExp)
                                {
                                    RegExValidator validation = item as RegExValidator;
                                    string         _exression = validation.RegExpression;

                                    if (item.Validate(value, _exression) == false)
                                    {
                                        if (ErrorList == null)
                                        {
                                            ErrorList = new List <KeyValuePair <string, string> >();
                                        }
                                        ErrorList.Add(new KeyValuePair <string, string>(this.GetCurrentPropertyName(), item.Message));
                                    }
                                }
                                else if (item.Type == ValidatorsType.Required)
                                {
                                    bool mandatory = true;
                                    if (imodel.PropertyConfiguration.SiteConfig != null && imodel.PropertyConfiguration.SiteConfig.Count > 0)
                                    {
                                        bool?configVlaueVisible = this.GetSiteConfigValue(imodel.PropertyConfiguration.SiteConfig, SiteConfigType.Visible);
                                        if (configVlaueVisible.HasValue && configVlaueVisible == false)
                                        {
                                            mandatory = false;
                                        }

                                        if (mandatory)
                                        {
                                            bool?configVlaueMandatory = this.GetSiteConfigValue(imodel.PropertyConfiguration.SiteConfig, SiteConfigType.Mandatory);
                                            if (configVlaueMandatory.HasValue && configVlaueMandatory == false)
                                            {
                                                mandatory = false;
                                            }
                                        }
                                    }
                                    if (mandatory)
                                    {
                                        if (item.Validate(value, string.Empty) == false)
                                        {
                                            if (ErrorList == null)
                                            {
                                                ErrorList = new List <KeyValuePair <string, string> >();
                                            }
                                            ErrorList.Add(new KeyValuePair <string, string>(this.GetCurrentPropertyName(), item.Message));
                                        }
                                    }
                                }
                                else
                                {
                                    if (item.Validate(value, string.Empty) == false)
                                    {
                                        if (ErrorList == null)
                                        {
                                            ErrorList = new List <KeyValuePair <string, string> >();
                                        }
                                        ErrorList.Add(new KeyValuePair <string, string>(this.GetCurrentPropertyName(), item.Message));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(this.ErrorList == null ? true : this.ErrorList.Count == 0);
        }