public void CreateRole() { const string roleName = "testRole"; var client = GetClient(); var item = new Role { Name = roleName }; client.Add(item); client.UnitOfWork.Commit(); string roleId = item.RoleId; // check client = GetClient(); int count = client.Roles.Where(x => x.RoleId == roleId).Count(); Assert.Equal(count, 1); // clear base EndActionClearRole(roleName); }
public RoleOverviewStepViewModel(IRepositoryFactory<ISecurityRepository> repositoryFactory, ISecurityEntityFactory entityFactory, Role item) : base(repositoryFactory, entityFactory, item) { }
public CreateRoleViewModel(IViewModelsFactory<IRoleOverviewStepViewModel> overviewVmFactory, Role item) { var itemParameter = new KeyValuePair<string, object>("item", item); RegisterStep(overviewVmFactory.GetViewModelInstance(itemParameter)); }
/// <summary> /// Checks the member in role. /// </summary> /// <param name="memberId">The member identifier.</param> /// <param name="role">The role.</param> /// <returns><c>true</c> if member is in role, <c>false</c> otherwise.</returns> /// <exception cref="System.ArgumentNullException"> /// memberId /// or /// role /// </exception> public bool CheckMemberInRole(string memberId, Role role) { if (memberId == null) { throw new ArgumentNullException("memberId"); } if (role == null) { throw new ArgumentNullException("role"); } var account = SecurityRepository.Accounts.FirstOrDefault(a => a.MemberId == memberId); if (account == null) { return false; } var retVal = false; foreach (var assignment in SecurityRepository.RoleAssignments.Where(x => x.AccountId == account.AccountId).Expand("Role")) { var examineRole = assignment.Role; retVal = examineRole != null && examineRole.RoleId.Equals(role.RoleId); if (retVal) { break; } } return retVal; }
public void RemoveUncommitedRoleTest() { ISecurityRepository client = GetClient(); var account = new Account() { UserName = "******" }; var role = new Role() { Name = "testRole" }; var roleAssignment = new RoleAssignment { Account = account, AccountId = account.AccountId, Role = role, RoleId = role.RoleId }; client.Attach(account); // add role account.RoleAssignments.Add(roleAssignment); Assert.True(client.IsAttachedTo(roleAssignment)); // remove uncommited role account.RoleAssignments.Remove(roleAssignment); client.Remove(roleAssignment); Assert.False(client.IsAttachedTo(roleAssignment)); }
public void CreateAccountWithNewRoleTest() { const string roleName = "testRole"; const string userName = "******"; ISecurityRepository client = GetClient(); var role = new Role() { Name = roleName }; var account = new Account() { UserName = userName }; var roleAssignment = new RoleAssignment { Account = account, AccountId = account.AccountId, Role = role, RoleId = role.RoleId }; // add role to account account.RoleAssignments.Add(roleAssignment); client.Add(role); client.Add(account); client.UnitOfWork.Commit(); string accountId = account.AccountId; string roleId = role.RoleId; EndActionClearAccount(userName); EndActionClearRole(roleName); client = GetClient(); int count = client.Accounts.Where(x => x.AccountId == accountId).Count(); Assert.Equal(count, 1); count = client.Roles.Where(x => x.RoleId == roleId).Count(); Assert.Equal(count, 1); count = client.RoleAssignments.Where(x => x.RoleId == roleId && x.AccountId == accountId).Count(); Assert.Equal(count, 1); }
private string AddRole(string name) { var client = GetRepository(); var role = new Role { Name = name }; client.Add(role); client.UnitOfWork.Commit(); return role.RoleId; }