Ejemplo n.º 1
0
        public void Can_Render_RazorTemplate()
        {
            const string mockContents = "[Replaced with Template]";

            RazorFormat.AddFileAndTemplate(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));
        }
Ejemplo n.º 2
0
        public void Can_Render_RazorPage()
        {
            RazorFormat.AddFileAndTemplate(staticTemplatePath, staticTemplateContent);
            var dynamicPage = AddViewPage("DynamicTpl", dynamicPagePath, dynamicPageContent, staticTemplatePath);

            var expectedHtml = dynamicPageContent
                               .Replace("@Model.FirstName", person.FirstName)
                               .Replace("@Model.LastName", person.LastName);

            expectedHtml = staticTemplateContent.Replace(RazorFormat.TemplatePlaceHolder, expectedHtml);

            var templateOutput = dynamicPage.RenderToHtml(templateArgs);

            Console.WriteLine(templateOutput);

            Assert.That(templateOutput, Is.EqualTo(expectedHtml));
        }
Ejemplo n.º 3
0
        public void Can_Render_RazorPage_with_foreach()
        {
            RazorFormat.AddFileAndTemplate(staticTemplatePath, staticTemplateContent);
            var dynamicPage = AddViewPage("DynamicListTpl", dynamicListPagePath, dynamicListPageContent, staticTemplatePath);

            var expectedHtml = dynamicListPageContent
                               .Replace("@Model.FirstName", person.FirstName)
                               .Replace("@Model.LastName", person.LastName);

            var foreachLinks = "  <li>ServiceStack - http://www.servicestack.net</li>\r\n"
                               + "  <li>AjaxStack - http://www.ajaxstack.com</li>";

            expectedHtml = expectedHtml.ReplaceForeach(foreachLinks);

            expectedHtml = staticTemplateContent.Replace(RazorFormat.TemplatePlaceHolder, expectedHtml);

            var templateOutput = dynamicPage.RenderToHtml(templateArgs);

            Console.WriteLine(templateOutput);

            Assert.That(templateOutput, Is.EqualTo(expectedHtml));
        }
Ejemplo n.º 4
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 = ""websiteTemplate.cshtml""; }

<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();


            RazorFormat.AddFileAndTemplate("websiteTemplate.cshtml", websiteTemplate);
            var dynamicPage = AddViewPage(PageName, @"C:\path\to\page-tpl", pageTemplate);

            var template = dynamicPage.RenderToHtml();

            Console.WriteLine(template);
            Assert.That(template, Is.EqualTo(expectedHtml));
        }
Ejemplo n.º 5
0
        public void Layout_MasterPage_Scenarios_Adding_Sections()
        {
            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=""left-menu"">
            @RenderSection(""Menu"")
        </div>
        
        <div id=""body"">
            @RenderBody()
        </div>
        
        <div id=""footer"">
            @RenderSection(""Footer"")
        </div>
    
    </body>
</html>".NormalizeNewLines();

            var pageTemplate = @"<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>

@section Menu {
<ul>
  <li>About Item 1</li>
  <li>About Item 2</li>
</ul>
}

@section Footer {
<p>This is my custom footer for Home</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=""left-menu"">
            
<ul>
  <li>About Item 1</li>
  <li>About Item 2</li>
</ul>

        </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>
        
        <div id=""footer"">
            
<p>This is my custom footer for Home</p>

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


            RazorFormat.AddFileAndTemplate("websiteTemplate.cshtml", websiteTemplate);

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


            var html = dynamicPage.RenderToHtml();

            Console.WriteLine(html);
            Assert.That(html, Is.EqualTo(expectedHtml));
        }
Ejemplo n.º 6
0
        public void Can_Render_Static_RazorContentPage_that_populates_variable_and_displayed_on_website_template()
        {
            var websiteTemplate = @"<!doctype html>
<html lang=""en-us"">
<head>
	<title>Static page</title>
</head>
<body>
	<header>
		@RenderSection(""Header"")
	</header>

	<div id='menus'>
		@RenderSection(""Menu"")
	</div>

	<h1>Website Template</h1>

	<div id=""content"">@RenderBody()</div>

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

            var template = @"<h1>Static Markdown Template</h1>
@section Menu {
  @Menu(""Links"")
}

@section Header {
<h3>Static Page Title</h3>
}

<h3>heading 3</h3>
<p>paragraph</p>";

            var expectedHtml = @"<!doctype html>
<html lang=""en-us"">
<head>
	<title>Static page</title>
</head>
<body>
	<header>
		
<h3>Static Page Title</h3>

	</header>

	<div id='menus'>
		
  <ul>
<li><a href='About Us'>About Us</a></li>
<li><a href='Blog'>Blog</a></li>
<li><a href='Links' class='selected'>Links</a></li>
<li><a href='Contact'>Contact</a></li>
</ul>


	</div>

	<h1>Website Template</h1>

	<div id=""content""><h1>Static Markdown Template</h1>




<h3>heading 3</h3>
<p>paragraph</p></div>

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

            RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase <>);

            var websiteTemplatePath = "websiteTemplate.cshtml";

            RazorFormat.AddFileAndTemplate(websiteTemplatePath, websiteTemplate);

            var staticPage = new ViewPageRef(RazorFormat,
                                             "pagetpl", "StaticTpl", template, RazorPageType.ContentPage)
            {
                Service  = RazorFormat.TemplateService,
                Template = websiteTemplatePath,
            };

            RazorFormat.AddPage(staticPage);
            RazorFormat.TemplateService.RegisterPage("pagetpl", "StaticTpl");
            RazorFormat.TemplateProvider.CompileQueuedPages();

            var templateOutput = RazorFormat.RenderStaticPage("pagetpl").NormalizeNewLines();

            Console.WriteLine(templateOutput);
            Assert.That(templateOutput, Is.EqualTo(expectedHtml));
        }
Ejemplo n.º 7
0
        public void Can_Render_RazorTemplate_with_section_and_variable_placeholders()
        {
            var template            = @"<h2>Welcome to Razor!</h2>

@{ var lastName = Model.LastName; }

<p>Hello @Upper(lastName), @Model.FirstName,</p>

@section Breadcrumbs {
<h3>Breadcrumbs</h3>
@Combine("" / "", Model.FirstName, lastName)
}

@section Menus {
<h3>Menus</h3>
<ul>
@foreach (var link in Model.Links) {
	<li>@link.Name - @link.Href
		<ul>
		@{ var labels = link.Labels; }
		@foreach (var label in labels) { 
			<li>@label</li>
		}
		</ul>
	</li>
}
</ul>
}";
            var websiteTemplatePath = "websiteTemplate.cshtml";

            var websiteTemplate = @"<!doctype html>
<html lang=""en-us"">
<head>
	<title>Bellot page</title>
</head>
<body>

	<header>
		@RenderSection(""Menus"")
	</header>

	<h1>Website Template</h1>

	<div id=""content"">@RenderBody()</div>

	<footer>
		@RenderSection(""Breadcrumbs"")
	</footer>

</body>
</html>";

            var expectedHtml =
                @"<!doctype html>
<html lang=""en-us"">
<head>
	<title>Bellot page</title>
</head>
<body>

	<header>
		
<h3>Menus</h3>
<ul>
	<li>ServiceStack - http://www.servicestack.net
		<ul>
			<li>REST</li>
			<li>JSON</li>
			<li>XML</li>
		</ul>
	</li>
	<li>AjaxStack - http://www.ajaxstack.com
		<ul>
			<li>HTML5</li>
			<li>AJAX</li>
			<li>SPA</li>
		</ul>
	</li>
</ul>

	</header>

	<h1>Website Template</h1>

	<div id=""content""><h2>Welcome to Razor!</h2>


<p>Hello BELLOT, Demis,</p>



</div>

	<footer>
		
<h3>Breadcrumbs</h3>
Demis / Bellot

	</footer>

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

            RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase <>);

            RazorFormat.AddFileAndTemplate(websiteTemplatePath, websiteTemplate);
            AddViewPage("DynamicModelTpl", "/path/to/page-tpl", template, websiteTemplatePath);

            var razorTemplate = RazorFormat.ExecuteTemplate(
                person, "DynamicModelTpl", websiteTemplatePath);

            var templateOutput = razorTemplate.Result.NormalizeNewLines();

            Console.WriteLine(templateOutput);

            Assert.That(templateOutput, Is.EqualTo(expectedHtml));
        }