3

I have 3 questions:

  1. Where is the correct place to put some template files? I'll be using these templates to render emails with DotLiquid. I'm thinking about just having it at ~/Templates/.
  2. How do I unit test this? Should I even unit test reading files from the file system?
  3. Best way to read the file into a string?
asked Feb 13, 2011 at 4:18
0

3 Answers 3

4
  1. I would make a views folder for them /Views/Emails perhaps
  2. Unit test code that you write, not code from the .NET framework imo
  3. string s = System.IO.File.ReadAllText( path );
answered Feb 13, 2011 at 4:24
2
  • @Lol Just provide sample files as assets available to the test. If you have a "test project", put the files there. Commented Feb 13, 2011 at 13:53
  • why a views subfolder? and what do you mean unit test code you write and not from the .NET framework...can't understand or infer what you're saying there specifically. Commented Jan 27, 2012 at 7:42
2

Check out this blog entry, which talks about how to send emails using a view as a template: ASP.NET MVC 2 Render Template to String.

In short, you create a method that renders the View into a string and then call that method from an action to generate the email body content.

answered Feb 13, 2011 at 4:28
0

Placing the code in ~/Content/Templates/ and downloading the content using a web client worked best for me.

var welcomeMailTemplatePath = "yourPath";
var webClient = new WebClient();
string html = webClient.DownloadString(WelcomeMailTemplatePath); 

This way, you don't need to deal with controllers/views and can directly grab the contents of the template file.

answered Apr 13, 2013 at 0:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.