public void FolderAddGetRemove()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                var    displayName   = TestRandom.RandomAlphaNumeric();
                var    description   = TestRandom.RandomAlphaNumeric();
                long?  folderId      = null;
                Folder currentFolder = null;
                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.AddFolder)
                    .AddParameter(UiPathStrings.DisplayName, displayName)
                    .AddParameter(UiPathStrings.Description, description)
                    .AddParameter(UiPathStrings.PermissionModel, FolderDtoPermissionModel.FineGrained)
                    .AddParameter(UiPathStrings.ProvisionType, FolderDtoProvisionType.Automatic);
                    var folders = Invoke <Folder>(cmdlet);

                    Validators.ValidateFolderResponse(folders, null, displayName, description, FolderDtoProvisionType.Automatic, FolderDtoPermissionModel.FineGrained);

                    folderId = folders[0].Id;
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetFolder)
                    .AddParameter(UiPathStrings.Id, folderId);
                    var folders = Invoke <Folder>(cmdlet);
                    currentFolder = folders[0];

                    Validators.ValidateFolderResponse(folders, folderId, displayName, description, FolderDtoProvisionType.Automatic, FolderDtoPermissionModel.FineGrained);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    var updatedDisplayName = TestRandom.RandomString();
                    cmdlet.AddCommand(UiPathStrings.EditFolder)
                    .AddArgument(currentFolder)
                    .AddParameter(UiPathStrings.DisplayName, updatedDisplayName);
                    Invoke <Folder>(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveFolder)
                    .AddParameter(UiPathStrings.Id, folderId);
                    Invoke(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetFolder)
                    .AddParameter(UiPathStrings.DisplayName, displayName);
                    var folders = Invoke <Folder>(cmdlet);
                    Validators.ValidatEmptyResponse(folders);
                }
            }
        }
        public void UserAddGetRemove()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                User        user     = default(User);
                var         userName = TestRandom.RandomAlphaNumeric();
                var         password = TestRandom.RandomPassword();
                var         name     = TestRandom.RandomString();
                var         surname  = TestRandom.RandomString();
                var         email    = TestRandom.RandomEmail();
                UserDtoType userType = UserDtoType.User;

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.AddUiPathUser)
                    .AddParameter(UiPathStrings.Username, userName)
                    .AddParameter(UiPathStrings.Password, password)
                    .AddParameter(UiPathStrings.Name, name)
                    .AddParameter(UiPathStrings.Surname, surname)
                    .AddParameter(UiPathStrings.EmailAddress, email)
                    .AddParameter(UiPathStrings.Type, userType)
                    .AddParameter(UiPathStrings.RolesList, new List <string>()
                    {
                        UiPathStrings.Administrator
                    });
                    var users = Invoke <User>(cmdlet);
                    Validators.ValidateUserResponse(users, null, userName, password, name, surname, email, userType);
                    user = users[0];
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathUser)
                    .AddParameter(UiPathStrings.Id, user.Id);
                    var users = Invoke <User>(cmdlet);
                    Validators.ValidateUserResponse(users, user.Id, userName, password, name, surname, email, userType);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveUiPathUser)
                    .AddParameter(UiPathStrings.Id, user.Id);
                    Invoke(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathUser)
                    .AddParameter(UiPathStrings.Username, userName);
                    var users = Invoke <User>(cmdlet);
                    Validators.ValidatEmptyResponse(users);
                }
            }
        }
        public void RoleAddGetRemove()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                Role role       = default(Role);
                var  name       = TestRandom.RandomAlphaNumeric();
                var  displaName = TestRandom.RandomString();

                var permissions = new List <string>()
                {
                    "Robots.View",
                    "Robots.Edit",
                    "Robots.Create",
                    "Robots.Delete"
                };

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.AddUiPathRole)
                    .AddParameter(UiPathStrings.Name, name)
                    //.AddParameter(UiPathStrings.DisplayName, displaName)  -- bugbug: the displayname is ignored by Orchestrator
                    .AddParameter(UiPathStrings.IsEditable)
                    .AddParameter(UiPathStrings.Permissions, permissions);
                    var roles = Invoke <Role>(cmdlet);
                    Validators.ValidateRoleResult(roles, null, name, name, true, false, null);
                    role = roles[0];
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathRole)
                    .AddParameter(UiPathStrings.Name, role.Name);
                    var roles = Invoke <Role>(cmdlet);
                    Validators.ValidateRoleResult(roles, role.Id, name, name, true, false, permissions);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveUiPathRole)
                    .AddParameter(UiPathStrings.Id, role.Id);
                    Invoke(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathRole)
                    .AddParameter(UiPathStrings.Name, role.Name);
                    var roles = Invoke <Role>(cmdlet);
                    Validators.ValidatEmptyResponse(roles);
                }
            }
        }
        public void CurrentUserFolders()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                var displayName = TestRandom.RandomAlphaNumeric();
                var description = TestRandom.RandomAlphaNumeric();
                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetCurrentUserFolders);
                    var folders = Invoke <ExtendedFolder>(cmdlet);

                    Assert.IsNotNull(folders);
                }
            }
        }