Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        public void RobotAddEditGetRemovePositional()
        {
            using (var runspace = PowershellFactory.CreateAuthenticatedSession(TestContext))
            {
                var  name        = TestRandom.RandomString();
                var  description = TestRandom.RandomString();
                var  licenseKey  = Guid.NewGuid();
                var  machine     = TestRandom.RandomString();
                var  username    = TestRandom.RandomString();
                long?robotId     = null;

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.AddUiPathRobot)
                    .AddParameter(UiPathStrings.Name, name)
                    .AddParameter(UiPathStrings.MachineName, machine)
                    .AddParameter(UiPathStrings.Description, description)
                    .AddParameter(UiPathStrings.LicenseKey, licenseKey)
                    .AddParameter(UiPathStrings.Username, username)
                    .AddParameter(UiPathStrings.Type, RobotDtoType.NonProduction);
                    var robots = Invoke <Robot>(cmdlet);

                    Validators.ValidateRobotResponse(robots, null, name, description, machine, licenseKey, RobotDtoType.NonProduction);

                    robotId = robots[0].Id;
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.EditUiPathRobot)
                    .AddParameter(UiPathStrings.Id, robotId)
                    .AddParameter(UiPathStrings.Password, TestRandom.RandomPassword())
                    .AddParameter(UiPathStrings.Type, RobotDtoType.Unattended);
                    Invoke <Robot>(cmdlet);
                }

                Robot robot = null;

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathRobot)
                    .AddParameter(UiPathStrings.Id, robotId);
                    var robots = Invoke <Robot>(cmdlet);

                    Validators.ValidateRobotResponse(robots, robotId, name, description, machine, licenseKey, RobotDtoType.Unattended);
                    robot = robots[0];
                }

                // Positional object Robot argument to Remove
                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.RemoveUiPathRobot)
                    .AddArgument(robot);
                    Invoke <Robot>(cmdlet);
                }

                using (var cmdlet = PowershellFactory.CreateCmdlet(runspace))
                {
                    cmdlet.AddCommand(UiPathStrings.GetUiPathRobot)
                    .AddParameter(UiPathStrings.Name, name);
                    var robots = Invoke <Robot>(cmdlet);

                    Validators.ValidatEmptyResponse(robots);
                }
            }
        }