public void ValidateAccountStatus(string accountStatus, Type exceptionType)
        {
            UserAccount userAccount;
            var         status = ( UserAccountStatusEnum_Enumeration )Enum.Parse(typeof(UserAccountStatusEnum_Enumeration), accountStatus);

            userAccount      = new UserAccount( );
            userAccount.Name = "Test user " + Guid.NewGuid( );
            userAccount.AccountStatus_Enum = status;
            userAccount.Password           = "******";
            userAccount.Save( );

            if (exceptionType == null)
            {
                UserAccountValidator.ValidateAccountStatus(userAccount, false);
            }
            else
            {
                Assert.Throws(exceptionType, () => UserAccountValidator.ValidateAccountStatus(userAccount, false));
            }
        }
Example #2
0
        /// <summary>
        /// Determine the user account associated with this API key.
        /// Return null if the user account is invalid.
        /// </summary>
        /// <param name="apiKey">The API key</param>
        /// <returns>The user account, or null if the user account is somehow unavailable or locked.</returns>
        private UserAccount GetValidUserAccount(ApiKey apiKey)
        {
            // Get the user account
            UserAccount userAccount = apiKey.ApiKeyUserAccount;

            if (userAccount == null)
            {
                return(null);
            }

            // Validate the account status
            try
            {
                UserAccountValidator.ValidateAccountStatus(userAccount, true);
            }
            catch (AuthenticationException) // note: there are various types that derive from this
            {
                return(null);
            }

            return(userAccount);
        }