public void TestUpdateRole() { _authorizationService = new AbilityAuthorizationService(new UserRepository(), new RoleRepository(), new AbilityRepository()); _authorizationService.AddRole(_role1); _authorizationService.AddRole(_role2); IEnumerable<IRole> roles = _authorizationService.GetRoles(); Assert.AreEqual(2, roles.Count()); Assert.AreEqual(_role1, roles.First()); Assert.AreEqual(_role2, roles.Last()); _role2.Name = "RoleUpdate"; _authorizationService.UpdateRole(_role2); roles = _authorizationService.GetRoles(); Assert.AreEqual(2, roles.Count()); Assert.AreEqual(_role1, roles.First()); Assert.AreEqual(_role2, roles.Last()); Assert.AreEqual("RoleUpdate", roles.Last().Name); }
public void TestRemoveAbilityAlsoRemovesFromRoles() { _authorizationService = new AbilityAuthorizationService(new UserRepository(), new RoleRepository(), new AbilityRepository()); _role1.Abilities.Add(_ability1); _role1.Abilities.Add(_ability2); _authorizationService.AddRole(_role1); IEnumerable<IAbility> abilities = _authorizationService.GetAbilities(); Assert.AreEqual(2, abilities.Count()); Assert.AreEqual(_ability1, abilities.First()); Assert.AreEqual(_ability2, abilities.Last()); _authorizationService.RemoveAbility("Ability1"); abilities = _authorizationService.GetAbilities(); Assert.AreEqual(1, abilities.Count()); Assert.AreEqual(_ability2, abilities.First()); IEnumerable<IRole> roles = _authorizationService.GetRoles(); Assert.AreEqual(1, roles.Count()); Assert.AreEqual(1, roles.FirstOrDefault().Abilities.Count); Assert.AreEqual(_ability2, roles.FirstOrDefault().Abilities.FirstOrDefault()); }
public void TestRemoveRole() { _authorizationService = new AbilityAuthorizationService(new UserRepository(), new RoleRepository(), new AbilityRepository()); _authorizationService.AddRole(_role1); _authorizationService.AddRole(_role2); IEnumerable<IRole> roles = _authorizationService.GetRoles(); Assert.AreEqual(2, roles.Count()); Assert.AreEqual(_role1, roles.First()); Assert.AreEqual(_role2, roles.Last()); _authorizationService.RemoveRole("Role1"); roles = _authorizationService.GetRoles(); Assert.AreEqual(1, roles.Count()); Assert.AreEqual(_role2, roles.First()); }
public void TestGetRole() { _authorizationService = new AbilityAuthorizationService(new UserRepository(), new RoleRepository(), new AbilityRepository()); _authorizationService.AddRole(_role1); _authorizationService.AddRole(_role2); IRole role = _authorizationService.GetRole("Role1"); Assert.AreEqual(role, _role1); }