private void lstRoleName_SelectedIndexChanged(object sender, EventArgs e) { try { if (lstRoleName.Items.Count > 0) { string selectedRole = lstRoleName.SelectedItem.ToString(); txtRoleName.Text = selectedRole; // ApplicationName txtApplicationName.Text = roleProvider.ApplicationName; try { // Find users in selected role string[] usersInRole = roleProvider.FindUsersInRole(selectedRole); if (usersInRole != null) { if (usersInRole.Length > 0) { lstUsersInRoles.Items.Clear(); IEnumerator enumerator = usersInRole.GetEnumerator(); while (enumerator.MoveNext()) { object obj = enumerator.Current; lstUsersInRoles.Items.Add(obj); } //MessageBox.Show("User(s) finded in role(s) successfully", "Find users in role", MessageBoxButtons.OK, MessageBoxIcon.Information); } //else // MessageBox.Show("Failed to find users in role, No matched found", "Find users in role", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { lstUsersInRoles.Items.Clear(); } } catch (Exception ex) { MessageBox.Show("Failed to select role info., " + ex.Message, "Select role info.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch (ArgumentException ex) { MessageBox.Show("Failed to select role info., " + ex.Message, "Select role info.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (SqlException ex) { MessageBox.Show("Failed to select role info., " + ex.Message, "Select role info.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show("Failed to select role info., " + ex.Message, "Select role info.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public void TestFindUsersInRoleQueryCount() { var roleProvider = new CustomRoleProvider(); var queryCount = new EntityFrameworkActivityLogger(); using (var usersContext = new ApplicationDbContext()) using (new WithInterception(queryCount)) { roleProvider.FindUsersInRole(usersContext, testRoleX.Name, ""); Assert.AreEqual(2, queryCount.TotalExecutedCount, "The query count for CustomRoleProvider::FindUsersInRole exceeded the expected number."); queryCount.Reset(); roleProvider.FindUsersInRole(usersContext, testRoleX.Name, testUserA.UserName); Assert.AreEqual(2, queryCount.TotalExecutedCount, "The query count for CustomRoleProvider::FindUsersInRole exceeded the expected number."); } }