public void SendMailUsingAddressesWithBadAddress()
        {
            string subject = "Subject " + Guid.NewGuid().ToString();
            string body    = "Body " + Guid.NewGuid().ToString();

            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock
            .Setup(m => m.SendMessages(It.IsAny <IReadOnlyCollection <MailMessage> >()))
            .Callback <IReadOnlyCollection <MailMessage> >(x =>
            {
                var emails = x.ToList();
                Assert.True(emails.Count == 1);
                Assert.True(emails[0].Subject == subject);
                Assert.True(emails[0].Body == body);
                Assert.True(emails[0].To.Count == 2);
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(emails[0].CC.Count == 0);
                Assert.True(emails[0].Bcc.Count == 0);
                Assert.True(emails[0].Attachments.Count == 0);
            });

            Action <Workflow, WfActivity> configurationCallback = (wf, emailActionAs) =>
            {
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Email To", new EntityRef("core:sendEmailActivityRecipientsAddress"));
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Send As", new EntityRef("core:sendEmailActivityGroupDistribution"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "To Addresses", "'[email protected]; NotAnEmailAddress.com; [email protected]'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Subject", $"'{subject}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Body", $"'{body}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "No Reply", "true", false);
            };

            SendMailWithConfigAction(configurationCallback, emailSenderMock.Object);
        }
        public void SendMailUsingRecipientList()
        {
            string subject = "Subject " + Guid.NewGuid().ToString();
            string body    = "Body " + Guid.NewGuid().ToString();

            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock
            .Setup(m => m.SendMessages(It.IsAny <IReadOnlyCollection <MailMessage> >()))
            .Callback <IReadOnlyCollection <MailMessage> >(x =>
            {
                var emails = x.ToList();
                Assert.True(emails.Count == 1);
                Assert.True(emails[0].Subject == subject);
                Assert.True(emails[0].Body == body);
                Assert.True(emails[0].To.Count > 1);
                Assert.True(emails[0].CC.Count == 0);
                Assert.True(emails[0].Bcc.Count == 0);
                Assert.True(emails[0].Attachments.Count == 0);
            });

            Action <Workflow, WfActivity> configurationCallback = (wf, emailActionAs) =>
            {
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Email To", new EntityRef("core:sendEmailActivityRecipientsList"));
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Send As", new EntityRef("core:sendEmailActivityGroupDistribution"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Recipients List", "all(Employee_Test)", false);
                ActivityTestHelper.SetActivityArgumentToResource(wf, emailActionAs, "TO Address Field", Entity.Get <Resource>("oldshared:workEmail"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Subject", $"'{subject}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Body", $"'{body}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "No Reply", "true", false);
            };

            SendMailWithConfigAction(configurationCallback, emailSenderMock.Object);
        }
        public void SendMailWithAttachments()
        {
            string subject = "Subject " + Guid.NewGuid().ToString();
            string body    = "Body " + Guid.NewGuid().ToString();

            string tempHash = null;
            var    buff     = Encoding.UTF8.GetBytes("Email Attachment File " + CryptoHelper.GetRandomPrintableString(10));

            using (MemoryStream stream = new MemoryStream(buff))
            {
                tempHash = Factory.DocumentFileRepository.Put(stream);
            }

            var file = Entity.Create <Document>();

            file.Name          = "Email Attachment Test File";
            file.Description   = "Send Email Attachment Test";
            file.FileDataHash  = tempHash;
            file.Size          = buff.Length;
            file.FileExtension = "txt";
            file.Save();

            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock
            .Setup(m => m.SendMessages(It.IsAny <IReadOnlyCollection <MailMessage> >()))
            .Callback <IReadOnlyCollection <MailMessage> >(x =>
            {
                var emails = x.ToList();
                Assert.True(emails.Count == 1);
                Assert.True(emails[0].To.Count == 2);
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(emails[0].CC.Count == 0);
                Assert.True(emails[0].Bcc.Count == 0);
                Assert.True(emails[0].Attachments.Count == 1);
                Assert.True(emails[0].Attachments[0].ContentStream.Length == buff.Length);
            });


            Action <Workflow, WfActivity> configurationCallback = (wf, emailActionAs) =>
            {
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Email To", new EntityRef("core:sendEmailActivityRecipientsAddress"));
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Send As", new EntityRef("core:sendEmailActivityGroupDistribution"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "To Addresses", "'[email protected]; [email protected]'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Subject", $"'{subject}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Body", $"'{body}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "No Reply", "true", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Attachments", file.Cast <Resource>().ToEnumerable());
            };

            SendMailWithConfigAction(configurationCallback, emailSenderMock.Object);

            file.Delete();
        }
        public void TestLoopOverNoResultsFromGetRelationship()
        {
            using (new WorkflowRunContext {
                RunTriggersInCurrentThread = true
            })
            {
                var myType = new EntityType {
                    Name = "MyType"
                };
                myType.Save();
                ToDelete.Add(myType.Id);

                var wf = new Workflow {
                    Name = "TestLoopOverNoResultsFromGetRelationship"
                };

                wf.AddDefaultExitPoint();

                var getResources = new GetResourcesActivity {
                    Name = "GetResources"
                };
                var getResourcesAs = getResources.As <WfActivity>();

                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, getResourcesAs, "Object", myType);   // this type has no instances

                wf.FirstActivity = getResourcesAs;
                wf.ContainedActivities.Add(getResourcesAs);

                var forEach1 = new ForEachResource
                {
                    Name = "foreach1" + DateTime.Now
                };
                var forEach1As = forEach1.As <WfActivity>();

                ActivityTestHelper.AddExpressionToActivityArgument(wf, forEach1As, "List", "[List]");  // there shouldn't be any

                wf.ContainedActivities.Add(forEach1As);

                ActivityTestHelper.AddTransition(wf, getResourcesAs, forEach1As);
                ActivityTestHelper.AddTransition(wf, forEach1As, forEach1As, "Loop");
                ActivityTestHelper.AddTermination(wf, forEach1As, "Finished");

                ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf);
                wf.Save();
                ToDelete.Add(wf.Id);

                var run = RunWorkflow(wf);

                IDictionary <string, object> outputs = run.GetOutput();
            }
        }
        public void SendMailUsingAddressesFromInbox()
        {
            string subject = "Subject " + Guid.NewGuid().ToString();
            string body    = "Body " + Guid.NewGuid().ToString();

            var inbox = new Inbox()
            {
                Name = "Test Inbox 1", InboxEmailAddress = "*****@*****.**"
            };

            inbox.Save();

            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock
            .Setup(m => m.SendMessages(It.IsAny <IReadOnlyCollection <MailMessage> >()))
            .Callback <IReadOnlyCollection <MailMessage> >(x =>
            {
                var emails = x.ToList();
                Assert.True(emails.Count == 1);
                Assert.True(emails[0].Subject == subject);
                Assert.True(emails[0].Body == body);
                Assert.True(emails[0].To.Count == 1);
                Assert.True(ContainsAddress(emails[0].To, "*****@*****.**"));
                Assert.True(emails[0].CC.Count == 1);
                Assert.True(ContainsAddress(emails[0].CC, "*****@*****.**"));
                Assert.True(emails[0].Bcc.Count == 1);
                Assert.True(ContainsAddress(emails[0].Bcc, "*****@*****.**"));
                Assert.True(emails[0].Attachments.Count == 0);
                Assert.True(emails[0].From.DisplayName == inbox.Name);
                Assert.True(emails[0].From.Address == inbox.InboxEmailAddress);
            });

            Action <Workflow, WfActivity> configurationCallback = (wf, emailActionAs) =>
            {
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Email To", new EntityRef("core:sendEmailActivityRecipientsAddress"));
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Send As", new EntityRef("core:sendEmailActivityGroupDistribution"));
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "To Addresses", "'*****@*****.**'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "CC Addresses", "'*****@*****.**'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "BCC Addresses", "'*****@*****.**'");
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Subject", $"'{subject}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "Body", $"'{body}'", false);
                ActivityTestHelper.AddExpressionToActivityArgument(wf, emailActionAs, "No Reply", "false", false);
                ActivityTestHelper.AddEntityExpressionToInputArgument(wf, emailActionAs, "Reply to Inbox", new EntityRef(inbox));
            };

            SendMailWithConfigAction(configurationCallback, emailSenderMock.Object);

            inbox.Delete();
        }