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 CreateAccountWithExistingRoleTest() { const string roleName = "testRole"; const string userName = "******"; ISecurityRepository client = GetClient(); var role = new Role() { Name = roleName }; client.Add(role); client.UnitOfWork.Commit(); EndActionClearRole(roleName); string roleId = role.RoleId; client = GetClient(); role = client.Roles.Where(x => x.RoleId == roleId).FirstOrDefault(); client.Attach(role); 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(account); client.UnitOfWork.Commit(); string accountId = account.AccountId; EndActionClearAccount(userName); 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); }