public void Can_Render_RazorTemplate()
        {
            const string mockContents = "[Replaced with Template]";

            razorFormat.AddTemplate(staticTemplatePath, staticTemplateContent);
            var page = AddViewPage("MockPage", "/path/to/page", mockContents, staticTemplatePath);

            var expectedHtml = staticTemplateContent.ReplaceFirst(RazorFormat.TemplatePlaceHolder, mockContents);

            var templateOutput = page.RenderToString(templateArgs);

            Console.WriteLine(templateOutput);

            Assert.That(templateOutput, Is.EqualTo(expectedHtml));
        }
Exemple #2
0
        public static void AddFileAndTemplate(this RazorFormat razorFormat, string filePath, string contents)
        {
            var pathProvider = (InMemoryVirtualPathProvider)razorFormat.VirtualPathProvider;

            pathProvider.AddFile(filePath, contents);
            razorFormat.AddTemplate(filePath, contents);
        }
Exemple #3
0
        public RazorFormat AddPage(string websiteTemplate, string pageTemplate)
        {
            RazorFormat.AddTemplate("websiteTemplate", websiteTemplate);
            RazorFormat.AddPage(
                new ViewPageRef(RazorFormat, "/path/to/tpl", PageName, pageTemplate)
            {
                Template = "websiteTemplate",
            });

            return(RazorFormat);
        }
Exemple #4
0
        public RazorFormat Create(string websiteTemplate, string pageTemplate)
        {
            var razorFormat = new RazorFormat();

            razorFormat.AddTemplate("/path/to/websitetpl", websiteTemplate);
            razorFormat.AddPage(
                new RazorPage(razorFormat, "/path/to/tpl", PageName, pageTemplate)
            {
                TemplatePath = "/path/to/websitetpl",
            });

            return(razorFormat);
        }
Exemple #5
0
        public void Simple_Layout_Example()
        {
            var websiteTemplate =
                @"<!DOCTYPE html>
<html>
    <head>
        <title>Simple Site</title>
    </head>
    <body>
    
        <div id=""header"">
            <a href=""/"">Home</a>
            <a href=""/About"">About</a>
        </div>
        
        <div id=""body"">
            @RenderBody()
        </div>
    
    </body>
</html>".NormalizeNewLines();

            var pageTemplate =
                @"@{ Layout = ""C:\\path\\to\\websiteTemplate""; }

<h1>About this Site</h1>

<p>This is some content that will make up the ""about"" 
page of our web-site. We'll use this in conjunction
with a layout template. The content you are seeing here
comes from ^^^websiteTemplate.</p>

<p>And obviously I can have code in here too. Here is the
current date/year: @DateTime.Now.Year</p>
".NormalizeNewLines();

            var expectedHtml = @"<!DOCTYPE html>
<html>
    <head>
        <title>Simple Site</title>
    </head>
    <body>
    
        <div id=""header"">
            <a href=""/"">Home</a>
            <a href=""/About"">About</a>
        </div>
        
        <div id=""body"">
            
<h1>About this Site</h1>

<p>This is some content that will make up the ""about"" 
page of our web-site. We'll use this in conjunction
with a layout template. The content you are seeing here
comes from ^^^websiteTemplate.</p>

<p>And obviously I can have code in here too. Here is the
current date/year: 2012</p>

        </div>
    
    </body>
</html>".NormalizeNewLines();


            var websiteTemplatePath = @"C:\path\to\websiteTemplate";

            razorFormat.AddTemplate(websiteTemplatePath, websiteTemplate);
            var dynamicPage = AddViewPage(PageName, @"C:\path\to\page-tpl", pageTemplate);

            var template = dynamicPage.RenderToHtml();

            Console.WriteLine(template);
            Assert.That(template, Is.EqualTo(expectedHtml));
        }