/// <summary>
        /// Request from the client to create a new account
        /// </summary>
        /// <param name="signupUserCommand"> </param>
        /// <returns></returns>
        public string CreateAccount(SignupUserCommand signupUserCommand)
        {
            // Check the given credential strings
            if (signupUserCommand != null &&
                !string.IsNullOrEmpty(signupUserCommand.Email) &&
                !string.IsNullOrEmpty(signupUserCommand.Username) &&
                !string.IsNullOrEmpty(signupUserCommand.Password))
            {
                User userByUserName = _userRepository.GetUserByUserName(signupUserCommand.Username);
                if (userByUserName != null)
                {
                    throw new InvalidOperationException("Username already exists. Operation aborted");
                }
                User userByEmail = _userRepository.GetUserByEmail(signupUserCommand.Email);
                if (userByEmail != null)
                {
                    throw new InvalidOperationException("Email already exists. Operation aborted.");
                }

                // Hash the Password
                string hashedPassword = _passwordEncryptionService.EncryptPassword(signupUserCommand.Password);
                // Generate new activation key
                string activationKey = _activationKeyGenerationService.GenerateNewActivationKey();
                if (!string.IsNullOrEmpty(activationKey))
                {
                    // Create new user
                    User user = new User(signupUserCommand.Email, signupUserCommand.Username, hashedPassword,
                                         signupUserCommand.Country, signupUserCommand.TimeZone,
                                         signupUserCommand.PgpPublicKey, activationKey);
                    user.IsActivationKeyUsed = new IsActivationKeyUsed(false);
                    user.IsUserBlocked       = new IsUserBlocked(false);
                    //persist so that user will be assigned an ID
                    _persistenceRepository.SaveUpdate(user);

                    IList <Tier> tiers = _tierRepository.GetAllTierLevels();
                    for (int i = 0; i < tiers.Count; i++)
                    {
                        user.AddTierStatus(Status.NonVerified, tiers[i]);
                    }

                    // Save to persistence
                    _persistenceRepository.SaveUpdate(user);
                    _emailService.SendPostSignUpEmail(user.Email, user.Username, user.ActivationKey,
                                                      user.AdminEmailsSubscribed);
                    // return Activation Key
                    return(activationKey);
                }
                else
                {
                    throw new DataException("Not able to generate an activation key for New User request");
                }
            }
            else
            {
                throw new InvalidCredentialException("Email, username and/or Password not provided for reister new user request.");
            }
        }
        public void GetAllTierLevel_IfMasterDataIsPresentInDatabase_ThereShooldBe5TierLevels()
        {
            IList <Tier> geTiers = _tierRepository.GetAllTierLevels();

            Assert.NotNull(geTiers);
            Assert.AreEqual(5, geTiers.Count);
            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(geTiers[i].TierLevel, "Tier " + i);
            }
        }
        public void CreateAccount_IfAccountIsCreatedSuccessfully_AllTierLevelsShouldBeAssignedAndAreNonVerified()
        {
            IRegistrationApplicationService registrationService =
                (IRegistrationApplicationService)_applicationContext["RegistrationApplicationService"];
            IUserRepository userRepository =
                (IUserRepository)_applicationContext["UserRepository"];
            ITierRepository tierRepository =
                (ITierRepository)_applicationContext["TierRepository"];
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            string           activationKey    = registrationService.CreateAccount(new SignupUserCommand(
                                                                                      "*****@*****.**", "Bob", "iamnotalice", "Wonderland", TimeZone.CurrentTimeZone, ""));

            // Wait for the email to be sent
            manualResetEvent.WaitOne(5000);
            User receivedUser = userRepository.GetUserByUserName("Bob");

            Assert.NotNull(receivedUser);
            IList <Tier> tiers = tierRepository.GetAllTierLevels();

            for (int i = 0; i < tiers.Count; i++)
            {
                Assert.AreEqual(receivedUser.GetTierLevelStatus(tiers[i]), Status.NonVerified.ToString());
            }
        }