private void ValidateAge(User user)
 {
     if (user.Age < 18 || user.Age > 65)
     {
         throw new ArgumentOutOfRangeException("age out of range");
     }
 }
 private void ValidateEmailAddress(User user)
 {
     if (!user.Email.IsEmail())
     {
         throw new ArgumentException("invalid email address");
     }
 }
 private void ValidatePassword(User user)
 {
     var containsDigits = user.Password.Count(x => char.IsDigit(x)) >= 2;
     var containsUpperCase = user.Password.Any(x => char.IsUpper(x));
     var containsNonAlphaNumeric = user.Password.Any(x => !char.IsDigit(x) && !char.IsLetter(x) && !char.IsWhiteSpace(x));
     if (user.Password.Length < 8 || !containsDigits || !containsUpperCase || !containsNonAlphaNumeric)
     {
         throw new ArgumentException("invalid user password");
     }
 }
 private void Validate(User user)
 {
     if (StringExtensions.IsNullOrEmpty(user.UserName, user.Password, user.Email, user.FirstName, user.LastName))
     {
         throw new NullReferenceException("invalid user");
     }
     ValidatePassword(user);
     ValidateEmailAddress(user);
     ValidateAge(user);
 }
 public User CreateUser(string userName, string email, string password, string firstName, string lastName, int age)
 {
     var user = new User(userName, email, password, firstName, lastName, age);
     Validate(user);
     return user;
 }
 public bool VerifyTransaction(User user, ITransaction transaction)
 {
     _user = user;
     return AccountIsValid() && SufficientFunds(transaction);
 }