public void EnvelopeCreateAddMemberWithDocumentTest()
        {
            ConfigLoader.LoadConfig();

            bool expected = true;
            bool actual = false;

            Account acct = new Account();
            acct.AccountName = Util.MakeUnique("ds client unit test {unique}");
            acct.Email = Util.MakeUnique("ds_client_unit_{unique}@gmail.com");
            acct.Password = "******";

            try
            {
                actual = acct.Create();
            }
            catch (Exception)
            {
            }

            Assert.AreEqual(expected, actual);
            AddUsers add = new AddUsers();
            List<NewUser> userList = new List<NewUser>();

            NewUser nu = new NewUser();
            nu.userName = Util.MakeUnique("ds client unit test member {unique}");
            nu.email = Util.MakeUnique("ds_client_unit_member_{unique}@gmail.com");
            nu.sendActivationOnInvalidLogin = false.ToString();
            nu.enableConnectForUser = true.ToString();
            Guid g = Guid.NewGuid();
            nu.password = g.ToString();

            List<UserSetting> userSettings = new List<UserSetting>();
            userSettings.Add(new UserSetting("canSendAPIRequests", "true"));
            userSettings.Add(new UserSetting("canSendEnvelope", "true"));
            userSettings.Add(new UserSetting("AllowSendOnBehalfOf", "true"));
            nu.userSettings = userSettings.ToArray();

            userList.Add(nu);
            add.newUsers = userList.ToArray();

            CreatedUsers added = null;

            try
            {
                added = acct.AddUser(add);
            }
            catch (Exception)
            {
            }

            Account member = new Account();
            member.ApiPassword = added.NewUsers[0].ApiPassword;
            member.AccountId = added.NewUsers[0].UserId;
            member.Email = added.NewUsers[0].Email;
            //member.BaseUrl = added.NewUsers[0].Uri;
            bool log = member.Login();

            Assert.IsNotNull(added);
            Envelope target = new Envelope();
            target.Login = member;
            FileInfo fi = new FileInfo("./Test Contract.pdf");
            string path = fi.FullName;

            actual = false;

            try
            {
                actual = target.Create(path);
            }
            catch (ArgumentNullException)
            {
            }

            Assert.AreEqual(expected, actual);
            Assert.IsFalse(string.IsNullOrEmpty(target.SenderViewUrl));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Serializes Json classes into a string
        /// </summary>
        /// <param name="user">NewUser object</param>
        /// <returns>json string</returns>
        private string ConstructNewUserJson(NewUser user)
        {
            try
            {
                if (string.IsNullOrEmpty(user.password.Trim()) == true)
                {
                    Guid g = Guid.NewGuid();
                    user.password = g.ToString();
                }

                AddUsers au = new AddUsers();
                List<NewUser> users = new List<NewUser>();
                users.Add(user);
                au.newUsers = users.ToArray();

                string output = au.Serialize();
                return output;
            }
            catch
            {
                return string.Empty;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a new user to an existing account
        /// </summary>
        /// <param name="users">Object representing the users to add</param>
        /// <returns>List of created users</returns>
        /// <exception cref="ArgumentNullException">If email, users or accountId are missing</exception>
        public CreatedUsers AddUser(AddUsers users)
        {
            if (users == null)
            {
                throw new ArgumentNullException("NewUser");
            }

            if (string.IsNullOrEmpty(this.Email) == true)
            {
                throw new ArgumentNullException("Email");
            }

            if (string.IsNullOrEmpty(this.AccountId) == true)
            {
                throw new ArgumentNullException("AccountId");
            }

            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "POST";
                req.LoginEmail = this.Email;
                req.LoginPassword = string.IsNullOrEmpty(this.ApiPassword) == false ? this.ApiPassword : this.Password;
                req.DistributorCode = RestSettings.Instance.DistributorCode;
                req.DistributorPassword = RestSettings.Instance.DistributorPassword;
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                string method = string.Format("/accounts/{0}/users?api_password=true", this.AccountId);

                if (String.IsNullOrEmpty(this.BaseUrl))
                {
                    req.Uri = string.Format("{0}{1}", RestSettings.Instance.WebServiceUrl, method);
                }
                else
                {
                    req.Uri = string.Format("{0}{1}", this.BaseUrl, "/users?api_password=true");
                }

                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder utils = new RequestBuilder();
                utils.Proxy = this.Proxy;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = users.Serialize();

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return null;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                utils.Request = req;
                ResponseInfo response = utils.MakeRESTRequest();

                this.Trace(utils, response);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                    return null;
                }

                return CreatedUsers.FromJson(response.ResponseText);
            }
            catch
            {
            }

            return null;
        }
Exemplo n.º 4
0
        public void AccountCreateAddUser()
        {
            ConfigLoader.LoadConfig();

            bool expected = true;
            bool actual = false;

            Account acct = new Account();
            acct.AccountName = Util.MakeUnique("ds client unit test {unique}");
            acct.Email = Util.MakeUnique("ds_client_unit_{unique}@gmail.com");
            acct.Password = "******";

            try
            {
                actual = acct.Create();
            }
            catch (Exception)
            {
            }

            Assert.AreEqual(expected, actual);
            AddUsers add = new AddUsers();
            List<NewUser> userList = new List<NewUser>();

            NewUser nu = new NewUser();
            nu.userName = Util.MakeUnique("ds client unit test member {unique}");
            nu.email = Util.MakeUnique("ds_client_unit_member_{unique}@gmail.com");
            nu.sendActivationOnInvalidLogin = false.ToString();
            nu.enableConnectForUser = true.ToString();
            Guid g = Guid.NewGuid();
            nu.password = g.ToString();

            List<UserSetting> userSettings = new List<UserSetting>();
            userSettings.Add(new UserSetting("canSendAPIRequests", "true"));
            userSettings.Add(new UserSetting("canSendEnvelope", "true"));
            userSettings.Add(new UserSetting("AllowSendOnBehalfOf", "true"));
            nu.userSettings = userSettings.ToArray();

            userList.Add(nu);
            add.newUsers = userList.ToArray();

            CreatedUsers added = null;

            try
            {
                added = acct.AddUser(add);
            }
            catch (Exception)
            {
            }

            Assert.IsNotNull(added);
        }