Ejemplo n.º 1
0
        public void each_message_should_have_only_one_target_client()
        {
            var pictureRes     = Substitute.For <IPictureResizer>();
            var templateReader = Substitute.For <IMailTemplateReader>();

            var content  = @"..\..\Newsletter\TestFiles\3.jpg";
            var resource = new LinkedResource(content);

            const string template = "<html><body><img id=\"newProductImage\" /><a id=\"cancelSubLink\" /><a id=\"goToProduct\"/></body></html>";

            templateReader.GetTemplate(MailTemplateType.Newsletter).Returns(x => template);

            var mailMessage = new NewsletterMessage
            {
                To                = new[] { "*****@*****.**" },
                Body              = "",
                From              = "*****@*****.**",
                Subject           = "Subject",
                ProductUrl        = "TestUri",
                NewsLetterPicture = new NewsletterPicture
                {
                    LinkedResource = resource
                },
                NewsletterClients = new[]
                {
                    new NewsletterClient
                    {
                        Email      = "*****@*****.**",
                        Id         = "TestKlient1",
                        InsertDate = DateTime.Now
                    },
                    new NewsletterClient
                    {
                        Email      = "*****@*****.**",
                        Id         = "TestKlient2",
                        InsertDate = DateTime.Now
                    },
                    new NewsletterClient
                    {
                        Email      = "*****@*****.**",
                        Id         = "TestKlient3",
                        InsertDate = DateTime.Now
                    },
                    new NewsletterClient
                    {
                        Email      = "*****@*****.**",
                        Id         = "TestKlient4",
                        InsertDate = DateTime.Now
                    },
                }
            };

            var messageFactory = new MailMessageFactory(pictureRes, templateReader);
            var messages       = messageFactory.GetMessages(mailMessage);

            foreach (var message in messages)
            {
                message.To.Count.Should().Be(1);
            }
        }
Ejemplo n.º 2
0
        public void mail_message_should_contain_button_href()
        {
            var pictureRes     = Substitute.For <IPictureResizer>();
            var templateReader = Substitute.For <IMailTemplateReader>();

            var content  = @"..\..\Newsletter\TestFiles\3.jpg";
            var resource = new LinkedResource(content);

            const string template = "<html><body><img id=\"newProductImage\" /><a id=\"cancelSubLink\" /><a id=\"goToProduct\"/></body></html>";

            templateReader.GetTemplate(MailTemplateType.Newsletter).Returns(x => template);

            var productId   = Guid.NewGuid();
            var mailMessage = new NewsletterMessage
            {
                To                = new[] { "*****@*****.**" },
                Body              = "",
                From              = "*****@*****.**",
                Subject           = "Subject",
                ProductUrl        = "TestUri",
                ProductId         = productId,
                NewsLetterPicture = new NewsletterPicture
                {
                    LinkedResource = resource
                },
                NewsletterClients = new[]
                {
                    new NewsletterClient()
                    {
                        Email      = "*****@*****.**",
                        Id         = "TestKlient",
                        InsertDate = DateTime.Now
                    },
                }
            };

            var messageFactory = new MailMessageFactory(pictureRes, templateReader);
            var messages       = messageFactory.GetMessages(mailMessage);

            messages.First().Body.Should().Contain($"href=\"www.crochetbyjk.pl/newsletter/{ShortGuid.Encode(productId)}\"");
        }
Ejemplo n.º 3
0
        public void every_client_should_have_his_own_cancel_sub_link()
        {
            var pictureRes     = Substitute.For <IPictureResizer>();
            var templateReader = Substitute.For <IMailTemplateReader>();

            var content  = @"..\..\Newsletter\TestFiles\3.jpg";
            var resource = new LinkedResource(content);

            const string template = "<html><body><img id=\"newProductImage\" /><a id=\"cancelSubLink\" /><a id=\"goToProduct\"/></body></html>";

            templateReader.GetTemplate(MailTemplateType.Newsletter).Returns(x => template);

            var newsClients = new[]
            {
                new NewsletterClient
                {
                    Email      = "*****@*****.**",
                    Id         = "TestKlient1",
                    InsertDate = DateTime.Now
                },
                new NewsletterClient
                {
                    Email      = "*****@*****.**",
                    Id         = "TestKlient2",
                    InsertDate = DateTime.Now
                },
                new NewsletterClient
                {
                    Email      = "*****@*****.**",
                    Id         = "TestKlient3",
                    InsertDate = DateTime.Now
                },
                new NewsletterClient
                {
                    Email      = "*****@*****.**",
                    Id         = "TestKlient4",
                    InsertDate = DateTime.Now
                },
                new NewsletterClient
                {
                    Email      = "*****@*****.**",
                    Id         = "TestKlient5",
                    InsertDate = DateTime.Now
                },
            };
            var mailMessage = new NewsletterMessage
            {
                To                = new[] { "*****@*****.**" },
                Body              = "",
                From              = "*****@*****.**",
                Subject           = "Subject",
                ProductUrl        = "TestUri",
                NewsLetterPicture = new NewsletterPicture
                {
                    LinkedResource = resource
                },
                NewsletterClients = newsClients
            };

            var messageFactory = new MailMessageFactory(pictureRes, templateReader);
            var messages       = messageFactory.GetMessages(mailMessage);

            foreach (var message in messages)
            {
                var client = newsClients.Single(x => x.Email == message.To.Single().Address);
                message.Body.Should()
                .Contain($"href=\"https://www.crochetbyjk.pl/newsletter/potwierdz/{client.Id}\"");
            }
        }