private List <int> GetUserIdsFromNames(IDatabase db, string[] usernames)
        {
            List <int> userIds = new List <int>(usernames.Length);

            foreach (string username in usernames)
            {
                int id = SimpleMembershipProvider.GetUserId(db, SafeUserTableName, SafeUserNameColumn, SafeUserIdColumn, CasingBehavior, username);
                if (id == -1)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, WebDataResources.Security_NoUserFound, username));
                }
                userIds.Add(id);
            }
            return(userIds);
        }
        // Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized
        public override string[] GetRolesForUser(string username)
        {
            if (!InitializeCalled)
            {
                return(PreviousProvider.GetRolesForUser(username));
            }
            using (var db = ConnectToDatabase())
            {
                int userId = SimpleMembershipProvider.GetUserId(db, SafeUserTableName, SafeUserNameColumn, SafeUserIdColumn, CasingBehavior, username);
                if (userId == -1)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, WebDataResources.Security_NoUserFound, username));
                }

                string query = @"SELECT r.RoleName FROM " + UsersInRoleTableName + " u, " + RoleTableName + " r Where (u.UserId = @0 and u.RoleId = r.RoleId) GROUP BY RoleName";
                return(db.Query(query, new object[] { userId }).Select <dynamic, string>(d => (string)d[0]).ToArray());
            }
        }
        public void GetUserId_WithoutCaseNormalization()
        {
            // Arrange
            var database      = new Mock <MockDatabase>(MockBehavior.Strict);
            var expectedQuery = @"SELECT userId FROM users WHERE (userName = @0)";

            database.Setup(d => d.QueryValue(expectedQuery, "zeke")).Returns(999);

            // Act
            var result = SimpleMembershipProvider.GetUserId(
                database.Object,
                "users",
                "userName",
                "userId",
                SimpleMembershipProviderCasingBehavior.RelyOnDatabaseCollation,
                "zeke");

            // Assert
            Assert.Equal <int>(999, result);
        }