public void AddRole_HasRole_GetRoles_Test() { var s = new FakeSubject(); var o = new FakeObject(); var res = _pm.AddRole(s, o, Role.Manager); Assert.IsTrue(res); Assert.IsTrue(_pm.HasRole(s, o, Role.Manager)); Assert.IsTrue(_pm.HasAllRoles(s, o, new Role[] { Role.Manager })); Assert.IsTrue(_pm.HasAnyRole(s, o, new Role[] { Role.Manager, Role.Owner })); CollectionAssert.AreEquivalent(new Role[] { Role.Manager }, _pm.GetRoles(s, o).ToList()); }
public void SetRolesTest() { var s = new FakeSubject(); var o = new FakeObject(); var roles = new Role[] { Role.Manager, Role.Owner }; _pm.SetRoles(s, o, roles); Assert.IsTrue(_pm.HasRole(s, o, Role.Manager)); Assert.IsTrue(_pm.HasRole(s, o, Role.Owner)); Assert.IsTrue(_pm.HasAllRoles(s, o, roles)); Assert.IsTrue(_pm.HasAnyRole(s, o, roles)); CollectionAssert.AreEquivalent(roles, _pm.GetRoles(s, o).ToList()); }
public void RemoveAllRolesTest() { var s = new FakeSubject(); var o = new FakeObject(); var roles = new Role[] { Role.Manager, Role.Owner, Role.Viewer }; _pm.SetRoles(s, o, roles); _pm.RemoveAllRoles(s, o); Assert.IsFalse(_pm.HasRole(s, o, Role.Manager)); Assert.IsFalse(_pm.HasRole(s, o, Role.Owner)); Assert.IsFalse(_pm.HasRole(s, o, Role.Viewer)); Assert.IsFalse(_pm.HasAllRoles(s, o, roles)); Assert.IsFalse(_pm.HasAnyRole(s, o, roles)); Assert.AreEqual(0, _pm.GetRoles(s, o).Count); }
public void IsSubjectInheritsTest() { var s1 = new FakeSubject { Id = 1 }; var s2 = new FakeSubject { Id = 2 }; var s3 = new FakeSubject { Id = 3 }; var o = new FakeObject(); _pm.AddRole(s1, o, Role.Editor); _pm.AddRole(s2, o, Role.Manager); _pm.AddRole(s3, o, Role.Owner); _ipm.AddSubjectInheritance(s1, s2); _ipm.AddSubjectInheritance(s2, s3); Assert.IsTrue(_ipm.IsSubjectInherits(s1, s2)); Assert.IsTrue(_ipm.IsSubjectInherits(s2, s3)); Assert.IsTrue(_ipm.IsSubjectInherits(s1, s3)); Assert.IsFalse(_ipm.IsSubjectInherits(s2, s1)); Assert.IsFalse(_ipm.IsSubjectInherits(s3, s1)); Assert.IsFalse(_ipm.IsSubjectInherits(s3, s2)); _ipm.RemoveSubjectInheritance(s2, s3); Assert.IsTrue(_ipm.IsSubjectInherits(s1, s2)); Assert.IsFalse(_ipm.IsSubjectInherits(s2, s3)); Assert.IsFalse(_ipm.IsSubjectInherits(s1, s3)); Assert.IsFalse(_ipm.IsSubjectInherits(s2, s1)); Assert.IsFalse(_ipm.IsSubjectInherits(s3, s1)); Assert.IsFalse(_ipm.IsSubjectInherits(s3, s2)); }
public void IsObjectInheritsTest() { var s = new FakeSubject(); var o1 = new FakeObject { Id = 1 }; var o2 = new FakeObject { Id = 1 }; var o3 = new FakeObject { Id = 1 }; _pm.AddRole(s, o1, Role.Editor); _pm.AddRole(s, o2, Role.Manager); _pm.AddRole(s, o3, Role.Owner); _ipm.AddObjectInheritance(o1, o2); _ipm.AddObjectInheritance(o2, o3); Assert.IsTrue(_ipm.IsObjectInherits(o1, o2)); Assert.IsTrue(_ipm.IsObjectInherits(o2, o3)); Assert.IsTrue(_ipm.IsObjectInherits(o1, o3)); Assert.IsFalse(_ipm.IsObjectInherits(o2, o1)); Assert.IsFalse(_ipm.IsObjectInherits(o3, o1)); Assert.IsFalse(_ipm.IsObjectInherits(o3, o2)); _ipm.RemoveObjectInheritance(o2, o3); Assert.IsTrue(_ipm.IsObjectInherits(o1, o2)); Assert.IsFalse(_ipm.IsObjectInherits(o2, o3)); Assert.IsFalse(_ipm.IsObjectInherits(o1, o3)); Assert.IsFalse(_ipm.IsObjectInherits(o2, o1)); Assert.IsFalse(_ipm.IsObjectInherits(o3, o1)); Assert.IsFalse(_ipm.IsObjectInherits(o3, o2)); }