From 9e12230eef513a2093a637ec768051b39005676c Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Mon, 3 Apr 2017 11:04:44 -0700 Subject: [PATCH] Add RazorPage test without model --- .../CodeGenerationTests.cs | 12 + .../Input/RazorPagesWithoutModel.cshtml | 36 +++ .../DesignTime/RazorPagesWithoutModel.cs | 94 ++++++++ .../RazorPagesWithoutModel.mappings.txt | 41 ++++ .../Output/Runtime/RazorPagesWithoutModel.cs | 218 ++++++++++++++++++ 5 files changed, 401 insertions(+) create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Input/RazorPagesWithoutModel.cshtml create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/DesignTime/RazorPagesWithoutModel.cs create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/DesignTime/RazorPagesWithoutModel.mappings.txt create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/Runtime/RazorPagesWithoutModel.cs diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/CodeGenerationTests.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/CodeGenerationTests.cs index f041f37813..daa1b65bf0 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/CodeGenerationTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/CodeGenerationTests.cs @@ -68,6 +68,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions { RunRuntimeTest("RazorPages", BuildDivDescriptors()); } + + [Fact] + public void RazorEngine_RazorPagesWithoutModel_Runtime() + { + RunRuntimeTest("RazorPagesWithoutModel", BuildDivDescriptors()); + } #endregion #region DesignTime @@ -124,6 +130,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions { RunDesignTimeTest("RazorPages", BuildDivDescriptors()); } + + [Fact] + public void RazorEngine_RazorPagesWithoutModel_DesignTime() + { + RunDesignTimeTest("RazorPagesWithoutModel", BuildDivDescriptors()); + } #endregion private static void RunRuntimeTest(string testName, IEnumerable descriptors = null) diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Input/RazorPagesWithoutModel.cshtml b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Input/RazorPagesWithoutModel.cshtml new file mode 100644 index 0000000000..1122dd4139 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Input/RazorPagesWithoutModel.cshtml @@ -0,0 +1,36 @@ +@page + +@addTagHelper "*, TestAssembly" +@using Microsoft.AspNetCore.Mvc.RazorPages + +@functions { + public IActionResult OnPost(Customer customer) + { + Name = customer.Name; + return Redirect("~/customers/inlinepagemodels/"); + } + + public string Name { get; set; } + + public class Customer + { + public string Name { get; set; } + } +} + +

New Customer

+
+
+
+ +
+ + +
+
+
+
+ +
+
+
diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/DesignTime/RazorPagesWithoutModel.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/DesignTime/RazorPagesWithoutModel.cs new file mode 100644 index 0000000000..09cdff3487 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/DesignTime/RazorPagesWithoutModel.cs @@ -0,0 +1,94 @@ +namespace AspNetCore +{ + #line hidden + using TModel = _TestFiles_Input_RazorPagesWithoutModel_cshtml; + using System; + using System.Threading.Tasks; +#line 2 "" +using System.Linq; + +#line default +#line hidden +#line 3 "" +using System.Collections.Generic; + +#line default +#line hidden +#line 4 "" +using Microsoft.AspNetCore.Mvc; + +#line default +#line hidden +#line 5 "" +using Microsoft.AspNetCore.Mvc.Rendering; + +#line default +#line hidden +#line 6 "" +using Microsoft.AspNetCore.Mvc.ViewFeatures; + +#line default +#line hidden +#line 4 "/TestFiles/Input/RazorPagesWithoutModel.cshtml" +using Microsoft.AspNetCore.Mvc.RazorPages; + +#line default +#line hidden + public class _TestFiles_Input_RazorPagesWithoutModel_cshtml : global::Microsoft.AspNetCore.Mvc.RazorPages.Page + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + private static System.Object __o = null; + private global::DivTagHelper __DivTagHelper = null; + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + __DivTagHelper = CreateTagHelper(); +#line 25 "/TestFiles/Input/RazorPagesWithoutModel.cshtml" + __o = Name; + +#line default +#line hidden + __DivTagHelper = CreateTagHelper(); + __DivTagHelper = CreateTagHelper(); + __DivTagHelper = CreateTagHelper(); + __DivTagHelper = CreateTagHelper(); + } + #pragma warning restore 1998 +#line 6 "/TestFiles/Input/RazorPagesWithoutModel.cshtml" + + public IActionResult OnPost(Customer customer) + { + Name = customer.Name; + return Redirect("~/customers/inlinepagemodels/"); + } + + public string Name { get; set; } + + public class Customer + { + public string Name { get; set; } + } + +#line default +#line hidden + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<_TestFiles_Input_RazorPagesWithoutModel_cshtml> Html { get; private set; } + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<_TestFiles_Input_RazorPagesWithoutModel_cshtml> ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<_TestFiles_Input_RazorPagesWithoutModel_cshtml>)PageContext?.ViewData; + public _TestFiles_Input_RazorPagesWithoutModel_cshtml Model => ViewData.Model; + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/DesignTime/RazorPagesWithoutModel.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/DesignTime/RazorPagesWithoutModel.mappings.txt new file mode 100644 index 0000000000..b3fdc25f13 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/DesignTime/RazorPagesWithoutModel.mappings.txt @@ -0,0 +1,41 @@ +Source Location: (23:2,14 [17] /TestFiles/Input/RazorPagesWithoutModel.cshtml) +|"*, TestAssembly"| +Generated Location: (970:41,29 [17] ) +|"*, TestAssembly"| + +Source Location: (571:24,47 [4] /TestFiles/Input/RazorPagesWithoutModel.cshtml) +|Name| +Generated Location: (1483:53,47 [4] ) +|Name| + +Source Location: (100:5,12 [283] /TestFiles/Input/RazorPagesWithoutModel.cshtml) +| + public IActionResult OnPost(Customer customer) + { + Name = customer.Name; + return Redirect("~/customers/inlinepagemodels/"); + } + + public string Name { get; set; } + + public class Customer + { + public string Name { get; set; } + } +| +Generated Location: (1924:64,12 [283] ) +| + public IActionResult OnPost(Customer customer) + { + Name = customer.Name; + return Redirect("~/customers/inlinepagemodels/"); + } + + public string Name { get; set; } + + public class Customer + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/Runtime/RazorPagesWithoutModel.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/Runtime/RazorPagesWithoutModel.cs new file mode 100644 index 0000000000..6c6b9bf2c1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/Output/Runtime/RazorPagesWithoutModel.cs @@ -0,0 +1,218 @@ +#pragma checksum "/TestFiles/Input/RazorPagesWithoutModel.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "c933419e57888c980327bbedf321c46e65488378" +namespace AspNetCore +{ + #line hidden + using System; + using System.Threading.Tasks; +#line 2 "" +using System.Linq; + +#line default +#line hidden +#line 3 "" +using System.Collections.Generic; + +#line default +#line hidden +#line 4 "" +using Microsoft.AspNetCore.Mvc; + +#line default +#line hidden +#line 5 "" +using Microsoft.AspNetCore.Mvc.Rendering; + +#line default +#line hidden +#line 6 "" +using Microsoft.AspNetCore.Mvc.ViewFeatures; + +#line default +#line hidden +#line 4 "/TestFiles/Input/RazorPagesWithoutModel.cshtml" +using Microsoft.AspNetCore.Mvc.RazorPages; + +#line default +#line hidden + public class _TestFiles_Input_RazorPagesWithoutModel_cshtml : global::Microsoft.AspNetCore.Mvc.RazorPages.Page + { + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_0 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("class", new global::Microsoft.AspNetCore.Html.HtmlString("text-danger"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_1 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("class", new global::Microsoft.AspNetCore.Html.HtmlString("col-md-10"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_2 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("class", new global::Microsoft.AspNetCore.Html.HtmlString("form-group"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_3 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("class", new global::Microsoft.AspNetCore.Html.HtmlString("col-md-offset-2 col-md-10"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + #line hidden + #pragma warning disable 0414 + private string __tagHelperStringValueBuffer = null; + #pragma warning restore 0414 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext = null; + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner(); + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null; + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager + { + get + { + if (__backed__tagHelperScopeManager == null) + { + __backed__tagHelperScopeManager = new Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope); + } + return __backed__tagHelperScopeManager; + } + } + private global::DivTagHelper __DivTagHelper = null; + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + BeginContext(7, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(86, 2, true); + WriteLiteral("\r\n"); + EndContext(); + BeginContext(386, 75, true); + WriteLiteral("\r\n

New Customer

\r\n
\r\n "); + EndContext(); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("div", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + } + ); + __DivTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__DivTagHelper); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_0); + BeginContext(461, 31, false); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + EndContext(); + BeginContext(492, 6, true); + WriteLiteral("\r\n "); + EndContext(); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("div", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + BeginContext(522, 48, true); + WriteLiteral("\r\n \r\n "); + EndContext(); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("div", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + BeginContext(616, 101, true); + WriteLiteral("\r\n \r\n \r\n "); + EndContext(); + } + ); + __DivTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__DivTagHelper); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1); + BeginContext(593, 130, false); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + EndContext(); + BeginContext(723, 6, true); + WriteLiteral("\r\n "); + EndContext(); + } + ); + __DivTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__DivTagHelper); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2); + BeginContext(498, 237, false); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + EndContext(); + BeginContext(735, 6, true); + WriteLiteral("\r\n "); + EndContext(); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("div", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + BeginContext(765, 10, true); + WriteLiteral("\r\n "); + EndContext(); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("div", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + BeginContext(814, 83, true); + WriteLiteral("\r\n \r\n "); + EndContext(); + } + ); + __DivTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__DivTagHelper); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_3); + BeginContext(775, 128, false); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + EndContext(); + BeginContext(903, 6, true); + WriteLiteral("\r\n "); + EndContext(); + } + ); + __DivTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__DivTagHelper); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2); + BeginContext(741, 174, false); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + EndContext(); + BeginContext(915, 11, true); + WriteLiteral("\r\n\r\n"); + EndContext(); + } + #pragma warning restore 1998 +#line 6 "/TestFiles/Input/RazorPagesWithoutModel.cshtml" + + public IActionResult OnPost(Customer customer) + { + Name = customer.Name; + return Redirect("~/customers/inlinepagemodels/"); + } + + public string Name { get; set; } + + public class Customer + { + public string Name { get; set; } + } + +#line default +#line hidden + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<_TestFiles_Input_RazorPagesWithoutModel_cshtml> Html { get; private set; } + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<_TestFiles_Input_RazorPagesWithoutModel_cshtml> ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<_TestFiles_Input_RazorPagesWithoutModel_cshtml>)PageContext?.ViewData; + public _TestFiles_Input_RazorPagesWithoutModel_cshtml Model => ViewData.Model; + } +}