I have 3 questions:
- 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/
. - How do I unit test this? Should I even unit test reading files from the file system?
- Best way to read the file into a string?
asked Feb 13, 2011 at 4:18
3 Answers 3
- I would make a views folder for them
/Views/Emails
perhaps - Unit test code that you write, not code from the .NET framework imo
string s = System.IO.File.ReadAllText( path );
answered Feb 13, 2011 at 4:24
-
@Lol Just provide sample files as assets available to the test. If you have a "test project", put the files there.bzlm– bzlm2011年02月13日 13:53:28 +00:00Commented 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.PositiveGuy– PositiveGuy2012年01月27日 07:42:16 +00:00Commented Jan 27, 2012 at 7:42
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
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.
lang-cs