Example #1
0
        private async Task <string> BuildMessage(RazorRenderer renderer, IMailer mailer)
        {
            this.BindDynamicProperties();

            if (this._html != null)
            {
                return(this._html);
            }

            if (this._viewPath != null)
            {
                return(await renderer
                       .RenderViewToStringAsync <T>(this._viewPath, this._viewModel)
                       .ConfigureAwait(false));
            }

            throw new NoMailRendererFound(NoRenderFoundMessage);
        }
Example #2
0
        public void TestTemplateCacheDatabase()
        {
            MailTemplate template = new MailTemplate {
                Name = "test", Text = "<b>Hello World</b> @Model.FirstName"
            };

            using (var db = new MailDemonDatabase())
            {
                db.Lists.Add(new MailList {
                    Name = "test"
                });
                db.Templates.Add(template);
                db.SaveChanges();
            }

            string html = viewRenderer.RenderViewToStringAsync("test", model, isMainPage: false).Sync();

            Assert.AreEqual("<b>Hello World</b> Bob", html);
            html = viewRenderer.RenderViewToStringAsync("test", model, isMainPage: false).Sync();
            Assert.AreEqual("<b>Hello World</b> Bob", html);

            template.Text        += " <br/>New Line<br/>";
            template.LastModified = DateTime.UtcNow;
            template.Dirty        = true;

            using (var db = new MailDemonDatabase())
            {
                db.Update(template);
                db.SaveChanges();
            }

            html = viewRenderer.RenderViewToStringAsync("test", model, isMainPage: false).Sync();
            Assert.AreEqual("<b>Hello World</b> Bob <br/>New Line<br/>", html);
            html = viewRenderer.RenderViewToStringAsync("test", model, isMainPage: false).Sync();
            Assert.AreEqual("<b>Hello World</b> Bob <br/>New Line<br/>", html);
        }