Esempio n. 1
0
        public void RendersSimpleLayoutWithReferencedTitle()
        {
            const string TemplateText =
                @"@model Simple.Web.Razor.Tests.TestModel
@{
    Layout = ""~/Views/Layouts/SimpleLayoutWithTitle.cshtml"";
    ViewBag.Title = @Handler.Title;
}<p>@Model.Text</p>";

            const string Expected = @"<!DOCTYPE html><html><head><title>Foo</title></head><body><p>Test Text</p></body></html>";

            var type = RazorTypeBuilderHelpers.CreateTypeFromText(TemplateText);

            var output = new MockHandler {
                Model = new TestModel {
                    Text = "Test Text"
                }, Handler = new HandlerStub {
                    Title = "Foo"
                }
            };
            var writer = new StringWriter();

            RazorHtmlMediaTypeHandler.RenderView(output, writer, type);

            Assert.Equal(Expected, HtmlComparison.Cleanse(writer.ToString()));
        }
Esempio n. 2
0
        public void RenderWithOptionalSection()
        {
            const string TemplateText =
                @"@model Simple.Web.Razor.Tests.TestModel
@{
    Layout = ""~/Views/Layouts/SimpleLayoutWithSections.cshtml"";
}
<span>@Model.Text</span>
@section Two {<p>I am in section two.</p>}";

            const string Expected = @"<!DOCTYPE html><html><head><title>Sections Layout Page</title></head><body><h1>Section One</h1><p><span>Test Text</span></p><h1>Section Two</h1><p>I am in section two.</p></body></html>";

            Type type;

            using (var reader = new StringReader(TemplateText))
            {
                type = new RazorTypeBuilder().CreateType(reader);
            }

            var output = new MockHandler {
                Model = new TestModel {
                    Text = "Test Text"
                }, Handler = null
            };
            var writer = new StringWriter();

            RazorHtmlMediaTypeHandler.RenderView(output, writer, type);

            Assert.Equal(Expected, HtmlComparison.Cleanse(writer.ToString()));
        }
Esempio n. 3
0
        public void RenderWithSectioDuplicated()
        {
            const string TemplateText =
                @"@model Simple.Web.Razor.Tests.TestModel
@{
    Layout = ""~/Views/Layouts/SimpleLayoutWithSectionDuplicated.cshtml"";
}
<span>@Model.Text</span>
@section Two {<p>I am in section two.</p>}";

            const string Expected = @"<!DOCTYPE html><html><head><title>Sections Layout Page</title></head><body><h1>Section Two - Once</h1><p>I am in section two.</p><p><span>Test Text</span></p><h1>Section Two - Twice</h1><p>I am in section two.</p></body></html>";

            var type = RazorTypeBuilderHelpers.CreateTypeFromText(TemplateText);

            var output = new MockHandler {
                Model = new TestModel {
                    Text = "Test Text"
                }, Handler = null
            };
            var writer = new StringWriter();

            RazorHtmlMediaTypeHandler.RenderView(output, writer, type);

            Assert.Equal(Expected, HtmlComparison.Cleanse(writer.ToString()));
        }
Esempio n. 4
0
        public void RendersSimpleLayoutWithTitle()
        {
            const string TemplateText =
                @"@model Simple.Web.Razor.Tests.TestModel
@{
    Layout = ""~/Views/Layouts/SimpleLayoutWithTitle.cshtml"";
    ViewBag.Title = ""Custom Layout Title"";
}<p>@Model.Text</p>";

            const string Expected = @"<!DOCTYPE html><html><head><title>Custom Layout Title</title></head><body><p>Test Text</p></body></html>";

            Type type;

            using (var reader = new StringReader(TemplateText))
            {
                type = new RazorTypeBuilder().CreateType(reader);
            }

            var output = new MockHandler {
                Model = new TestModel {
                    Text = "Test Text"
                }, Handler = null
            };
            var writer = new StringWriter();

            RazorHtmlMediaTypeHandler.RenderView(output, writer, type);

            Assert.Equal(Expected, HtmlComparison.Cleanse(writer.ToString()));
        }