Пример #1
0
            public void SetsEmailAddress()
            {
                var recipient = TransactMessageRecipient.Create(
                    "*****@*****.**");

                Assert.Equal("*****@*****.**", recipient.EmailAddress);
            }
Пример #2
0
        public void InvokeGetRecipientBatchedMessages <T>(
            int recipientCount,
            int recipientsPerBatch,
            T personalizationTagsForEachRecipient)
        {
            var message = TransactMessage.Create("123", Enumerable.Range(0, recipientCount)
                                                 .Select(x => TransactMessageRecipient.Create(
                                                             Guid.NewGuid().ToString() + "@example.com",
                                                             personalizationTagsObject: personalizationTagsForEachRecipient))
                                                 .ToArray());

            var stopwatch = Stopwatch.StartNew();

            Console.WriteLine("Stopwatch started.");

            // Console.WriteLine("Calling GetRecipientBatchedMessages on constructed message...");
            // var recipientBatchedMesssages = message.GetRecipientBatchedMessages(recipientsPerBatch);

            // Console.WriteLine("{0} messages were generated.", recipientBatchedMesssages.Count());
            // Console.WriteLine();

            stopwatch.Stop();
            Console.WriteLine("Operation took {0}", stopwatch.Elapsed.ToString());
            Console.WriteLine();
        }
Пример #3
0
            public void SetsBodyType()
            {
                var recipient = TransactMessageRecipient.Create(
                    "*****@*****.**",
                    bodyType: TransactMessageRecipientBodyType.Text);

                Assert.Equal(TransactMessageRecipientBodyType.Text, recipient.BodyType);
            }
Пример #4
0
 private static TransactMessage GetTestMessage(string testType)
 {
     return(TransactMessage.Create("123456", TransactMessageRecipient.Create(
                                       "*****@*****.**",
                                       new TestPersonalizationTags()
     {
         Tag1 = "tag1-value",
         Tag2 = "tag2-value"
     })));
 }
Пример #5
0
            public void SetsMessageRecipient()
            {
                var recipient = new TransactMessageRecipient()
                {
                    EmailAddress = "*****@*****.**"
                };

                var message = TransactMessage.Create("123", recipient);

                Assert.Equal(recipient, message.Recipients.Single());
            }
            public void SetsMessageRecipient()
            {
                var recipient = new TransactMessageRecipient()
                {
                    EmailAddress = "*****@*****.**"
                };

                var message = TransactMessage.Create("123", recipient);

                Assert.Equal(recipient, message.Recipients.Single());
            }
Пример #7
0
            public void SetsAllPersonalizationTagsForParentAndSubclasses()
            {
                var recipient = TransactMessageRecipient.Create <TestPersonalizationTagsWithSilverpopPersonalizationTag>(
                    "*****@*****.**",
                    new TestPersonalizationTagsWithSilverpopPersonalizationTag2()
                {
                    Tag1 = "tag1-value",
                    Tag2 = "tag2-value",
                    Tag3 = "tag3-value",
                });

                Assert.Equal(3, recipient.PersonalizationTags.Count());

                Assert.True(recipient.PersonalizationTags.Any(x => x.Value == "tag1-value"));
                Assert.True(recipient.PersonalizationTags.Any(x => x.Value == "tag2-value"));
                Assert.True(recipient.PersonalizationTags.Any(x => x.Value == "tag3-value"));
            }
Пример #8
0
            public void SetsPersonalizationTagsUsingSilverpopPersonalizationTagName()
            {
                var recipient = TransactMessageRecipient.Create <TestPersonalizationTagsWithSilverpopPersonalizationTag>(
                    "*****@*****.**",
                    new TestPersonalizationTagsWithSilverpopPersonalizationTag()
                {
                    Tag1 = "tag1-value",
                    Tag2 = "tag2-value"
                });

                Assert.Equal(2, recipient.PersonalizationTags.Count());

                Assert.Equal("special-tag1-name", recipient.PersonalizationTags.First().Name);
                Assert.Equal("tag1-value", recipient.PersonalizationTags.First().Value);

                Assert.Equal("Tag2", recipient.PersonalizationTags.Last().Name);
                Assert.Equal("tag2-value", recipient.PersonalizationTags.Last().Value);
            }
Пример #9
0
            public void SetsPersonalizationTags()
            {
                var recipient = TransactMessageRecipient.Create <object>(
                    "*****@*****.**",
                    new
                {
                    Tag1 = "tag1-value",
                    Tag2 = "tag2-value"
                });

                Assert.Equal(2, recipient.PersonalizationTags.Count());

                Assert.Equal("Tag1", recipient.PersonalizationTags.First().Name);
                Assert.Equal("tag1-value", recipient.PersonalizationTags.First().Value);

                Assert.Equal("Tag2", recipient.PersonalizationTags.Last().Name);
                Assert.Equal("tag2-value", recipient.PersonalizationTags.Last().Value);
            }
Пример #10
0
            public void ShouldNotThrowWhenPropertyInPersonalizationTagsObjectHasANullValue()
            {
                // Verify this test is valid when using the
                // TestPersonalizationTagsWithSilverpopPersonalizationTag type.
                var propertiesCount = new TestPersonalizationTagsWithSilverpopPersonalizationTag()
                                      .GetType()
                                      .GetProperties(Constants.DefaultPersonalizationTagsPropertyReflectionBindingFlags)
                                      .Count();

                Assert.True(propertiesCount > 1);

                TransactMessageRecipient.Create <TestPersonalizationTagsWithSilverpopPersonalizationTag>(
                    "*****@*****.**",
                    new TestPersonalizationTagsWithSilverpopPersonalizationTag()
                {
                    Tag1 = "tag1-value",
                });
            }
Пример #11
0
        public HomeModule(TransactClient client)
        {
            Get["/"] = _ => View["Index", new IndexModel(client.Configuration)];

            Post["/send"] = _ =>
            {
                var model = this.Bind <SendModel>();

                // Validate request
                var validationResult = this.Validate <SendModel>(model);
                if (!validationResult.IsValid)
                {
                    return(new TextResponse(
                               HttpStatusCode.BadRequest,
                               string.Join(" ", validationResult.Errors.SelectMany(x => x.Value))));
                }

                // Create message
                var recipient = TransactMessageRecipient.Create(model.ToAddress);
                recipient.PersonalizationTags = model.PersonalizationTags;

                var message = TransactMessage.Create(model.CampaignId, recipient);

                // Send message
                TransactMessageResponse response = null;
                try
                {
                    response = client.SendMessage(message);
                }
                catch (TransactClientException ex)
                {
                    return(new TextResponse(
                               HttpStatusCode.InternalServerError,
                               ex.Message));
                }

                return(Response.AsJson(response));
            };
        }
Пример #12
0
 public void ThrowsForNullPersonalizationTagsObject()
 {
     Assert.Throws <ArgumentNullException>(
         () => TransactMessageRecipient.Create <object>("*****@*****.**", null));
 }
Пример #13
0
 public void ThrowsForNullEmailAddress()
 {
     Assert.Throws <ArgumentNullException>(
         () => TransactMessageRecipient.Create <object>(null, new { }));
 }