protected override void InitializeClientService() { var smtpClientFactory = new SmtpClientFactory(); var mailMessageFactory = new MailMessageFactory(); _clientService = new EmailClientService(smtpClientFactory, mailMessageFactory) }
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); } }
public EmailNotificatorTests(ITestOutputHelper output) { _output = output; var senderAddress = "*****@*****.**"; var senderName = "notif-test"; var mailhogSmtpServerConfig = new SmtpServerConfig() { Host = "localhost", Port = 25, SenderName = senderName, SenderAddress = senderAddress }; var mailSettingsConfig = new MailSettingsConfig() { Smtp = new MailSettingsConfig.SmtpConfig() { Servers = new List <SmtpServerConfig>() { mailhogSmtpServerConfig } } }; var toList = new List <string>(); var subject = "Test subject"; var body = "Test body"; _emailMessage = new EmailMessage(toList, subject, body); var smtpClientFactory = new SmtpClientWithoutSslFactory(); var mailMessageFactory = new MailMessageFactory(); _notificator = new EmailNotificator(smtpClientFactory, mailSettingsConfig, mailMessageFactory); }
private void AlertLender() { var model = new AlertLenderEmailModel() { FromAddress = new MailAddress("*****@*****.**", "Valkyrie Insights"), ToAddress = new MailAddress(SimulationConfiguration.EmailAddress, SimulationConfiguration.Lender.Name + " (Commercial Lending)"), Name = SimulationConfiguration.Lender.Name, CustomerName = "Peter's Pumpkin Cannery" }; MailMessageFactory.Send(model); }
public MailMessageFactoryTests() { _factory = new MailMessageFactory(); _smtpServerConfig = SmtpServerConfigFake.Generate(); var from = _faker.Internet.Email(); var to = new List <string>() { _faker.Internet.Email() }; _emailMessage = new EmailMessage(from, to, "subject", "body"); _request = new MailMessageCreateRequest() { EmailMessage = _emailMessage, SmtpServerConfig = _smtpServerConfig, IsReadSenderFromConfig = false, }; }
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)}\""); }
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}\""); } }