示例#1
0
        public void RenderWithoutNonOptionalErrors()
        {
            const string TemplateText =
                @"@model Simple.Web.Razor.Tests.TestModel
@{
    Layout = ""~/Views/Layouts/SimpleLayoutWithSections.cshtml"";
}
<span>@Model.Text</span>
@section One {<p>I am in section one.</p>}";

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

            Assert.Throws <ArgumentException>(() => RazorHtmlMediaTypeHandler.RenderView(output, writer, type));
        }
示例#2
0
        public void Renders()
        {
            const string templateText =
                @"@model Simple.Web.Razor.Tests.TestModel
<!DOCTYPE html><html><head><title>@Handler.Title</title></head><body>@Model.Text</body></html>";

            const string expected = @"<!DOCTYPE html><html><head><title>Foo</title></head><body>Test Text</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 = new HandlerStub {
                    Title = "Foo"
                }
            };

            var writer = new StringWriter();

            RazorHtmlMediaTypeHandler.RenderView(output, writer, type);
            Assert.Equal(expected, writer.ToString().Trim());
        }
示例#3
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()));
        }
        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()));            
           
        }
示例#5
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>";

            Type type;

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

            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()));
        }
 public void GetsATypeGivenAHandler()
 {
     Type type;
     using (var reader = new StringReader(HandlerTemplateText))
     {
         type = new RazorTypeBuilder().CreateType(reader, typeof (TestHandler), null);
     }
     Assert.NotNull(type);
 }
 public void GetsATypeGivenADerivedModel()
 {
     Type type;
     using (var reader = new StringReader(ModelTemplateText))
     {
         type = new RazorTypeBuilder().CreateType(reader, null, typeof (SuperTestModel));
     }
     Assert.NotNull(type);
 }
 public void GetsHandlerTypeFromRazorMarkup()
 {
     Type type;
     using (var reader = new StringReader(HandlerTemplateText))
     {
         type = new RazorTypeBuilder().CreateType(reader);
     }
     Assert.NotNull(type);
     var genericArguments = type.BaseType.GetGenericArguments();
     Assert.Equal(1, genericArguments.Length);
     Assert.Equal(typeof (TestHandler), genericArguments[0]);
 }
示例#9
0
        public void GetsHandlerTypeFromRazorMarkup()
        {
            Type type;

            using (var reader = new StringReader(HandlerTemplateText))
            {
                type = new RazorTypeBuilder().CreateType(reader);
            }
            Assert.NotNull(type);
            var genericArguments = type.BaseType.GetGenericArguments();

            Assert.Equal(1, genericArguments.Length);
            Assert.Equal(typeof(TestHandler), genericArguments[0]);
        }
        public void GetsComplexModelTypeFromRazorMarkup()
        {
            const string templateText =
                @"@model IEnumerable<Simple.Web.Razor.Tests.TestModel>
<!DOCTYPE html><html><body>@foreach (var m in @Model)
{
<p>@m.Text</p>
}
</body></html>";
            Type type;
            using (var reader = new StringReader(templateText))
            {
                type = new RazorTypeBuilder().CreateType(reader);
            }
            Assert.NotNull(type);
            var genericArguments = type.BaseType.GetGenericArguments();
            Assert.Equal(1, genericArguments.Length);
            Assert.Equal(typeof(IEnumerable<TestModel>), genericArguments[0]);
        }
        public void Renders()
        {
            const string templateText =
                @"@model Simple.Web.Razor.Tests.TestModel
<!DOCTYPE html><html><head><title>@Var.Title</title></head><body>@Model.Text</body></html>";

            const string expected = @"<!DOCTYPE html><html><head><title>Foo</title></head><body>Test Text</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"}, Variables = new Dictionary<string, object> { { "Title", "Foo"}}};

            var writer = new StringWriter();
            RazorHtmlContentTypeHandler.RenderView(output, writer, type);
            Assert.Equal(expected, writer.ToString().Trim());
        }
示例#12
0
        public void GetsComplexModelTypeFromRazorMarkup()
        {
            const string templateText =
                @"@model IEnumerable<Simple.Web.Razor.Tests.TestModel>
<!DOCTYPE html><html><body>@foreach (var m in @Model)
{
<p>@m.Text</p>
}
</body></html>";
            Type type;

            using (var reader = new StringReader(templateText))
            {
                type = new RazorTypeBuilder().CreateType(reader);
            }
            Assert.NotNull(type);
            var genericArguments = type.BaseType.GetGenericArguments();

            Assert.Equal(1, genericArguments.Length);
            Assert.Equal(typeof(IEnumerable <TestModel>), genericArguments[0]);
        }
示例#13
0
        public void RenderWithoutNonOptionalErrors()
        {
            const string TemplateText =
                @"@model Simple.Web.Razor.Tests.TestModel
@{
    Layout = ""~/Views/Layouts/SimpleLayoutWithSections.cshtml"";
}
<span>@Model.Text</span>
@section One {<p>I am in section one.</p>}";

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

            Assert.Throws<ArgumentException>(() => RazorHtmlMediaTypeHandler.RenderView(output, writer, type));
        }
示例#14
0
        public void RendersSimpleLayout()
        {
            const string TemplateText =
                @"@model Simple.Web.Razor.Tests.TestModel
@{
    Layout = ""~/Views/Layouts/SimpleLayout.cshtml"";
}<p>@Model.Text</p>";

            const string Expected = @"<!DOCTYPE html><html><head><title>Simple Layout Page</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, this.CleanseForComparison(writer.ToString()));
        }
示例#15
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>";

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

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