Esempio n. 1
0
        public void CancelRole()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Role role = Role.Create();
            role.Code = StringFactory.NewGuid();
            role.Name = "test-giverole-role";
            role.Save();

            user.GiveRole(role);
            User user1 = User.GetUser(user.Account);
            var user2 = user1.RoleList.Where(r => r.Code == role.Code).ToList();
            Assert.AreEqual(1, user2.Count);

            user1.CancelRole(role);
            var user3 = user1.RoleList.Where(r => r.Code == role.Code).ToList();
            Assert.AreEqual(0, user3.Count);

            role.Delete();
            user.Delete();
        }
Esempio n. 2
0
        public void CheckPermission()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Operation target = new Operation();
            target.Code = StringFactory.NewGuid();
            target.AppId = StringFactory.NewGuid();
            target.TargetId = StringFactory.NewGuid();
            target.Name = "test-add-RoleTargetOperation";

            bool b = user.CheckPermission(target);
            Assert.IsFalse(b);

            User user1 = new User();
            user1.Name = "test-add-user";
            user1.Account = StringFactory.NewGuid();
            user1.Save();

            Role role = Role.Create();
            role.Name = "test-giverole-role";
            role.Save();

            role.GivePermission(target);
            user.GiveRole(role);

            User user2 = User.GetUser(user.Account);
            var b1 = user2.CheckPermission(target);
            Assert.IsTrue(b1);

            role.Delete();
            user1.CancelRole(role);
            role.CancelPermission(target);
            user.Delete();
            user1.Delete();
        }
Esempio n. 3
0
        public void TargetOperationList()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Operation operation = new Operation();
            operation.Code = StringFactory.NewGuid();
            operation.AppId = StringFactory.NewGuid();
            operation.TargetId = StringFactory.NewGuid();
            operation.Name = "test-add-RoleTargetOperation";
            operation.Save();

            User user1 = new User();
            user1.Name = "test-add-user";
            user1.Account = StringFactory.NewGuid();
            user1.Save();

            Role role = Role.Create();
            role.Name = "test-giverole-role";
            role.Save();

            role.GivePermission(operation);
            user.GiveRole(role);

            User user2 = User.GetUser(user.Account);
            Assert.AreEqual(1, user2.OperationList.Count);

            role.Delete();
            user1.CancelRole(role);
            role.CancelPermission(operation);
            operation.Delete();
            user.Delete();
            user1.Delete();
        }
Esempio n. 4
0
        public void TargetList()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Role role = Role.Create();
            role.Name = "test-giverole-role";
            role.Save();

            user.GiveRole(role);

            Organization org1 = Organization.Create();
            org1.Code = StringFactory.NewGuid();
            org1.Name = "org-test-name";
            org1.FullName = "org-test-fullname";
            org1.Save();
            Assert.IsNotNull(org1);

            org1.GiveRole(role);

            Target target = Target.Create();
            target.Code = StringFactory.NewGuid();
            target.AppId = StringFactory.NewGuid();
            target.Save();

            Operation targetoperation = new Operation();
            targetoperation.Code = StringFactory.NewGuid();
            targetoperation.AppId = StringFactory.NewGuid();
            targetoperation.TargetId = StringFactory.NewGuid();
            target.AddOperation(targetoperation);

            role.GivePermission(targetoperation);

            User user1 = User.GetUser(user.Account);

            Assert.IsNotNull(user.TargetList);

            user.Delete();
            role.Delete();
            org1.Delete();
            org1.CancelRole(role);
            target.Delete();
            target.RemoveOperation(targetoperation);
            role.CancelPermission(targetoperation);
        }
Esempio n. 5
0
        public void DeepRoleList()
        {
            User user = new User();
            user.Name = "test-add-user";
            user.Account = StringFactory.NewGuid();
            user.Save();

            Role role = Role.Create();
            role.Name = "test-giverole-role";
            role.Save();

            user.GiveRole(role);
            User user1 = User.GetUser(user.Account);
            var user2 = user1.DeepRoleList.Where(r => r.Code == role.Code); ;
            Assert.IsNotNull(user2);

            user1.CancelRole(role);
            role.Delete();
            user.Delete();
        }