Exemplo n.º 1
0
        public void AssignSharedSpaceAdminRoleToUserTest()
        {
            //FIND shared space admin role
            LogicalQueryPhrase roleLogicalName = new LogicalQueryPhrase(Role.LOGICAL_NAME_FIELD, "role.shared.space.admin");
            CrossQueryPhrase byRole = new CrossQueryPhrase(WorkspaceRole.ROLE_FIELD, roleLogicalName);
            List<QueryPhrase> queries = new List<QueryPhrase>();
            queries.Add(byRole);
            EntityListResult<WorkspaceRole> roles = entityService.Get<WorkspaceRole>(sharedSpaceContext, queries, null);
            Assert.AreEqual<int>(1, roles.total_count.Value);
            WorkspaceRole sharedSpaceAdminRole = roles.data[0];

            //CREATE USER
            SharedspaceUser createdUser = CreateUser();

            //UPDATE USER by adding shared space admin role
            SharedspaceUser userForUpdate = new SharedspaceUser(createdUser.Id);
            userForUpdate.WorkspaceRoles = createdUser.WorkspaceRoles;
            userForUpdate.WorkspaceRoles.data.Add(sharedSpaceAdminRole);
            entityService.Update<SharedspaceUser>(sharedSpaceContext, userForUpdate);

            //READ USER
            List<String> fields = new List<string> { SharedspaceUser.NAME_FIELD, SharedspaceUser.WORKSPACE_ROLES_FIELD };
            SharedspaceUser updatedUser = EntityService.GetInstance().GetById<SharedspaceUser>(sharedSpaceContext, createdUser.Id, fields);

            List<long> assignedWorkspaceRoles = updatedUser.WorkspaceRoles.data.Select(p => p.Id).ToList<long>();
            Assert.IsTrue(assignedWorkspaceRoles.Contains(sharedSpaceAdminRole.Id));
        }
Exemplo n.º 2
0
        private static SharedspaceUser CreateUser()
        {
            SharedspaceUser user = new SharedspaceUser();
            user.Name = "Name" + Guid.NewGuid() + "@hpe.com";
            user.Password = "******";
            user.LastName = "Last name";
            user.FirstName = "First name";
            user.Email = user.Name;
            user.Phone1 = "123-123-123";

            SharedspaceUser createdUser = entityService.Create<SharedspaceUser>(sharedSpaceContext, user);
            Assert.AreEqual<string>(user.Name, createdUser.Name);
            return createdUser;
        }