Permalink
Browse files

Initial stab at Razor sections.

  • Loading branch information...
1 parent 6c24955 commit d3f5cf61ad6dc735228d03b6949129807c5e4e11 @ianbattersby ianbattersby committed Feb 2, 2013
Binary file not shown.
Binary file not shown.
@@ -793,14 +793,18 @@
</summary>
</member>
<member name="P:System.Web.Mvc.Properties.MvcResources.DefaultControllerFactory_ControllerNameAmbiguous_WithoutRouteUrl">
- <summary>
- Looks up a localized string similar to Multiple types were found that match the controller named &apos;{0}&apos;. This can happen if the route that services this request does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the &apos;MapRoute&apos; method that takes a &apos;namespaces&apos; parameter.{2}{2}The request for &apos;{0}&apos; has found the following matching controllers:{1}.
- </summary>
+ <summary>
+ Looks up a localized string similar to Multiple types were found that match the controller named &apos;{0}&apos;. This can happen if the route that services this request does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the &apos;MapRoute&apos; method that takes a &apos;namespaces&apos; parameter.
+
+ The request for &apos;{0}&apos; has found the following matching controllers:{1}.
+ </summary>
</member>
<member name="P:System.Web.Mvc.Properties.MvcResources.DefaultControllerFactory_ControllerNameAmbiguous_WithRouteUrl">
- <summary>
- Looks up a localized string similar to Multiple types were found that match the controller named &apos;{0}&apos;. This can happen if the route that services this request (&apos;{1}&apos;) does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the &apos;MapRoute&apos; method that takes a &apos;namespaces&apos; parameter.{3}{3}The request for &apos;{0}&apos; has found the following matching controllers:{2}.
- </summary>
+ <summary>
+ Looks up a localized string similar to Multiple types were found that match the controller named &apos;{0}&apos;. This can happen if the route that services this request (&apos;{1}&apos;) does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the &apos;MapRoute&apos; method that takes a &apos;namespaces&apos; parameter.
+
+ The request for &apos;{0}&apos; has found the following matching controllers:{2}.
+ </summary>
</member>
<member name="P:System.Web.Mvc.Properties.MvcResources.DefaultControllerFactory_ErrorCreatingController">
<summary>
Binary file not shown.
Binary file not shown.
@@ -1096,81 +1096,6 @@
Looks up a localized string similar to In order to put a symbol back, it must have been the symbol which ended at the current position. The specified symbol ends at {0}, but the current position is {1}.
</summary>
</member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_BackgroundThreadShutdown">
- <summary>
- Looks up a localized string similar to [BG][{0}] Shutdown.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_BackgroundThreadStart">
- <summary>
- Looks up a localized string similar to [BG][{0}] Startup.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_ChangesArrived">
- <summary>
- Looks up a localized string similar to [BG][{0}] {1} changes arrived.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_ChangesDiscarded">
- <summary>
- Looks up a localized string similar to [BG][{0}] Discarded {1} changes.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_CollectedDiscardedChanges">
- <summary>
- Looks up a localized string similar to [BG][{0}] Collecting {1} discarded changes.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_Disabled">
- <summary>
- Looks up a localized string similar to Disabled.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_EditorProcessedChange">
- <summary>
- Looks up a localized string similar to [P][{0}] {3} Change in {2} milliseconds: {1}.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_EditorReceivedChange">
- <summary>
- Looks up a localized string similar to [P][{0}] Received Change: {1}.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_Enabled">
- <summary>
- Looks up a localized string similar to Enabled.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_Format">
- <summary>
- Looks up a localized string similar to [Razor] {0}.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_NoChangesArrived">
- <summary>
- Looks up a localized string similar to [BG][{0}] no changes arrived?.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_ParseComplete">
- <summary>
- Looks up a localized string similar to [BG][{0}] Parse Complete in {1} milliseconds.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_QueuingParse">
- <summary>
- Looks up a localized string similar to [M][{0}] Queuing Parse for: {1}.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_Startup">
- <summary>
- Looks up a localized string similar to [Razor] Editor Tracing {0}.
- </summary>
- </member>
- <member name="P:System.Web.Razor.Resources.RazorResources.Trace_TreesCompared">
- <summary>
- Looks up a localized string similar to [BG][{0}] Trees Compared in {1} milliseconds. Different = {2}.
- </summary>
- </member>
<member name="P:System.Web.Razor.Resources.RazorResources.VBSymbol_CharacterLiteral">
<summary>
Looks up a localized string similar to &lt;&lt;character literal&gt;&gt;.
@@ -1230,6 +1155,9 @@
<summary>
Gets the 1-based index of the line referred to by this Source Location.
</summary>
+ <remarks>
+ THIS IS 1-based!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ </remarks>
</member>
<member name="M:System.Web.Razor.Text.TextChange.#ctor(System.Int32,System.Int32,System.Web.Razor.Text.ITextBuffer,System.Int32,System.Web.Razor.Text.ITextBuffer)">
<summary>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,6 +2,9 @@
{
using System;
using System.IO;
+
+ using Simple.Web.TestHelpers;
+
using Xunit;
public class RazorLayoutTests
@@ -28,7 +31,7 @@ public void RendersSimpleLayout()
RazorHtmlMediaTypeHandler.RenderView(output, writer, type);
- Assert.Equal(Expected, this.CleanseForComparison(writer.ToString()));
+ Assert.Equal(Expected, HtmlComparison.Cleanse(writer.ToString()));
}
[Fact]
@@ -54,7 +57,7 @@ public void RendersSimpleLayoutWithTitle()
RazorHtmlMediaTypeHandler.RenderView(output, writer, type);
- Assert.Equal(Expected, this.CleanseForComparison(writer.ToString()));
+ Assert.Equal(Expected, HtmlComparison.Cleanse(writer.ToString()));
}
[Fact]
@@ -80,17 +83,12 @@ public void RendersSimpleLayoutWithReferencedTitle()
RazorHtmlMediaTypeHandler.RenderView(output, writer, type);
- Assert.Equal(Expected, this.CleanseForComparison(writer.ToString()));
+ Assert.Equal(Expected, HtmlComparison.Cleanse(writer.ToString()));
}
public class HandlerStub
{
public string Title { get; set; }
}
-
- private string CleanseForComparison(string result)
- {
- return result.Trim().Replace("\n", "").Replace("\r", "");
- }
}
}
@@ -0,0 +1,146 @@
+namespace Simple.Web.Razor.Tests
+{
+ using System;
+ using System.IO;
+
+ using Simple.Web.TestHelpers;
+
+ using Xunit;
+
+ public class RazorSectionsTests
+ {
+ [Fact]
+ public void RenderTwoSection()
+ {
+ 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>}
+@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>I am in section one.</p><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()));
+ }
+
+ [Fact]
+ 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));
+ }
+
+ [Fact]
+ 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()));
+
+ }
+
+ [Fact]
+ 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>";
+
+ 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()));
+ }
+
+ [Fact]
+ public void RenderSectionWithinPage()
+ {
+ const string TemplateText =
+ @"@model Simple.Web.Razor.Tests.TestModel
+@{
+ Layout = ""~/Views/Layouts/SimpleLayout.cshtml"";
+}
+<p>@Model.Text</p>
+@section Two {<p>I am in section two.</p>}
+@RenderSection(""Two"", required:true)";
+
+ const string Expected = @"<!DOCTYPE html><html><head><title>Simple Layout Page</title></head><body><p>Test Text</p><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()));
+ }
+ }
+}
@@ -52,6 +52,7 @@
</Compile>
<Compile Include="RazorHtmlContentTypeHandlerTests.cs" />
<Compile Include="RazorLayoutTests.cs" />
+ <Compile Include="RazorSectionsTests.cs" />
<Compile Include="RazorTypeBuilderTests.cs" />
<Compile Include="RazorViewsTests.cs" />
<Compile Include="SimpleRazorBuildProviderTests.cs" />
@@ -62,6 +63,10 @@
<Project>{A226D857-22FD-4C10-8596-EB7821C59255}</Project>
<Name>Simple.Web.Razor</Name>
</ProjectReference>
+ <ProjectReference Include="..\Simple.Web.TestHelpers\Simple.Web.TestHelpers.csproj">
+ <Project>{2C65A993-1EB6-4971-A1EE-B0FCF31AF525}</Project>
+ <Name>Simple.Web.TestHelpers</Name>
+ </ProjectReference>
<ProjectReference Include="..\Simple.Web\Simple.Web.csproj">
<Project>{903C289D-4CAE-4259-80DA-79D74CE06DCE}</Project>
<Name>Simple.Web</Name>
@@ -92,6 +97,8 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
+ <None Include="Views\Layouts\SimpleLayoutWithSectionDuplicated.cshtml" />
+ <None Include="Views\Layouts\SimpleLayoutWithSections.cshtml" />
<None Include="Views\Layouts\SimpleLayoutWithTitle.cshtml" />
<None Include="Views\Layouts\SimpleLayout.cshtml" />
</ItemGroup>
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Sections Layout Page</title>
+</head>
+<body>
+<h1>Section Two - Once</h1>
+@RenderSection("Two", required:true)
+<p>@RenderBody()</p>
+<h1>Section Two - Twice</h1>
+@RenderSection("Two", required:true)
+</body>
+</html>
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Sections Layout Page</title>
+</head>
+<body>
+<h1>Section One</h1>
+@RenderSection("One", required:false)
+<p>@RenderBody()</p>
+<h1>Section Two</h1>
+@RenderSection("Two", required:true)
+</body>
+</html>
@@ -8,13 +8,22 @@ internal class SimpleRazorEngineHost : RazorEngineHost
{
public SimpleRazorEngineHost(RazorCodeLanguage codeLanguage) : base(codeLanguage)
{
- base.DefaultBaseClass = SimpleRazorConfiguration.BaseClass;
- base.DefaultClassName = SimpleRazorConfiguration.ClassName;
- base.DefaultNamespace = SimpleRazorConfiguration.Namespace;
+ this.DefaultBaseClass = SimpleRazorConfiguration.BaseClass;
+ this.DefaultClassName = SimpleRazorConfiguration.ClassPrefix;
+ this.DefaultNamespace = SimpleRazorConfiguration.Namespace;
+
+ base.GeneratedClassContext = new GeneratedClassContext(
+ executeMethodName: "Execute",
+ writeMethodName: "Write",
+ writeLiteralMethodName: "WriteLiteral",
+ writeToMethodName: "WriteTo",
+ writeLiteralToMethodName: "WriteLiteralTo",
+ templateTypeName: null,
+ defineSectionMethodName: "DefineSection");
foreach (var namespaceAssembly in SimpleRazorConfiguration.NamespaceImports)
{
- base.NamespaceImports.Add(namespaceAssembly.Key);
+ this.NamespaceImports.Add(namespaceAssembly.Key);
}
}
Oops, something went wrong.

0 comments on commit d3f5cf6

Please sign in to comment.