Exemplo n.º 1
0
        /// <summary>
        /// Determine if rules for a resetting a password are met using property data
        /// annotation in the class CustomerLogin. Rules for a password are done
        /// in <see cref="PasswordCheck"/> class.
        /// </summary>
        private void ProcessLogin()
        {
            EntityValidationResult validationResult = ValidationHelper.ValidateEntity(_customerLogin);

            if (validationResult.HasError)
            {
                _retryCount += 1;

                if (_retryCount >= 3)
                {
                    MessageBox.Show("Too many attempts");
                    Application.Current.Shutdown();
                }
                else
                {
                    MessageBox.Show(validationResult.ErrorMessageList());
                }
            }
            else
            {
                Hide();

                var workWindow = new WorkWindow();
                Application.Current.MainWindow = workWindow;
                workWindow.ShowDialog();

                Close();
            }
        }
        private void ProcessLogin()
        {
            var customerLogin = (CustomerLogin)_bindingSource.Current;

            EntityValidationResult validationResult = ValidationHelper.ValidateEntity(customerLogin);

            if (validationResult.HasError)
            {
                _retryCount += 1;

                if (_retryCount >= 3)
                {
                    MessageBox.Show("Too many attempts");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show(validationResult.ErrorMessageList());
                }
            }
            else
            {
                Hide();

                var workForm = new WorkForm();
                workForm.ShowDialog();

                Close();
            }
        }
        public void PersonPhoneExample()
        {
            Person person = new () { FirstName = "Bob", LastName = "Jones", SSN = "201518161" };

            EntityValidationResult validationResult = ValidationHelper.ValidateEntity(person);

            Assert.IsTrue(validationResult.HasError);
            Assert.IsTrue(validationResult.ErrorMessageList().Contains("Phone is required"));
        }
        public void PersonSocialSecurityExample()
        {
            Person person = new Person()
            {
                FirstName = "Jimmy Bob",
                LastName  = "Jones",
                Phone     = "(305) 444-9999",
                SSN       = "078-05-1120"
            };

            EntityValidationResult validationResult =
                ValidationHelper.ValidateEntity(person);

            Console.WriteLine(validationResult.ErrorMessageList());
            Assert.IsTrue(validationResult.HasError);
        }
        public void PersonFirstNameMissingExample()
        {
            Person person = new Person()
            {
                FirstName = "Jimmy Bob",
                LastName  = "Jones",
                Phone     = "(305) 444-9999",
                SSN       = "201518161"
            };

            EntityValidationResult validationResult =
                ValidationHelper.ValidateEntity(person);

            Assert.IsFalse(validationResult.HasError);
            var test = validationResult.Errors;

            person.FirstName = "";
            validationResult = ValidationHelper.ValidateEntity(person);

            Assert.IsTrue(validationResult.Errors.Count == 1 &&
                          validationResult.ErrorMessageList().Contains("First Name"));
        }