示例#1
0
        public async Task Mail_Merge_Into_DocuSign_EndToEnd_Upstream_Values_From_Google_Check_Tabs()
        {
            //
            //Setup Test
            //
            await RevokeTokens();

            var terminalGoogleTestTools = new Fr8.Testing.Integration.Tools.Terminals.IntegrationTestTools_terminalGoogle(this);
            var googleActivityTestTools = new Fr8.Testing.Integration.Tools.Activities.IntegrationTestTools_terminalGoogle(this);
            var googleAuthTokenId       = await terminalGoogleTestTools.ExtractGoogleDefaultToken();

            string spreadsheetName    = Guid.NewGuid().ToString();
            string spreadsheetKeyWord = Guid.NewGuid().ToString();
            string worksheetName      = "TestSheet";

            //create new excel spreadsheet inside google and insert one row of data inside the spreadsheet
            //spreadsheetKeyWord is an identifier that will help up later in the test to easily identify specific envelope
            var    tableFixtureData = FixtureData.TestStandardTableData(TestEmail, spreadsheetKeyWord);
            string spreadsheetId    = await terminalGoogleTestTools.CreateNewSpreadsheet(googleAuthTokenId, spreadsheetName, worksheetName, tableFixtureData);

            //
            // Create solution
            //
            var parameters = await _docuSignActivitiesTestTools.CreateAndConfigure_MailMergeIntoDocuSign_Solution("Get_Google_Sheet_Data",
                                                                                                                  "Get Google Sheet Data", "a439cedc-92a8-49ad-ab31-e2ee7964b468", "Fr8 Fromentum Registration Form", false);

            this.solution = parameters.Item1;
            var plan      = parameters.Item2;
            var tokenGuid = parameters.Item3;

            //
            // configure Get_Google_Sheet_Data activity
            //
            var googleSheetActivity = this.solution.ChildrenActivities.Single(a => a.ActivityTemplate.Name.Equals("Get_Google_Sheet_Data", StringComparison.InvariantCultureIgnoreCase));
            await googleActivityTestTools.ConfigureGetFromGoogleSheetActivity(googleSheetActivity, spreadsheetName, false, worksheetName);

            //
            // configure Loop activity
            //
            var loopActivity         = this.solution.ChildrenActivities.Single(a => a.ActivityTemplate.Name.Equals("Loop", StringComparison.InvariantCultureIgnoreCase));
            var terminalFr8CoreTools = new IntegrationTestTools_terminalFr8(this);

            loopActivity = await terminalFr8CoreTools.ConfigureLoopActivity(loopActivity, "Standard Table Data", "Table Generated From Google Sheet Data");

            //
            // Configure Send DocuSign Envelope action
            //

            //
            // Initial Configuration
            //
            var sendEnvelopeAction = loopActivity.ChildrenActivities.Single(a => a.ActivityTemplate.Name == "Send_DocuSign_Envelope");

            crateStorage = Crate.FromDto(sendEnvelopeAction.CrateStorage);
            var controlsCrate = crateStorage.CratesOfType <StandardConfigurationControlsCM>().First();

            var docuSignTemplate = controlsCrate.Content.Controls.OfType <DropDownList>().First();

            docuSignTemplate.Value       = "a439cedc-92a8-49ad-ab31-e2ee7964b468";
            docuSignTemplate.selectedKey = "Fr8 Fromentum Registration Form";

            using (var updatableStorage = Crate.GetUpdatableStorage(sendEnvelopeAction))
            {
                updatableStorage.Remove <StandardConfigurationControlsCM>();
                updatableStorage.Add(controlsCrate);
            }

            sendEnvelopeAction = await HttpPostAsync <ActivityDTO, ActivityDTO>(_baseUrl + "activities/save", sendEnvelopeAction);

            sendEnvelopeAction = await HttpPostAsync <ActivityDTO, ActivityDTO>(_baseUrl + "activities/configure", sendEnvelopeAction);

            //
            // Follow-up Configuration
            //
            //chosen "Fr8 Fromentum Registration Form" contains 7 specific DocuSign tabs that will be configured with upstream values
            crateStorage  = Crate.FromDto(sendEnvelopeAction.CrateStorage);
            controlsCrate = crateStorage.CratesOfType <StandardConfigurationControlsCM>().First();
            var emailField = controlsCrate.Content.Controls.OfType <TextSource>().First(f => f.InitialLabel == "Lead role email");

            emailField.ValueSource = "upstream";
            emailField.Value       = "emailaddress";
            emailField.selectedKey = "emailaddress";

            var emailNameField = controlsCrate.Content.Controls.OfType <TextSource>().First(f => f.InitialLabel == "Lead role name");

            emailNameField.ValueSource = "upstream";
            emailNameField.Value       = "name";
            emailNameField.selectedKey = "name";

            var phoneField = controlsCrate.Content.Controls.OfType <TextSource>().First(f => f.InitialLabel == "Phone (Lead)");

            phoneField.ValueSource = "upstream";
            phoneField.Value       = "phone";
            phoneField.selectedKey = "phone";

            var titleField = controlsCrate.Content.Controls.OfType <TextSource>().First(f => f.InitialLabel == "Title (Lead)");

            titleField.ValueSource = "upstream";
            titleField.Value       = "title";
            titleField.selectedKey = "title";

            var companyField = controlsCrate.Content.Controls.OfType <TextSource>().First(f => f.InitialLabel == "Company (Lead)");

            companyField.ValueSource = "upstream";
            companyField.Value       = "companyname";
            companyField.selectedKey = "companyname";

            var radioGroup = controlsCrate.Content.Controls.OfType <RadioButtonGroup>().First(f => f.GroupName == "Registration Type (Lead)");

            foreach (var radios in radioGroup.Radios)
            {
                //reset all preselected radioButtons
                radios.Selected = false;
            }
            var radioButton = radioGroup.Radios.FirstOrDefault(x => x.Name == "Buy 2, Get 3rd Free");

            radioButton.Selected = true;

            var checkboxField = controlsCrate.Content.Controls.OfType <CheckBox>().First(f => f.Name == "CheckBoxFields_GovernmentEntity? (Lead)");

            checkboxField.Selected = true;

            var dropdownField = controlsCrate.Content.Controls.OfType <DropDownList>().First(f => f.Name == "DropDownListFields_Size of Company (Lead)");

            dropdownField.Value       = "Medium (51-250)";
            dropdownField.selectedKey = "Medium (51-250)";

            using (var updatableStorage = Crate.GetUpdatableStorage(sendEnvelopeAction))
            {
                updatableStorage.Remove <StandardConfigurationControlsCM>();
                updatableStorage.Add(controlsCrate);
            }

            sendEnvelopeAction = await HttpPostAsync <ActivityDTO, ActivityDTO>(_baseUrl + "activities/save", sendEnvelopeAction);

            crateStorage  = Crate.FromDto(sendEnvelopeAction.CrateStorage);
            controlsCrate = crateStorage.CratesOfType <StandardConfigurationControlsCM>().First();

            docuSignTemplate = controlsCrate.Content.Controls.OfType <DropDownList>().First();
            Assert.AreEqual("a439cedc-92a8-49ad-ab31-e2ee7964b468", docuSignTemplate.Value, "Selected DocuSign Template did not save on Send DocuSign Envelope action.");
            Assert.AreEqual("Fr8 Fromentum Registration Form", docuSignTemplate.selectedKey, "Selected DocuSign Template did not save on Send DocuSign Envelope action.");

            //
            // Activate and run plan
            //
            var container = await HttpPostAsync <string, ContainerDTO>(_baseUrl + "plans/run?planId=" + plan.Id, null);

            Assert.AreEqual(container.State, State.Completed, "Container state is not equal to completed on Mail_Merge e2e test");

            //
            // Assert
            //
            var authorizationTokenDO = _terminalDocuSignTestTools.GetDocuSignAuthToken(tokenGuid);
            var authorizationToken   = new AuthorizationToken()
            {
                Token = authorizationTokenDO.Token,
            };
            var configuration = new DocuSignManager().SetUp(authorizationToken);
            //find the envelope on the Docusign Account
            var folderItems = DocuSignFolders.GetFolderItems(configuration, new DocuSignQuery()
            {
                Status     = "sent",
                SearchText = spreadsheetKeyWord
            });

            var envelope = folderItems.FirstOrDefault();

            Assert.IsNotNull(envelope, "Cannot find created Envelope in sent folder of DocuSign Account");
            var envelopeApi = new EnvelopesApi(configuration.Configuration);
            //get the recipient that receive this sent envelope
            var envelopeSigner = envelopeApi.ListRecipients(configuration.AccountId, envelope.EnvelopeId).Signers.FirstOrDefault();

            Assert.IsNotNull(envelopeSigner, "Envelope does not contain signer as recipient. Send_DocuSign_Envelope activity failed to provide any signers");
            //get the tabs for the envelope that this recipient received
            var tabs = envelopeApi.ListTabs(configuration.AccountId, envelope.EnvelopeId, envelopeSigner.RecipientId);

            Assert.IsNotNull(tabs, "Envelope does not contain any tabs. Check for problems in DocuSignManager and HandleTemplateData");

            //check all tabs and their values for received envelope, and compare them to those from the google sheet configured into Mail_Merge_Into_Docusign solution
            var titleRecipientTab = tabs.TextTabs.FirstOrDefault(x => x.TabLabel == "Title");

            Assert.IsNotNull(titleRecipientTab, "Envelope does not contain Title tab. Check for problems in DocuSignManager and HandleTemplateData");
            Assert.AreEqual(tableFixtureData.Table[1].Row.FirstOrDefault(x => x.Cell.Key == "title").Cell.Value, titleRecipientTab.Value, "Provided value for Title in document for recipient after finishing mail merge plan is incorrect");

            var companyRecipientTab = tabs.TextTabs.FirstOrDefault(x => x.TabLabel == "Company");

            Assert.IsNotNull(companyRecipientTab, "Envelope does not contain Company tab. Check for problems in DocuSignManager and HandleTemplateData");
            Assert.AreEqual(tableFixtureData.Table[1].Row.FirstOrDefault(x => x.Cell.Key == "companyname").Cell.Value, companyRecipientTab.Value, "Provided value for CompanyName in document for recipient after finishing mail merge plan is incorrect");

            var phoneRecipientTab = tabs.TextTabs.FirstOrDefault(x => x.TabLabel == "Phone");

            Assert.IsNotNull(phoneRecipientTab, "Envelope does not contain phone tab. Check for problems in DocuSignManager and HandleTemplateData");
            Assert.AreEqual(tableFixtureData.Table[1].Row.FirstOrDefault(x => x.Cell.Key == "phone").Cell.Value, phoneRecipientTab.Value, "Provided value for phone in document for recipient after finishing mail merge plan is incorrect");

            var listRecipientTab = tabs.ListTabs.FirstOrDefault(x => x.TabLabel == "Size of Company");

            Assert.IsNotNull(listRecipientTab, "Envelope does not contain List Tab for Size of Company tab. Check for problems in DocuSignManager and HandleTemplateData");
            Assert.AreEqual("Medium (51-250)", listRecipientTab.Value, "Provided value for Size of Company(Lead) in document for recipient after finishing mail merge plan is incorrect");

            var checkboxRecipientTab = tabs.CheckboxTabs.FirstOrDefault(x => x.TabLabel == "GovernmentEntity?");

            Assert.IsNotNull(checkboxRecipientTab, "Envelope does not contain Checkbox for Goverment Entity tab. Check for problems in DocuSignManager and HandleTemplateData");
            Assert.AreEqual("true", checkboxRecipientTab.Selected, "Provided value for GovernmentEntity? in document for recipient after finishing mail merge plan is incorrect");

            var radioButtonGroupTab = tabs.RadioGroupTabs.FirstOrDefault(x => x.GroupName == "Registration Type");

            Assert.IsNotNull(radioButtonGroupTab, "Envelope does not contain RadioGroup tab for registration. Check for problems in DocuSignManager and HandleTemplateData");
            Assert.AreEqual("Buy 2, Get 3rd Free", radioButtonGroupTab.Radios.FirstOrDefault(x => x.Selected == "true").Value, "Provided value for Registration Type in document for recipient after finishing mail merge plan is incorrect");

            // Verify that test email has been received
            EmailAssert.EmailReceived("*****@*****.**", "Test Message from Fr8");

            //
            // Cleanup
            //

            //delete spreadsheet
            await terminalGoogleTestTools.DeleteSpreadSheet(googleAuthTokenId, spreadsheetId);

            //
            // Deactivate plan
            //
            await HttpPostAsync <string, string>(_baseUrl + "plans/deactivate?planId=" + plan.Id, null);

            //
            // Delete plan
            //
            //await HttpDeleteAsync(_baseUrl + "plans?id=" + plan.Id);
        }
        public async Task MailMergeFromSalesforceEndToEnd()
        {
            await RevokeTokens("terminalDocuSign");

            var salesforceAuthToken = await HealthMonitor_FixtureData.CreateSalesforceAuthToken();

            //Create Case object in Salesforce
            var caseIdAndName = await CreateCase(salesforceAuthToken);

            PlanDTO plan = null;

            try
            {
                plan = await CreatePlan();

                var solution = plan.SubPlans.First().Activities.Single();
                await ApplyAuthTokenToSolution(solution, salesforceAuthToken);

                //Initial configuration
                solution = await Configure(solution);

                //Folowup configuration
                solution = solution.UpdateControls <Mail_Merge_From_Salesforce_v1.ActivityUi>(x =>
                {
                    x.SalesforceObjectSelector.selectedKey = "Case";
                    x.SalesforceObjectSelector.Value       = "Case";
                });
                //This call will make solution to load specified Salesforce object properties and clear filter
                solution = await Configure(solution);

                //This call will run generation of child activities
                solution = solution.UpdateControls <Mail_Merge_From_Salesforce_v1.ActivityUi>(x =>
                {
                    x.SalesforceObjectFilter.Value = $"[{{\"field\":\"SuppliedName\",\"operator\":\"eq\",\"value\":\"{caseIdAndName.Item2}\"}}]";
                    var sendDocuSignItem           = x.MailSenderActivitySelector.ListItems.FirstOrDefault(y => y.Key == "Send DocuSign Envelope");
                    Assert.IsNotNull(sendDocuSignItem, $"Send DocuSign Envelope activity is not marked with '{Tags.EmailDeliverer}' tag");
                    x.MailSenderActivitySelector.selectedKey = sendDocuSignItem.Key;
                    x.MailSenderActivitySelector.Value       = sendDocuSignItem.Value;
                    x.RunMailMergeButton.Clicked             = true;
                });
                solution = await Configure(solution);

                Assert.AreEqual(2, solution.ChildrenActivities.Length, "Child activities were not generated after mail merge was requested");
                //Configure Send DocuSign Envelope activity to use proper upstream values
                var docuSignActivity       = solution.ChildrenActivities[1].ChildrenActivities[0];
                var docusSignAuthAndConfig = await AuthorizeAndConfigureDocuSignActivity(docuSignActivity);

                docuSignActivity = docusSignAuthAndConfig.Item1;
                //Run plan
                var container = await Run(plan);

                Assert.AreEqual(State.Completed, container.State, "Container state is not equal to Completed");
                // Deactivate plan
                await Deactivate(plan);

                //Verify contents of envelope
                AssertEnvelopeContents(docusSignAuthAndConfig.Item2, caseIdAndName.Item2);
                // Verify that test email has been received
                EmailAssert.EmailReceived("*****@*****.**", "Test Message from Fr8");
            }
            finally
            {
                var caseWasDeleted = await DeleteCase(caseIdAndName.Item1, salesforceAuthToken);

                Assert.IsTrue(caseWasDeleted, "Case created for test purposes failed to be deleted");
                //if (plan != null)
                //{
                //    await HttpDeleteAsync($"{_baseUrl}plans?id={plan.Id}");
                //}
            }
        }
        public async Task GetSalesforceData_Into_SendEmail_EndToEnd()
        {
            AuthorizationTokenDO authTokenDO = null;
            Guid initialPlanId = Guid.Empty;

            try
            {
                authTokenDO = await Fixtures.HealthMonitor_FixtureData.CreateSalesforceAuthToken();

                //Create the required plan
                initialPlanId = await CreatePlan_GetSalesforceDataIntoSendEmail(authTokenDO);

                //get the full plan which is created
                var plan = await HttpGetAsync <PlanDTO>(_baseUrl + "Plans?include_children=true&id=" + initialPlanId.ToString());

                Debug.WriteLine("Created plan with all activities.");

                //make get salesforce data to get Lead
                var getData = plan.SubPlans.First().Activities.First();
                using (var updatableStorage = Crate.GetUpdatableStorage(getData))
                {
                    //select Lead
                    var configControls = updatableStorage.CratesOfType <StandardConfigurationControlsCM>().Single();
                    (configControls.Content.Controls.Single(c => c.Name.Equals(nameof(Get_Data_v1.ActivityUi.SalesforceObjectSelector))) as DropDownList).selectedKey = "Lead";

                    //give condition
                    var conditionQuery = new List <FilterConditionDTO>()
                    {
                        new FilterConditionDTO {
                            Field = "LastName", Operator = "eq", Value = "McSorely"
                        }
                    };
                    (configControls.Content.Controls.Single(c => c.Name.Equals(nameof(Get_Data_v1.ActivityUi.SalesforceObjectFilter))) as QueryBuilder).Value = JsonConvert.SerializeObject(conditionQuery);
                }
                getData = await ConfigureActivity(getData);

                Debug.WriteLine("Get Lead using condition is successful in the Follow Up Configure");

                //prepare the send email activity controls.
                var sendEmail = plan.SubPlans.First().Activities.Last();
                using (var updatableStorage = Crate.GetUpdatableStorage(sendEmail))
                {
                    var configControls = updatableStorage.CratesOfType <StandardConfigurationControlsCM>().Single();

                    var emailAddressControl = (TextSource)configControls.Content.Controls.Single(c => c.Name.Equals("EmailAddress"));
                    var emailSubjectControl = (TextSource)configControls.Content.Controls.Single(c => c.Name.Equals("EmailSubject"));
                    var emailBodyControl    = (TextSource)configControls.Content.Controls.Single(c => c.Name.Equals("EmailBody"));

                    emailAddressControl.ValueSource = "specific";
                    emailAddressControl.TextValue   = ConfigurationManager.AppSettings["TestEmailYahoo"];

                    emailSubjectControl.ValueSource = emailBodyControl.ValueSource = "upstream";
                    emailSubjectControl.selectedKey = "Name";
                    emailBodyControl.selectedKey    = "Phone";
                }
                sendEmail = await ConfigureActivity(sendEmail);

                Debug.WriteLine("Send Email follow up configure is successful.");

                //Run the plan
                await HttpPostAsync <string, string>(_baseUrl + "plans/run?planId=" + plan.Id, null);

                Debug.WriteLine("Plan execution is successful.");

                await CleanUp(authTokenDO, initialPlanId);

                //Verify the email
                EmailAssert.EmailReceived(ConfigurationManager.AppSettings["OpsEmail"], "Marty McSorely", true);
            }
            finally
            {
                await CleanUp(authTokenDO, initialPlanId);
            }
        }