public void Test_that_interceptor_executes() { var emailSender = new DummyEmailSender(); var countEmailsInterceptor = new CountEmailsInterceptor(); emailSender.AddInterceptor(countEmailsInterceptor); emailSender.SendAsync(new MailMessage()).Wait(); emailSender.SendAsync(new MailMessage()).Wait(); emailSender.SendAsync(new MailMessage()).Wait(); Assert.Equal(3, countEmailsInterceptor.SendingCallCount); Assert.Equal(3, countEmailsInterceptor.SentCallCount); }
private static void Main(string[] args) { // We'll dump the resulting HTML body in a file var file = File.Create(Path.Combine(Environment.CurrentDirectory, "output.html")); var streamWriter = new StreamWriter(file, Encoding.UTF8); var emailSender = new DummyEmailSender(message => streamWriter.Write(message.Body)); // or new DummyEmailSender(Dump) var templateCompiler = new TemplateCompiler(); var xmlSerializer = new CustomXmlSerializer(); var templateDirectory = Path.Combine(Environment.CurrentDirectory, "Templates"); var layoutFile = Path.Combine(templateDirectory, "layout.html"); var xsltFilePath = Path.Combine(templateDirectory, "ActivateAccount.xslt"); var variables = new { FirstName = "Axel", LastName = "Zarate", Username = "******", Ignored = default(object), Logo = "http://www.logotree.com/images/single-logo-design/logo-design-sample-14.jpg", ActivationLink = "http://localhost/Account/Activate/azarate", Benefits = new[] { "Free support", "Great discounts", "Unlimited access" }, IsPremiumUser = true }; var templateEmailSender = new TemplateEmailSender(emailSender, templateCompiler, xmlSerializer) { LayoutFilePath = layoutFile }; templateEmailSender.Send(xsltFilePath, variables, "*****@*****.**", "This is a template test"); // Close the file streamWriter.Dispose(); file.Close(); Console.WriteLine("Ready."); Console.Read(); }
public void Email_filter_should_filter_addresses() { var emailSender = new DummyEmailSender(); var filterInterceptor = new FilterEmailInterceptor("*@saritasa.com; *@saritasa-hosting.com"); emailSender.AddInterceptor(filterInterceptor); var countEmailsInterceptor = new CountEmailsInterceptor(); emailSender.AddInterceptor(countEmailsInterceptor); emailSender.SendAsync(new MailMessage("*****@*****.**", "*****@*****.**")).Wait(); Assert.Equal(0, countEmailsInterceptor.SentCallCount); emailSender.SendAsync(new MailMessage("*****@*****.**", "*****@*****.**")).Wait(); Assert.Equal(1, countEmailsInterceptor.SentCallCount); emailSender.SendAsync(new MailMessage("*****@*****.**", "*****@*****.**")).Wait(); Assert.Equal(2, countEmailsInterceptor.SentCallCount); filterInterceptor.SetApprovedEmails("*"); emailSender.SendAsync(new MailMessage("*****@*****.**", "*****@*****.**")).Wait(); Assert.Equal(3, countEmailsInterceptor.SentCallCount); }