public FakeTemplate(string templateName = null, ID templateId = null, Database database = null, TemplateEngine engine = null) { string name = string.IsNullOrEmpty(templateName) ? "fakeTemplate" : templateName; ID id = templateId ?? ID.NewID; Database db = database ?? FakeUtil.FakeDatabase(); this.Database = db; templateEngine = engine ?? Substitute.For <TemplateEngine>(db); templateBuilder = new Template.Builder(name, id, templateEngine); templateBuilder.SetName(name); templateBuilder.SetID(id); templateEngine.GetTemplate(id).Returns(this); templateEngine.GetTemplate(name).Returns(this); }
public void EmailCommentToBlogAuthor(FeedbackItem comment) { if (String.IsNullOrEmpty(Blog.Email) || comment.FeedbackType == FeedbackType.PingTrack || Context.User.IsAdministrator()) { return; } string fromEmail = comment.Email; if (String.IsNullOrEmpty(fromEmail)) { fromEmail = null; } var commentForTemplate = new { blog = Blog, comment = new { author = comment.Author, title = comment.Title, source = Url.FeedbackUrl(comment).ToFullyQualifiedUrl(Blog), email = fromEmail ?? "none given", authorUrl = comment.SourceUrl, ip = comment.IpAddress, // we're sending plain text email by default, but body includes <br />s for crlf body = (comment.Body ?? string.Empty).Replace("<br />", Environment.NewLine).Replace("<br />", Environment. NewLine) }, spamFlag = comment.FlaggedAsSpam ? "Spam Flagged " : "" }; ITextTemplate template = TemplateEngine.GetTemplate("CommentReceived"); string message = template.Format(commentForTemplate); string subject = String.Format(CultureInfo.InvariantCulture, Resources.Email_CommentVia, comment.Title, Blog.Title); if (comment.FlaggedAsSpam) { subject = "[SPAM Flagged] " + subject; } string from = EmailProvider.UseCommentersEmailAsFromAddress ? (fromEmail ?? EmailProvider.AdminEmail) : EmailProvider.AdminEmail; EmailProvider.Send(Blog.Email, from, subject, message); }
public void Test2() { var options = new StorageOptions(new ConnectionStrings().Get("XtricateTestSqlDb"), schemaName: "StorageTests") { BufferedLoad = false }; var connectionFactory = new SqlConnectionFactory(); var storage = new DocStorage <MimeMessage>(connectionFactory, options, new SqlBuilder(), new JsonNetSerializer(), new Md5Hasher()); // REGISTER templates - all templates registered in kernel var engine = new TemplateEngine( new TemplateFactory( new[] { new TemplateDefinition { Key = "OrderConfirmation", Tags = new[] { "shop", "de-DE" }, //Culture = CultureInfo.GetCultureInfo("de-DE"), TemplateType = typeof(OrderConfirmationTemplate), ModelType = typeof(OrderConfirmationModel), } }), new PropertyBag <IDictionary <string, string> > { { CultureInfo.GetCultureInfo("de-DE").Name, new Dictionary <string, string> { { "welcome", "Wilkommen" } } }, { CultureInfo.GetCultureInfo("nl-NL").Name, new Dictionary <string, string> { { "welcome", "Welkom" } } } }); // CREATE the template based on a model (MAILSERVICE) var model = new OrderConfirmationModel { FirstName = "John", LastName = "Doe", DeliveryDate = DateTime.Now.AddDays(2), Items = new List <OrderItemModel> { new OrderItemModel { Name = "product1", Price = 9.99m, Quantity = 2, Sku = "sku1" }, new OrderItemModel { Name = "product2", Price = 3.99m, Quantity = 4, Sku = "sku2" }, } }; var templ = engine.GetTemplate(model, "OrderConfirmation", new[] { "shop", "de-DE" }, "de-DE"); Assert.That(templ, Is.Not.Null); Assert.That(templ.Model, Is.Not.Null); var body = templ.ToString(); Assert.That(body, Is.Not.Null.Or.Empty); Assert.That(templ.OutProperties.Any()); Assert.That(templ.OutProperties.ContainsKey("subject")); Trace.WriteLine(body); Trace.WriteLine(templ.OutProperties["subject"]); // CREATE the message (MAILSERVICE) var message = new MimeMessage(); message.Subject = templ.OutProperties["subject"]; message.From.Add(new MailboxAddress("Joey", "*****@*****.**")); message.To.Add(new MailboxAddress("Alice", "*****@*****.**")); var builder = new BodyBuilder { HtmlBody = body }; message.Body = builder.ToMessageBody(); //message.Attachments // STORE message in docset (MAILSERVICE) var key = new Random().Next(10000, 99999); var messageStream = new MemoryStream(); message.WriteTo(messageStream); Assert.That(messageStream, Is.Not.Null); messageStream.Position = 0; storage.Upsert(key, messageStream, new[] { "en-US" }); // LOAD message from docst (JOB) message = MimeMessage.Load(storage.LoadData(key, new[] { "en-US" }).FirstOrDefault()); Assert.That(message, Is.Not.Null); // SEND the docset message (JOB) using (var client = new SmtpClient(new ProtocolLogger("smtp.log"))) { client.Connect("localhost", 25, SecureSocketOptions.None); //client.Authenticate("username", "password"); client.Send(message); client.Disconnect(true); } }
public FakeTemplate WithFullName(string fullName) { templateBuilder.SetFullName(fullName); templateEngine.GetTemplate(fullName).Returns(this); return(this); }