private async Task <Tuple <ActivityDTO, Guid> > AuthorizeAndConfigureDocuSignActivity(ActivityDTO docuSignActivity)
        {
            var crateStorage           = Crate.GetStorage(docuSignActivity);
            var authenticationRequired = crateStorage.CratesOfType <StandardAuthenticationCM>().Any();
            var tokenId = Guid.Empty;

            if (authenticationRequired)
            {
                var terminalSummaryDTO = new TerminalSummaryDTO
                {
                    Name    = docuSignActivity.ActivityTemplate.TerminalName,
                    Version = docuSignActivity.ActivityTemplate.TerminalVersion
                };
                // Authenticate with DocuSign
                tokenId = await _docuSignTestTools.AuthenticateDocuSignAndAssociateTokenWithAction(docuSignActivity.Id, GetDocuSignCredentials(), terminalSummaryDTO);

                docuSignActivity = await Configure(docuSignActivity);
            }
            docuSignActivity.UpdateControls <Send_DocuSign_Envelope_v2.ActivityUi>(x => x.TemplateSelector.SelectByKey("SendEnvelopeTestTemplate"));
            //This configuration call will generate text source fields for selected template properties
            docuSignActivity = await Configure(docuSignActivity);

            docuSignActivity.UpdateControls <Send_DocuSign_Envelope_v2.ActivityUi>(x =>
            {
                var roleEmailControl         = x.RolesFields.First(y => y.Name == "TestSigner role email");
                roleEmailControl.ValueSource = TextSource.UpstreamValueSrouce;
                roleEmailControl.selectedKey = "SuppliedEmail";
                roleEmailControl.Value       = "SuppliedEmail";

                var roleNameControl         = x.RolesFields.First(y => y.Name == "TestSigner role name");
                roleNameControl.ValueSource = TextSource.UpstreamValueSrouce;
                roleNameControl.selectedKey = "SuppliedName";
                roleNameControl.Value       = "SuppliedName";
            });
            return(new Tuple <ActivityDTO, Guid>(await Save(docuSignActivity), tokenId));
        }
Esempio n. 2
0
        /// <summary>
        /// Authenticate to DocuSign and accociate generated token with activity
        /// </summary>
        /// <param name="activityId"></param>
        /// <param name="credentials"></param>
        /// <param name="terminalId"></param>
        /// <returns></returns>
        public async Task <Guid> AuthenticateDocuSignAndAssociateTokenWithAction(Guid activityId, CredentialsDTO credentials, TerminalSummaryDTO terminalDTO)
        {
            //
            // Authenticate with DocuSign Credentials
            //
            var authTokenDTO = await GenerateAuthToken(credentials.Username, credentials.Password, terminalDTO);

            var tokenGuid = Guid.Parse(authTokenDTO.Token);

            //
            // Asociate token with action
            //
            var applyToken = new AuthenticationTokenGrantDTO()
            {
                ActivityId  = activityId,
                AuthTokenId = tokenGuid,
                IsMain      = true
            };
            await _baseHubITest.HttpPostAsync <AuthenticationTokenGrantDTO[], string>(_baseHubITest.GetHubApiBaseUrl() + "authentication/tokens/grant", new[] { applyToken });

            return(tokenGuid);
        }
Esempio n. 3
0
        /// <summary>
        /// Helper method for creating new Mail_Merge_Into_DocuSign solution and configure that solution with chosen data source and docuSign template.
        /// After solution is created, check for authentication and authenticate if needed to DocuSign.
        /// </summary>
        /// <param name="dataSourceValue">Value property for DataSource dropDownList</param>
        /// <param name="dataSourceSelectedKey">selectedKey property for DataSource dropdownList</param>
        /// <param name="docuSignTemplateValue">Value property for DocuSignTemplate dropDownList</param>
        /// <param name="docuSignTemplateSelectedKey">>selectedKey property for DocuSignTemplate dropdownList</param>
        /// <param name="addNewDocuSignTemplate">add provided DocuSign Template values as new ListItem in DocuSignTemplate DropDownList</param>
        /// <returns>
        ///  Objects that are created from this solution and can be reused for different scenarios
        ///   Item1 from Tuple: new created Mail_Merge_Into_DocuSign solution as ActivityDTO with all children activities inside.
        ///   Item2 from Tuple: new created Plan associated with Mail_Merge_Into_DocuSign solution.
        ///   Item3 from Tuple: authorizationTokenId returned from DocuSign authentication process
        /// </returns>
        public async Task <Tuple <ActivityDTO, PlanDTO, Guid> > CreateAndConfigure_MailMergeIntoDocuSign_Solution(string dataSourceValue,
                                                                                                                  string dataSourceSelectedKey, string docuSignTemplateValue, string docuSignTemplateSelectedKey, bool addNewDocuSignTemplate)
        {
            var solutionCreateUrl = _baseHubITest.GetHubApiBaseUrl() + "plans?solutionName=Mail_Merge_Into_DocuSign";

            //
            // Create solution
            //
            var plan = await _baseHubITest.HttpPostAsync <string, PlanDTO>(solutionCreateUrl, null);

            var solution = plan.SubPlans.FirstOrDefault().Activities.FirstOrDefault();

            //
            // Send configuration request without authentication token
            //
            solution = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/configure?id=" + solution.Id, solution);

            var  crateStorage = _baseHubITest.Crate.FromDto(solution.CrateStorage);
            var  stAuthCrate  = crateStorage.CratesOfType <StandardAuthenticationCM>().FirstOrDefault();
            bool defaultDocuSignAuthTokenExists = stAuthCrate == null;

            var tokenGuid = Guid.Empty;

            if (!defaultDocuSignAuthTokenExists)
            {
                var terminalSummaryDTO = new TerminalSummaryDTO
                {
                    Name    = solution.ActivityTemplate.TerminalName,
                    Version = solution.ActivityTemplate.TerminalVersion
                };
                // Authenticate with DocuSign
                tokenGuid = await _terminalDocuSignTestTools.AuthenticateDocuSignAndAssociateTokenWithAction(solution.Id, _baseHubITest.GetDocuSignCredentials(), terminalSummaryDTO);
            }

            //
            // Send configuration request with authentication token
            //
            solution = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/configure?id=" + solution.Id, solution);

            crateStorage = _baseHubITest.Crate.FromDto(solution.CrateStorage);
            Assert.True(crateStorage.CratesOfType <StandardConfigurationControlsCM>().Any(), "Crate StandardConfigurationControlsCM is missing in API response.");

            //
            // Followup configuration
            //
            var controlsCrate = crateStorage.CratesOfType <StandardConfigurationControlsCM>().First();
            var controls      = controlsCrate.Content.Controls;
            //
            // Set dataSource value and Key, Example "Get_Google_Sheet_Data", "Load_Excel_File"...
            //
            var dataSource = controls.OfType <DropDownList>().FirstOrDefault(c => c.Name == "DataSource");

            dataSource.Value       = dataSourceValue;
            dataSource.selectedKey = dataSourceSelectedKey;
            //
            // Set DocuSign template value
            //
            var template = controls.OfType <DropDownList>().FirstOrDefault(c => c.Name == "DocuSignTemplate");

            template.Value       = docuSignTemplateValue;
            template.selectedKey = docuSignTemplateSelectedKey;
            if (addNewDocuSignTemplate)
            {
                template.ListItems.Add(new ListItem()
                {
                    Value = docuSignTemplateValue, Key = docuSignTemplateSelectedKey
                });
            }

            var button = controls.OfType <Button>().FirstOrDefault();

            button.Clicked = true;

            //
            //Rename plan to include a dateTimeStamp in the name
            //
            var newName = plan.Name + " | " + DateTime.UtcNow.ToShortDateString() + " " +
                          DateTime.UtcNow.ToShortTimeString();
            await _baseHubITest.HttpPostAsync <object, PlanDTO>(_baseHubITest.GetHubApiBaseUrl() + "plans?id=" + plan.Id,
                                                                new { id = plan.Id, name = newName });

            //
            // Configure solution
            //
            using (var crateStorageTemp = _baseHubITest.Crate.GetUpdatableStorage(solution))
            {
                crateStorageTemp.Remove <StandardConfigurationControlsCM>();
                crateStorageTemp.Add(controlsCrate);
            }
            solution = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/configure?id=" + solution.Id, solution);

            Assert.AreEqual(2, solution.ChildrenActivities.Count(), "Solution child actions failed to create.");

            return(new Tuple <ActivityDTO, PlanDTO, Guid>(solution, plan, tokenGuid));
        }
Esempio n. 4
0
        /// <summary>
        /// Generate new DocuSign authorization token from provided credentials
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="terminalId"></param>
        /// <returns></returns>
        public async Task <AuthorizationTokenDTO> GenerateAuthToken(string username, string password, TerminalSummaryDTO terminalDTO)
        {
            var creds = new CredentialsDTO()
            {
                Username      = username,
                Password      = password,
                IsDemoAccount = true,
                Terminal      = terminalDTO
            };

            var token = await _baseHubITest.HttpPostAsync <CredentialsDTO, JObject>(_baseHubITest.GetHubApiBaseUrl() + "authentication/token", creds);

            Assert.AreNotEqual(token["error"].ToString(), "Unable to authenticate in DocuSign service, invalid login name or password.",
                               "DocuSign auth error. Perhaps max number of tokens is exceeded.");
            Assert.AreEqual(false, String.IsNullOrEmpty(token["authTokenId"].Value <string>()),
                            "AuthTokenId is missing in API response.");

            Guid tokenGuid = Guid.Parse(token["authTokenId"].Value <string>());

            return(await Task.FromResult(new AuthorizationTokenDTO { Token = tokenGuid.ToString() }));
        }
Esempio n. 5
0
        public async Task <ActivityDTO> AddAndConfigure_QueryDocuSign(PlanDTO plan, int ordering, int version = 1)
        {
            var queryDocuSignActivity = FixtureData.Query_DocuSign_v1_InitialConfiguration();
            var activityTemplates     = await _baseHubITest.HttpGetAsync <ActivityTemplateCategoryDTO[]>(_baseHubITest.GetHubApiBaseUrl() + "/activity_templates");

            var apmActivityTemplate = activityTemplates
                                      .SelectMany(a => a.Activities)
                                      .Select(x => new ActivityTemplateSummaryDTO
            {
                Name            = x.Name,
                Version         = x.Version,
                TerminalName    = x.Terminal.Name,
                TerminalVersion = x.Terminal.Version
            })
                                      .FirstOrDefault(a => a.Name == "Query_DocuSign" && a.Version == version.ToString());

            if (apmActivityTemplate == null)
            {
                throw new Exception("Unable to find template for Query_DocuSign v1");
            }

            queryDocuSignActivity.ActivityTemplate = apmActivityTemplate;

            //connect current activity with a plan
            var subPlan = plan.SubPlans.FirstOrDefault();

            queryDocuSignActivity.ParentPlanNodeId = subPlan.SubPlanId;
            queryDocuSignActivity.RootPlanNodeId   = plan.Id;
            queryDocuSignActivity.Ordering         = ordering;

            //call initial configuration to server
            queryDocuSignActivity = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/save", queryDocuSignActivity);

            //this call is without authtoken
            queryDocuSignActivity = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/configure", queryDocuSignActivity);

            var initialcrateStorage = _baseHubITest.Crate.FromDto(queryDocuSignActivity.CrateStorage);

            var stAuthCrate = initialcrateStorage.CratesOfType <StandardAuthenticationCM>().FirstOrDefault();

            ;

            //if (!defaultDocuSignAuthTokenExists)
            //{
            var terminalDocuSignTools = new Fr8.Testing.Integration.Tools.Terminals.IntegrationTestTools_terminalDocuSign(_baseHubITest);
            // queryDocuSignActivity.AuthToken = await terminalDocuSignTools.GenerateAuthToken("*****@*****.**", "fr8mesomething", queryDocuSignActivity.ActivityTemplate.Terminal);
            var terminalSummaryDTO = new TerminalSummaryDTO
            {
                Name    = queryDocuSignActivity.ActivityTemplate.TerminalName,
                Version = queryDocuSignActivity.ActivityTemplate.TerminalVersion
            };

            queryDocuSignActivity.AuthToken = await terminalDocuSignTools.GenerateAuthToken("*****@*****.**", "I6HmXEbCxN", terminalSummaryDTO);

            var applyToken = new AuthenticationTokenGrantDTO()
            {
                ActivityId  = queryDocuSignActivity.Id,
                AuthTokenId = Guid.Parse(queryDocuSignActivity.AuthToken.Token),
            };
            await _baseHubITest.HttpPostAsync <AuthenticationTokenGrantDTO[], string>(_baseHubITest.GetHubApiBaseUrl() + "authentication/tokens/grant", new AuthenticationTokenGrantDTO[] { applyToken });

            //send configure with the auth token
            queryDocuSignActivity = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/save", queryDocuSignActivity);

            queryDocuSignActivity = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/configure", queryDocuSignActivity);

            initialcrateStorage = _baseHubITest.Crate.FromDto(queryDocuSignActivity.CrateStorage);

            Assert.True(initialcrateStorage.CratesOfType <StandardConfigurationControlsCM>().Any(),
                        "Query_DocuSign: Crate StandardConfigurationControlsCM is missing in API response.");

            var controlsCrate = initialcrateStorage.CratesOfType <StandardConfigurationControlsCM>().First();
            //set the value of folder to drafts and
            var controls      = controlsCrate.Content.Controls;
            var folderControl = controls.OfType <DropDownList>().FirstOrDefault(c => c.Name == "FolderFilter");

            Assert.IsNotNull(folderControl, "Query_DocuSign: DropDownList control for Folder value selection was not found");
            folderControl.Value       = "Draft";
            folderControl.selectedKey = "Draft";

            //set the value of status to any
            var statusControl = controls.OfType <DropDownList>().FirstOrDefault(c => c.Name == "StatusFilter");

            Assert.IsNotNull(folderControl, "Query_DocuSign: DropDownList control for Status value selection was not found");
            statusControl.Value       = null;
            statusControl.selectedKey = null;

            //call followup configuration
            using (var crateStorage = _baseHubITest.Crate.GetUpdatableStorage(queryDocuSignActivity))
            {
                crateStorage.Remove <StandardConfigurationControlsCM>();
                crateStorage.Add(controlsCrate);
            }
            queryDocuSignActivity = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/save", queryDocuSignActivity);

            queryDocuSignActivity = await _baseHubITest.HttpPostAsync <ActivityDTO, ActivityDTO>(_baseHubITest.GetHubApiBaseUrl() + "activities/configure", queryDocuSignActivity);

            return(await Task.FromResult(queryDocuSignActivity));
        }