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?
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 );
Sign up to request clarification or add additional context in comments.

2 Comments

@Lol Just provide sample files as assets available to the test. If you have a "test project", put the files there.
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.
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.

Comments

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.

Comments

Your Answer

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.