public void EnvelopeCreateNoAccount() { ConfigLoader.LoadConfig(); Envelope target = new Envelope(); bool expected = false; bool actual = false; try { actual = target.Create(string.Empty); } catch(ArgumentNullException) { } Assert.AreEqual(expected, actual); }
public void ReteivingAllDraftEnvelopesTest() { var envelope = new Envelope { Login = _account }; // add a draft envelope to be found later Assert.IsTrue(envelope.Create()); Assert.IsNull(envelope.RestError); Thread.Sleep(1000); // need to allow the system to fully create the envelope var accountEnvelopes = envelope.GetDraftEnvelopes(DateTime.Now.AddSeconds(-5)); Assert.IsNull(envelope.RestError); Assert.AreEqual(1, accountEnvelopes.Envelopes.Length, "We expect only 1 draft envelope in the last 5 seconds that was created by this unit test"); }
public void TemplateEndToEndTest() { Assert.IsTrue(string.IsNullOrEmpty(RestSettings.Instance.EmailSubject) == false, "Set the email subject for the envelope"); var template = new Template { Login = _account }; byte[] doc1 = { 36, 45, 34, 67, 121, 87, 99, 32, 32, 32, 54, 54, 55, 56, 32 }; var names = new List<string>(); var docs = new List<byte[]>(); names.Add("test1.doc"); docs.Add(doc1); // add recipients var signers = new List<Signer>(); signers.Add(new Signer { email = "*****@*****.**", name = "test test", recipientId = "1", roleName = "signer1", routingOrder = "1" }); signers.Add(new Signer { recipientId = "2", roleName = "signer2", routingOrder = "1" }); var recipients = new Recipients { signers = signers.ToArray() }; template.Recipients = recipients; Assert.IsTrue(template.CreateTemplate(docs, names, "DocuSign.NET Client Unit Test Template")); Assert.IsNull(template.RestError); // Note that EnvelopeId for a template is the TemplateId... // start a new envelope var templateId = template.EnvelopeId; var envelope = new Envelope { Login = _account }; Assert.IsTrue(envelope.Create()); // add the template var templates = new List<string>(); templates.Add(template.EnvelopeId); Assert.IsTrue(envelope.AddTemplates(templates)); Assert.IsNull(template.RestError); // update recipients recipients.signers[1].name = "test test2"; recipients.signers[1].email = "*****@*****.**"; Assert.IsTrue(envelope.UpdateRecipients(recipients, false)); Assert.IsNull(template.RestError); // send envelope envelope.Status = "sent"; Assert.IsTrue(envelope.UpdateStatus()); Assert.IsNull(template.RestError); }
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)); }
public void EnvelopeCreateNotLoggedIn() { ConfigLoader.LoadConfig(); bool expected = false; bool actual = false; Envelope target = new Envelope(); Account acct = new Account(); acct.AccountName = Util.MakeUnique("freakin me out {unique}"); acct.Email = Util.MakeUnique("freakin_{unique}@gmail.com"); acct.Password = "******"; try { target.Login = acct; actual = target.Create(string.Empty); } catch(ArgumentNullException) { } Assert.AreEqual(expected, actual); }
public void AddRemoveDocumentsFromEnvelopeTest() { var envelope = new Envelope { Login = _account }; // add a draft envelope to be found later Assert.IsTrue(envelope.Create()); Assert.IsNull(envelope.RestError); // no docs yet Assert.AreEqual(0, envelope.GetDocIds(envelope.EnvelopeId).Count); // add a doc byte[] doc1 = { 36, 45, 34, 67, 121, 87, 99, 32, 32, 32, 54, 54, 55, 56, 32 }; Assert.IsTrue(envelope.AddDocument(doc1, "test1.doc", 1)); Assert.IsNull(envelope.RestError); // we should have exactly 1 doc now Assert.AreEqual(1, envelope.GetDocIds(envelope.EnvelopeId).Count); Assert.AreEqual("test1.doc", envelope.GetDocNames(envelope.EnvelopeId).First()); var envelopeDocuments = envelope.GetEnvelopeDocumentInfo(envelope.EnvelopeId); Assert.AreEqual(envelopeDocuments.envelopeId, envelope.EnvelopeId); Assert.AreEqual(envelopeDocuments.envelopeDocuments[0].name, "test1.doc"); Assert.AreEqual(envelopeDocuments.envelopeDocuments[0].documentId, "1"); // remove the doc Assert.IsTrue(envelope.RemoveDocument(1)); Assert.IsNull(envelope.RestError); // back to having no docs Assert.AreEqual(0, envelope.GetDocIds(envelope.EnvelopeId).Count); }
//========================================================================================== // *** Walkthrough #4 - Request Signature on Document //========================================================================================== private void SignatureRequestOnDocument() { //***************************************************************** // ENTER VALUES FOR FOLLOWING VARIABLES! //***************************************************************** string AccountEmail = "***"; string AccountPassword = "******"; string RecipientEmail = "***"; string RecipientName = "***"; string documentPath = "***"; //***************************************************************** // user credentials Account account = new Account(); account.Email = AccountEmail; account.Password = AccountPassword; // make the login call (retrieves your baseUrl and accountId) bool result = account.Login(); if (!result) { Console.WriteLine("Login API call failed for user {0}.\nError Code: {1}\nMessage: {2}", account.Email, account.RestError.errorCode, account.RestError.message); return; } // create envelope object and assign login info Envelope envelope = new Envelope(); envelope.Login = account; // add one signer to the envelope envelope.Recipients = new Recipients() { signers = new Signer[] { new Signer() { email = RecipientEmail, name = RecipientName, routingOrder = "1", recipientId = "1" } } }; // send the envelope immediately (otherwise set to "created" to save as draft envelope) envelope.Status = "sent"; // email subject is required envelope.EmailSubject = "DocuSign .NET Client - Signature Request on Document"; // create envelope and send the signature request (since status is set to "sent") result = envelope.Create(documentPath); if (!result) { if (envelope.RestError != null) { Console.WriteLine("Error code: {0}\nMessage: {1}", envelope.RestError.errorCode, envelope.RestError.message); return; } else { Console.WriteLine("Error encountered while requesting signature from template, please review your envelope and recipient data."); return; } } else { Console.WriteLine("Signature request has been sent to {0}, envelopeId is {1}.", envelope.Recipients.signers[0].email, envelope.EnvelopeId); } }
public void EnvelopeCreateNoDocument() { ConfigLoader.LoadConfig(); bool expected = true; bool actual = true; Account acct = new Account(); acct.AccountName = Util.MakeUnique("freakin me out {unique}"); acct.Email = Util.MakeUnique("freakin_{unique}@gmail.com"); acct.Password = "******"; try { actual = acct.Create(); } catch (Exception) { } Assert.AreEqual(expected, actual); Assert.IsFalse(string.IsNullOrEmpty(acct.BaseUrl)); Envelope target = new Envelope(); target.Login = acct; actual = false; try { actual = target.Create(string.Empty); } catch (ArgumentNullException) { } Assert.AreEqual(expected, actual); Assert.IsFalse(string.IsNullOrEmpty(target.SenderViewUrl)); }
public void EnvelopeCustomFieldsTest() { var envelope = new Envelope { Login = _account }; byte[] doc1 = { 36, 45, 34, 67, 121, 87, 99, 32, 32, 32, 54, 54, 55, 56, 32 }; var signers = new List<Signer>(); signers.Add(new Signer { email = "*****@*****.**", name = "test2", recipientId = "1", routingOrder = "1" }); envelope.Recipients = new Recipients { signers = signers.ToArray() }; Assert.IsTrue(envelope.Create(doc1, "test-self-signed.doc")); Assert.IsNull(envelope.RestError); var fields = new Dictionary<string, object>(); fields.Add("time", DateTime.Now); fields.Add("isUnitTest", true); fields.Add("unitTestName", "EnvelopeCustomFieldsTest"); Assert.IsTrue(envelope.AddCustomFields(fields)); Assert.IsNull(envelope.RestError); Assert.IsTrue(envelope.GetCustomFields()); Assert.IsNull(envelope.RestError); Assert.AreEqual(3, envelope.CustomFields.textCustomFields.Length); Assert.AreEqual("True", envelope.CustomFields.textCustomFields[1].value); }
public void AddEmailSubjectAndBlurbToExisitingEnvelopeAndVeryifyStatusTest() { var envelope = new Envelope { Login = _account }; byte[] doc1 = { 36, 45, 34, 67, 121, 87, 99, 32, 32, 32, 54, 54, 55, 56, 32 }; var signers = new List<Signer>(); signers.Add(new Signer { email = "*****@*****.**", name = "test2", recipientId = "1", routingOrder = "1" }); envelope.Recipients = new Recipients { signers = signers.ToArray()}; Assert.IsTrue(envelope.Create(doc1, "test-self-signed.doc")); Assert.IsNull(envelope.RestError); Assert.IsTrue(envelope.AddEmailInformation("DocuSign Client Tests Message", "DocuSign Client Tests Message")); Assert.IsNull(envelope.RestError); var time = envelope.GetStatus(envelope.EnvelopeId); Assert.AreEqual("created", envelope.Status); // envelope was created very recently... Assert.IsTrue(DateTime.Now.Subtract(time).Ticks < 10000); // send envelope envelope.Status = "sent"; envelope.UpdateStatus(); }
public void RecipientsEndToEndTest() { var envelope = new Envelope { Login = _account }; byte[] doc1 = { 36, 45, 34, 67, 121, 87, 99, 32, 32, 32, 54, 54, 55, 56, 32 }; var signers = new List<Signer>(); var ccs = new List<Signer>(); signers.Add(new Signer { email = "*****@*****.**", name = "test2", recipientId = "1", routingOrder = "1" }); ccs.Add(new Signer { email = _account.Email, name = _account.AccountName, recipientId = "2", routingOrder = "2" }); envelope.Recipients = new Recipients { signers = signers.ToArray(), carbonCopies = ccs.ToArray() }; Assert.IsTrue(envelope.Create(doc1, "test-self-signed.doc")); Assert.IsNull(envelope.RestError); Assert.AreEqual(2, envelope.GetRecipientNames().Count()); // add more recipients signers.Clear(); ccs.Clear(); ccs.Add(new Signer { email = "*****@*****.**", name = "test2", recipientId = "3", routingOrder = "4" }); signers.Add(new Signer { email = _account.Email, name = _account.AccountName, recipientId = "4", routingOrder = "3" }); Assert.IsTrue(envelope.AddRecipients(new Recipients { signers = signers.ToArray(), carbonCopies = ccs.ToArray() })); Assert.IsNull(envelope.RestError); Assert.AreEqual(4, envelope.GetRecipientNames().Count()); Assert.AreEqual((string)(envelope.GetFirstRecipients().First()["email"]), "*****@*****.**"); }
public void CreateEnvelopeFromStreamTest() { var envelope = new Envelope { Login = _account }; byte[] byteArray = { 36, 45, 34, 67, 121, 87, 99, 32, 32, 32, 54, 54, 55, 56, 32 }; var doc1 = new MemoryStream(byteArray); envelope.Status = "sent"; var signers = new List<Signer>(); signers.Add(new Signer { email = _account.Email, name = _account.AccountName, recipientId = "1", routingOrder = "1" }); envelope.Recipients = new Recipients { signers = signers.ToArray() }; Assert.IsTrue(envelope.Create(doc1, "test-self-signed.doc")); Assert.IsNull(envelope.RestError); Assert.IsTrue(envelope.GetRecipientView()); Assert.IsNull(envelope.RestError); // note SenderViewUrl in this case is the Signer view (Recipient) Assert.IsNotNull(envelope.SenderViewUrl); }
//========================================================================================== // *** Walkthrough #1 - Request Signature from Template //========================================================================================== private void SignatureRequestFromTemplate() { //***************************************************************** // ENTER VALUES FOR FOLLOWING VARIABLES! //***************************************************************** string AccountEmail = "***"; string AccountPassword = "******"; string RecipientEmail = "***"; string RecipientName = "***"; string TemplateId = "***"; string TemplateRoleName = "***"; //***************************************************************** // user credentials Account account = new Account(); account.Email = AccountEmail; account.Password = AccountPassword; // make the login call (retrieves your baseUrl and accountId) bool result = account.Login(); if (!result) { Console.WriteLine("Login API call failed for user {0}.\nError Code: {1}\nMessage: {2}", account.Email, account.RestError.errorCode, account.RestError.message); return; } // create envelope object and assign login info Envelope envelope = new Envelope(); envelope.Login = account; // use an existing server template envelope.TemplateId = TemplateId; // add one signer to a template role identified by roleName envelope.TemplateRoles = new TemplateRole[] { new TemplateRole() { email = RecipientEmail, name = RecipientName, roleName = TemplateRoleName } }; // Email subject is a required parameter when requesting signatures envelope.EmailSubject = "DocuSign .NET Client - Signature Request from Template"; // "sent" to send immediately, "created" to save envelope as draft envelope.Status = "sent"; // create and send the envelope (since status is set to "sent") result = envelope.Create(); if (!result) { if (envelope.RestError != null) { Console.WriteLine("Error code: {0}\nMessage: {1}", envelope.RestError.errorCode, envelope.RestError.message); return; } else { Console.WriteLine("Error encountered while requesting signature from template, please review your envelope and recipient data."); return; } } else { Console.WriteLine("Signature request has been sent to {0}, envelopeId is {1}", envelope.TemplateRoles[0].email, envelope.EnvelopeId); } }
//========================================================================================== // *** Walkthrough #7 - Embedded Sending //========================================================================================== private void EmbeddedSending() { //***************************************************************** // ENTER VALUES FOR FOLLOWING VARIABLES! //***************************************************************** string AccountEmail = "***"; string AccountPassword = "******"; string documentPath = "***"; //***************************************************************** // user credentials Account account = new Account(); account.Email = AccountEmail; account.Password = AccountPassword; // make the login call (retrieves your baseUrl and accountId) bool result = account.Login(); if (!result) { Console.WriteLine("Login API call failed for user {0}.\nError Code: {1}\nMessage: {2}", account.Email, account.RestError.errorCode, account.RestError.message); return; } // create envelope object and assign login info Envelope envelope = new Envelope(); envelope.Login = account; // create a new DocuSign envelope (i.e. server side) envelope.Create(documentPath); // generate sender view token result = envelope.GetSenderView("http://www.nuget.org/packages/DocuSign.Integration.Client.dll/"); if (!result) { if (envelope.RestError != null) { Console.WriteLine("Error code: {0}\nMessage: {1}", envelope.RestError.errorCode, envelope.RestError.message); return; } else { Console.WriteLine("Error encountered retrieving signing token, please review your envelope and recipient data."); return; } } else { // open the envelope's sending view Process.Start(envelope.SenderViewUrl); } }
public void EnvelopeCreateWithDocumentTest() { ConfigLoader.LoadConfig(); bool expected = true; bool actual = false; Account acct = new Account(); acct.AccountName = Util.MakeUnique("freakin me out {unique}"); acct.Email = Util.MakeUnique("freakin_{unique}@gmail.com"); acct.Password = "******"; AddressInformation ai = new AddressInformation(); acct.Address = ai; ai.address1 = "123 Main ST"; ai.address2 = string.Empty; ai.city = "Anytown"; ai.country = "USA"; ai.postalCode = "11111"; ai.state = "WA"; CreditCardInformation cc = new CreditCardInformation(); acct.CreditCard = cc; cc.cardNumber = "4111111111111111"; cc.cardType = "visa"; cc.expirationMonth = "12"; cc.expirationYear = "2015"; cc.nameOnCard = "Freak Me Out"; try { actual = acct.Create(); } catch (Exception) { } Assert.AreEqual(expected, actual); Assert.IsFalse(string.IsNullOrEmpty(acct.BaseUrl)); Envelope target = new Envelope(); target.Login = acct; 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)); }
public void EnvelopeCreateWithSmsAuthenticationDocumentTest() { ConfigLoader.LoadConfig(); bool expected = true; bool actual = false; Account acct = new Account(); acct.AccountName = Util.MakeUnique("freakin me out {unique}"); acct.Email = Util.MakeUnique("freakin_{unique}@gmail.com"); acct.Password = "******"; AddressInformation ai = new AddressInformation(); acct.Address = ai; ai.address1 = "123 Main ST"; ai.address2 = string.Empty; ai.city = "Anytown"; ai.country = "USA"; ai.postalCode = "11111"; ai.state = "WA"; CreditCardInformation cc = new CreditCardInformation(); acct.CreditCard = cc; cc.cardNumber = "4111111111111111"; cc.cardType = "visa"; cc.expirationMonth = "12"; cc.expirationYear = "2015"; cc.nameOnCard = "Freak Me Out"; try { actual = acct.Create(); } catch (Exception) { } Assert.AreEqual(expected, actual); Assert.IsFalse(string.IsNullOrEmpty(acct.BaseUrl)); if (expected == actual) { Envelope target = new Envelope(); target.Login = acct; // add signers to the envelope target.Recipients = new Recipients() { signers = new Signer[] { new Signer() { email = "freakin_{unique}@gmail.com", name = "freakin", routingOrder = "1", recipientId = "1", requireIdLookup = "true", idCheckConfigurationName = "SMS Auth $", smsAuthentication = new SmsAuthentication() { senderProvidedNumbers = new string[] { String.Format("+{0} {1}", "34", "000000000") } } } } }; // Email subject is a required parameter when requesting signatures target.EmailSubject = "Example subject"; // "sent" to send immediately, "created" to save envelope as draft target.Status = "sent"; 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)); } }
public void EmbeddedSigningViewTest() { // create a new envelope with 2 recipients var envelope = new Envelope { Login = _account }; byte[] doc1 = { 36, 45, 34, 67, 121, 87, 99, 32, 32, 32, 54, 54, 55, 56, 32 }; var signers = new List<Signer>(); // note we need to specify clientUserId signers.Add(new Signer { email = "*****@*****.**", name = "test1", recipientId = "1", routingOrder = "1", clientUserId = "1" }); signers.Add(new Signer { email = "*****@*****.**", name = "test2", recipientId = "2", routingOrder = "2", clientUserId = "2" }); envelope.Recipients = new Recipients { signers = signers.ToArray() }; Assert.IsTrue(envelope.Create(doc1, "test-self-signed.doc")); Assert.IsNull(envelope.RestError); // send it envelope.Status = "sent"; Assert.IsTrue(envelope.UpdateStatus()); Assert.IsNull(envelope.RestError); // get embedded signing views for 2 recipients string urlForfirstSigner = envelope.GetEmbeddedSignerView("www.docusign.com", signers.First()); Assert.IsNull(envelope.RestError); Assert.IsFalse(string.IsNullOrEmpty(urlForfirstSigner)); string urlForSecondSigner = envelope.GetEmbeddedSignerView("www.docusign.com", signers.Last()); // now, this one won't work until first one signed (which cannot happen in this test) // this is because second recpieint was set to sign only after the first one finished (routing order) Assert.IsTrue(string.IsNullOrEmpty(urlForSecondSigner)); }
public void EnvelopeCreateWithDocumentObjectsAndGetDocumentFieldsTest() { const bool expected = true; const string expectedDocumentAttributeName = "Document Attribute Name"; const string expectedDocumentAttributeValue = "Document Attribute Value"; var actual = false; Assert.IsFalse(string.IsNullOrEmpty(_account.BaseUrl)); var target = new Envelope { Login = _account }; var fi = new FileInfo("./Test Contract.pdf"); var documentCustomFields = new List<DocumentField> { new DocumentField {name = expectedDocumentAttributeName, value = expectedDocumentAttributeValue} }; var documents = new List<Document> { new Document { attachmentDescription = fi.Name.Replace(fi.Extension, string.Empty), documentId = "1", documentFields = documentCustomFields.ToArray(), fileExtension = fi.Extension, name = fi.Name } }; var fileBytes = new List<Byte[]> { File.ReadAllBytes(fi.FullName) }; try { actual = target.Create(fileBytes, documents); } catch (ArgumentNullException) { } Assert.AreEqual(expected, actual); Assert.IsFalse(string.IsNullOrEmpty(target.SenderViewUrl)); var actualDocuments = target.GetDocuments(); Assert.AreEqual(documents.Count, actualDocuments.Count); for (var i = 0; i < documents.Count; i++) { Assert.AreEqual(documents[i].documentId, actualDocuments[i].documentId); Assert.AreEqual(documents[i].name, actualDocuments[i].name); var fields = target.GetDocumentFields(documents[i].documentId); Assert.AreEqual(documents[i].documentFields.Count(), fields.documentFields.Count()); for (var j = 0; j < documents[i].documentFields.Count(); j++) { Assert.AreEqual(documents[i].documentFields[j].name, fields.documentFields[j].name); Assert.AreEqual(documents[i].documentFields[j].value, fields.documentFields[j].value); } } }
public Envelope CreateEnvelope(ApplicationUser user, TemplateInfo templateInfo, string parentUserId) { try { if (user == null) throw new ArgumentNullException("user"); if (templateInfo == null) throw new ArgumentNullException("templateInfo"); var envelope = new Envelope { Login = Account, EmailSubject = user.Company, Status = "sent", TemplateId = templateInfo.Id, TemplateRoles = new[] { new TemplateRole { email = user.Email, name = string.Concat(user.FirstName, " ", user.LastName), roleName = "Signer", clientUserId = user.Id } } }; envelope.Create(); if (envelope.EnvelopeId != null) { _context.Envelopes.Add(new Envelopes { EnvelopeId = envelope.EnvelopeId, EnvelopeName = templateInfo.Name, UserId = parentUserId }); _context.SaveChanges(); return envelope; } } catch (Exception ex) { throw ex; } return null; }