protected string Render <TController, TModel>(Expression <Func <TController, ActionResult> > action, TModel model)
        {
            var filename = RequestUtil.GetViewFile(action);

            Assert.That(File.Exists(filename), string.Format("View '{0}' does not exist", filename));

            var templateLines = File.ReadAllLines(filename);

            int startLine = 0;

            if (templateLines[0].StartsWith("@model"))
            {
                startLine++;  // skip the @model
            }
            var template = string.Join("\n", templateLines.Skip(startLine));

            string output = "";

            try
            {
                Razor.DefaultTemplateService.Namespaces.Add("OfflineExample.Controllers");
                Razor.DefaultTemplateService.Namespaces.Add("OfflineExample.Util");
                Razor.DefaultTemplateService.Namespaces.Add("OfflineExample.Views.Offline");
                Razor.SetTemplateBase(typeof(TestTemplateBase <>));
                return(Razor.Parse <TModel>(template, model));
            }
            catch (TemplateCompilationException tce)
            {
                Assert.Fail(string.Join("\n", tce.Errors.Select(e => e.ErrorText)));
            }

            return(output);
        }
Exemple #2
0
 public string Filename()
 {
     return(RequestUtil.GetViewFile(ViewAction));
 }