diff --git a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/DefaultTagHelperContent.cs b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/DefaultTagHelperContent.cs index dfd17be39c..5d776a4474 100644 --- a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/DefaultTagHelperContent.cs +++ b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/DefaultTagHelperContent.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers /// /// Default concrete . /// - public class DefaultTagHelperContent : TagHelperContent, ITextWriterCopyable + public class DefaultTagHelperContent : TagHelperContent { private readonly BufferEntryCollection _buffer; @@ -124,15 +124,6 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers return string.Join(string.Empty, _buffer); } - /// - public void CopyTo([NotNull] TextWriter writer) - { - foreach (var value in _buffer) - { - writer.Write(value); - } - } - /// public override string ToString() { diff --git a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/ITextWriterCopyable.cs b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/ITextWriterCopyable.cs deleted file mode 100644 index 07f49bc0b2..0000000000 --- a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/ITextWriterCopyable.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; - -namespace Microsoft.AspNet.Razor.Runtime.TagHelpers -{ - /// - /// Specifies the contract for copying to a . - /// - public interface ITextWriterCopyable - { - /// - /// Copies to the . - /// - /// The target. - void CopyTo(TextWriter writer); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperOutput.cs b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperOutput.cs index 7bdf92b10a..f69c287ffd 100644 --- a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperOutput.cs +++ b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperOutput.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Globalization; using System.Text; using Microsoft.Framework.Internal; -using Microsoft.Framework.WebEncoders; namespace Microsoft.AspNet.Razor.Runtime.TagHelpers { @@ -15,16 +14,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers /// public class TagHelperOutput { - private bool _isTagNameNullOrWhitespace; - private string _tagName; - private readonly IHtmlEncoder _htmlEncoder; private readonly DefaultTagHelperContent _preContent; private readonly DefaultTagHelperContent _content; private readonly DefaultTagHelperContent _postContent; // Internal for testing internal TagHelperOutput(string tagName) - : this(tagName, new Dictionary(StringComparer.OrdinalIgnoreCase), null) + : this(tagName, new Dictionary(StringComparer.OrdinalIgnoreCase)) { } @@ -33,19 +29,15 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers /// /// The HTML element's tag name. /// The HTML attributes. - /// The used - /// to encode HTML attribute values. public TagHelperOutput( string tagName, - [NotNull] IDictionary attributes, - [NotNull] IHtmlEncoder htmlEncoder) + [NotNull] IDictionary attributes) { TagName = tagName; Attributes = new Dictionary(attributes, StringComparer.OrdinalIgnoreCase); _preContent = new DefaultTagHelperContent(); _content = new DefaultTagHelperContent(); _postContent = new DefaultTagHelperContent(); - _htmlEncoder = htmlEncoder; } /// @@ -54,18 +46,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers /// /// A whitespace or null value results in no start or end tag being rendered. /// - public string TagName - { - get - { - return _tagName; - } - set - { - _tagName = value; - _isTagNameNullOrWhitespace = string.IsNullOrWhiteSpace(_tagName); - } - } + public string TagName { get; set; } /// /// The HTML element's pre content. @@ -125,107 +106,6 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers /// public IDictionary Attributes { get; } - /// - /// Generates the 's start tag. - /// - /// string.Empty if is null or whitespace. Otherwise, the - /// representation of the 's start tag. - public string GenerateStartTag() - { - // Only render a start tag if the tag name is not whitespace - if (_isTagNameNullOrWhitespace) - { - return string.Empty; - } - - var sb = new StringBuilder(); - - sb.Append('<') - .Append(TagName); - - foreach (var attribute in Attributes) - { - var value = _htmlEncoder.HtmlEncode(attribute.Value); - sb.Append(' ') - .Append(attribute.Key) - .Append("=\"") - .Append(value) - .Append('"'); - } - - if (SelfClosing) - { - sb.Append(" /"); - } - - sb.Append('>'); - - return sb.ToString(); - } - - /// - /// Generates the 's . - /// - /// null if is not null or whitespace - /// and is true. - /// Otherwise, an containing the . - public ITextWriterCopyable GeneratePreContent() - { - if (!_isTagNameNullOrWhitespace && SelfClosing) - { - return null; - } - - return _preContent; - } - - /// - /// Generates the 's body. - /// - /// null if is not null or whitespace - /// and is true. - /// Otherwise, an containing the . - public ITextWriterCopyable GenerateContent() - { - if (!_isTagNameNullOrWhitespace && SelfClosing) - { - return null; - } - - return _content; - } - - /// - /// Generates the 's . - /// - /// null if is not null or whitespace - /// and is true. - /// Otherwise, an containing the . - public ITextWriterCopyable GeneratePostContent() - { - if (!_isTagNameNullOrWhitespace && SelfClosing) - { - return null; - } - - return _postContent; - } - - /// - /// Generates the 's end tag. - /// - /// string.Empty if is null or whitespace. Otherwise, the - /// representation of the 's end tag. - public string GenerateEndTag() - { - if (SelfClosing || _isTagNameNullOrWhitespace) - { - return string.Empty; - } - - return string.Format(CultureInfo.InvariantCulture, "", TagName); - } - /// /// Changes to generate nothing. /// diff --git a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperRunner.cs b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperRunner.cs index d8659e99e0..0c264696b3 100644 --- a/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperRunner.cs +++ b/src/Microsoft.AspNet.Razor.Runtime/TagHelpers/TagHelperRunner.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Framework.Internal; -using Microsoft.Framework.WebEncoders; namespace Microsoft.AspNet.Razor.Runtime.TagHelpers { @@ -13,17 +12,6 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers /// public class TagHelperRunner { - private readonly IHtmlEncoder _htmlEncoder; - - /// - /// Instantiates a new instance of . - /// - /// The used to encode HTML. - public TagHelperRunner([NotNull] IHtmlEncoder htmlEncoder) - { - _htmlEncoder = htmlEncoder; - } - /// /// Calls the method on s. /// @@ -40,8 +28,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers executionContext.GetChildContentAsync); var tagHelperOutput = new TagHelperOutput( executionContext.TagName, - executionContext.HTMLAttributes, - _htmlEncoder) + executionContext.HTMLAttributes) { SelfClosing = executionContext.SelfClosing, }; diff --git a/src/Microsoft.AspNet.Razor.Runtime/project.json b/src/Microsoft.AspNet.Razor.Runtime/project.json index 93ed896b4e..922a55f010 100644 --- a/src/Microsoft.AspNet.Razor.Runtime/project.json +++ b/src/Microsoft.AspNet.Razor.Runtime/project.json @@ -5,8 +5,7 @@ "Microsoft.AspNet.Razor": "4.0.0-*", "Microsoft.Framework.BufferEntryCollection.Internal": { "type": "build", "version": "1.0.0-*" }, "Microsoft.Framework.CopyOnWriteDictionary.Internal": { "type": "build", "version": "1.0.0-*" }, - "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, - "Microsoft.Framework.WebEncoders.Core": "1.0.0-*" + "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, "frameworks": { "net45": { }, diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs index 45b8f4efd4..4af3f2bd0c 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs @@ -75,15 +75,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp if (!_designTimeMode) { RenderRunTagHelpers(); - - RenderTagOutput(_tagHelperContext.OutputGenerateStartTagMethodName, methodReturnsString: true); - RenderTagOutput(_tagHelperContext.OutputGeneratePreContentMethodName, methodReturnsString: false); - - RenderTagHelperContent(); - - RenderTagOutput(_tagHelperContext.OutputGeneratePostContentMethodName, methodReturnsString: false); - RenderTagOutput(_tagHelperContext.OutputGenerateEndTagMethodName, methodReturnsString: true); - + RenderWriteTagHelperMethodCall(); RenderEndTagHelpersScope(); } } @@ -360,71 +352,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp } } - private void RenderTagHelperContent() - { - _writer.Write("if (") - .Write(ExecutionContextVariableName) - .Write(".") - .Write(_tagHelperContext.ExecutionContextOutputPropertyName) - .Write(".") - .Write(_tagHelperContext.OutputIsContentModifiedPropertyName) - .WriteLine(")"); - - // At this point in the codegen, TagHelperOutput.Content is set. We need to use this to render the Content - // instead of executing the child content - using (_writer.BuildScope()) - { - RenderTagOutput(_tagHelperContext.OutputGenerateContentMethodName, methodReturnsString: false); - } - - _writer.Write("else if (") - .Write(ExecutionContextVariableName) - .Write(".") - .Write(_tagHelperContext.ExecutionContextChildContentRetrievedPropertyName) - .WriteLine(")"); - - // Render the body of the else if statement, at this point in the codegen the GetChildContentAsync method - // was invoked but the TagHelperOutput's Content was not set. Call into GetChildContentAsync to retrieve - // the cached value of the content so we don't execute the child content twice. - using (_writer.BuildScope()) - { - RenderStartWriteMethod(); - - _writer.WriteInstanceMethodInvocation(ExecutionContextVariableName, - _tagHelperContext.ExecutionContextGetChildContentAsyncMethodName, - endLine: false); - - _writer.Write(".Result") - .WriteEndMethodInvocation(); - } - - _writer.WriteLine("else"); - - // Render the body of the else statement, at this point in the codegen the GetChildContentAsync method - // was not invoked and the TagHelperOutput's Content was not set. Call into ExecuteChildContentAsync to - // to execute and render child content. - using (_writer.BuildScope()) - { - if (!string.IsNullOrEmpty(_context.TargetWriterName)) - { - _writer.WriteMethodInvocation( - _tagHelperContext.StartTagHelperWritingScopeMethodName, - _context.TargetWriterName); - } - - _writer.WriteInstanceMethodInvocation( - ExecutionContextVariableName, - _tagHelperContext.ExecutionContextExecuteChildContentAsyncMethodName, - endLine: false); - _writer.WriteLine(".Wait();"); - - if (!string.IsNullOrEmpty(_context.TargetWriterName)) - { - _writer.WriteMethodInvocation(_tagHelperContext.EndTagHelperWritingScopeMethodName); - } - } - } - private void RenderEndTagHelpersScope() { _writer.WriteStartAssignment(ExecutionContextVariableName) @@ -432,38 +359,24 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp _tagHelperContext.ScopeManagerEndMethodName); } - private void RenderTagOutput(string tagOutputMethodName, bool methodReturnsString) - { - // If its a string WriteLiteral must be generated. - if (methodReturnsString) - { - CSharpCodeVisitor.RenderPreWriteStart(_writer, _context); - } - else - { - RenderStartWriteMethod(); - } - - _writer.Write(ExecutionContextVariableName) - .Write(".") - .Write(_tagHelperContext.ExecutionContextOutputPropertyName) - .Write(".") - .WriteMethodInvocation(tagOutputMethodName, endLine: false) - .WriteEndMethodInvocation(); - } - private void RenderStartWriteMethod() + private void RenderWriteTagHelperMethodCall() { if (!string.IsNullOrEmpty(_context.TargetWriterName)) { _writer - .WriteStartMethodInvocation(_context.Host.GeneratedClassContext.WriteToMethodName) + .WriteStartMethodInvocation(_tagHelperContext.WriteTagHelperToAsyncMethodName) .Write(_context.TargetWriterName) .WriteParameterSeparator(); } else { - _writer.WriteStartMethodInvocation(_context.Host.GeneratedClassContext.WriteMethodName); + _writer.WriteStartMethodInvocation(_tagHelperContext.WriteTagHelperAsyncMethodName); } + + _writer + .Write(ExecutionContextVariableName) + .WriteEndMethodInvocation(endLine: false) + .WriteLine(".Wait();"); } private void RenderRunTagHelpers() diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperRunnerInitializationVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperRunnerInitializationVisitor.cs index e5752edead..1d4772567e 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperRunnerInitializationVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperRunnerInitializationVisitor.cs @@ -38,7 +38,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp .Write(CSharpTagHelperCodeRenderer.RunnerVariableName) .Write(" ?? ") .WriteStartNewObject(_tagHelperContext.RunnerTypeName) - .Write(_tagHelperContext.HtmlEncoderPropertyName) .WriteEndMethodInvocation(); } } diff --git a/src/Microsoft.AspNet.Razor/Generator/GeneratedTagHelperContext.cs b/src/Microsoft.AspNet.Razor/Generator/GeneratedTagHelperContext.cs index 76a66a648d..4fa07f307c 100644 --- a/src/Microsoft.AspNet.Razor/Generator/GeneratedTagHelperContext.cs +++ b/src/Microsoft.AspNet.Razor/Generator/GeneratedTagHelperContext.cs @@ -17,15 +17,6 @@ namespace Microsoft.AspNet.Razor.Generator RunnerRunAsyncMethodName = "RunAsync"; ScopeManagerBeginMethodName = "Begin"; ScopeManagerEndMethodName = "End"; - OutputIsContentModifiedPropertyName = "IsContentModified"; - OutputGenerateStartTagMethodName = "GenerateStartTag"; - OutputGeneratePreContentMethodName = "GeneratePreContent"; - OutputGenerateContentMethodName = "GenerateContent"; - OutputGeneratePostContentMethodName = "GeneratePostContent"; - OutputGenerateEndTagMethodName = "GenerateEndTag"; - ExecutionContextChildContentRetrievedPropertyName = "ChildContentRetrieved"; - ExecutionContextExecuteChildContentAsyncMethodName = "ExecuteChildContentAsync"; - ExecutionContextGetChildContentAsyncMethodName = "GetChildContentAsync"; ExecutionContextAddMethodName = "Add"; ExecutionContextAddTagHelperAttributeMethodName = "AddTagHelperAttribute"; ExecutionContextAddHtmlAttributeMethodName = "AddHtmlAttribute"; @@ -35,8 +26,9 @@ namespace Microsoft.AspNet.Razor.Generator RunnerTypeName = "TagHelperRunner"; ScopeManagerTypeName = "TagHelperScopeManager"; ExecutionContextTypeName = "TagHelperExecutionContext"; - HtmlEncoderPropertyName = "HtmlEncoder"; TagHelperContentTypeName = "TagHelperContent"; + WriteTagHelperAsyncMethodName = "WriteTagHelperAsync"; + WriteTagHelperToAsyncMethodName = "WriteTagHelperToAsync"; } /// @@ -59,52 +51,6 @@ namespace Microsoft.AspNet.Razor.Generator /// public string ScopeManagerEndMethodName { get; set; } - /// - /// The name of the property used to determine if a tag helper output's content was set. - /// - public string OutputIsContentModifiedPropertyName { get; set; } - - /// - /// The name of the method used to generate a tag helper output's start tag. - /// - public string OutputGenerateStartTagMethodName { get; set; } - - /// - /// The name of the method used to generate a tag helper output's pre content. - /// - public string OutputGeneratePreContentMethodName { get; set; } - - /// - /// The name of the method used to generate a tag helper output's content. - /// - public string OutputGenerateContentMethodName { get; set; } - - /// - /// The name of the method used to generate a tag helper output's post-content. - /// - public string OutputGeneratePostContentMethodName { get; set; } - - /// - /// The name of the method used to generate a tag helper output's end tag. - /// - public string OutputGenerateEndTagMethodName { get; set; } - - /// - /// The name of the method used to get a - /// that executes tag helper child content. - /// - public string ExecutionContextChildContentRetrievedPropertyName { get; set; } - - /// - /// - public string ExecutionContextExecuteChildContentAsyncMethodName { get; set; } - - /// - /// The name of the method used to execute and retrieve tag helper - /// child content. - /// - public string ExecutionContextGetChildContentAsyncMethodName { get; set; } - /// /// The name of the method used to add tag helper attributes. /// @@ -153,11 +99,6 @@ namespace Microsoft.AspNet.Razor.Generator /// public string ExecutionContextTypeName { get; set; } - /// - /// The name of the property used to encode HTML. - /// - public string HtmlEncoderPropertyName { get; set; } - /// /// The name of the type containing tag helper content. /// @@ -165,5 +106,16 @@ namespace Microsoft.AspNet.Razor.Generator /// Contains the data returned by EndTagHelperWriteScope(). /// public string TagHelperContentTypeName { get; set; } + + /// + /// The name of the method used to write . + /// + public string WriteTagHelperAsyncMethodName { get; set; } + + /// + /// The name of the method used to write to a specified + /// . + /// + public string WriteTagHelperToAsyncMethodName { get; set; } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/DefaultTagHelperContentTest.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/DefaultTagHelperContentTest.cs index c28df3d595..0b0d09bc85 100644 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/DefaultTagHelperContentTest.cs +++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/DefaultTagHelperContentTest.cs @@ -4,9 +4,6 @@ using System; using System.IO; using System.Linq; -#if !DNXCORE50 -using Moq; -#endif using Xunit; namespace Microsoft.AspNet.Razor.Runtime.TagHelpers @@ -316,46 +313,6 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers Assert.True(tagHelperContent.IsEmpty); } - // CopyTo - [Fact] - public void CanWriteToTextWriter() - { - // Arrange - var writer = new StringWriter(); - var tagHelperContent = new DefaultTagHelperContent(); - var expected = "Hello World!"; - tagHelperContent.SetContent(expected); - - // Act - tagHelperContent.CopyTo(writer); - - // Assert - Assert.Equal(expected, writer.ToString()); - } - -#if !DNXCORE50 - [Fact] - public void CanWriteToTextWriter_MultipleAppends() - { - // Arrange - var writer = new Mock(); - writer.CallBase = true; - var tagHelperContent = new DefaultTagHelperContent(); - var text1 = "Hello"; - var text2 = " World!"; - var expected = text1 + text2; - tagHelperContent.Append(text1); - tagHelperContent.Append(text2); - - // Act - tagHelperContent.CopyTo(writer.Object); - - // Assert - Assert.Equal(expected, writer.Object.ToString()); - writer.Verify(w => w.Write(It.IsAny()), Times.Exactly(2)); - } -#endif - [Fact] public void ToString_ReturnsExpectedValue() { diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/NullHtmlEncoder.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/NullHtmlEncoder.cs deleted file mode 100644 index fd9acf7272..0000000000 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/NullHtmlEncoder.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using Microsoft.Framework.WebEncoders; - -namespace Microsoft.AspNet.Razor.Runtime.TagHelpers.Test -{ - public class NullHtmlEncoder : IHtmlEncoder - { - public string HtmlEncode(string value) - { - return value; - } - - public void HtmlEncode(string value, int startIndex, int charCount, TextWriter output) - { - output.Write(value.Substring(startIndex, charCount)); - } - - public void HtmlEncode(char[] value, int startIndex, int charCount, TextWriter output) - { - output.Write(value, startIndex, charCount); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/PseudoHtmlEncoder.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/PseudoHtmlEncoder.cs deleted file mode 100644 index b5221f79fd..0000000000 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/PseudoHtmlEncoder.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.IO; -using Microsoft.Framework.WebEncoders; - -namespace Microsoft.AspNet.Razor.Runtime.TagHelpers.Test -{ - public class PseudoHtmlEncoder : IHtmlEncoder - { - public string HtmlEncode(string value) - { - return "HtmlEncode[[" + value + "]]"; - } - - public void HtmlEncode(string value, int startIndex, int charCount, TextWriter output) - { - output.Write("HtmlEncode[["); - output.Write(value.Substring(startIndex, charCount)); - output.Write("]]"); - } - - public void HtmlEncode(char[] value, int startIndex, int charCount, TextWriter output) - { - output.Write("HtmlEncode[["); - output.Write(value, startIndex, charCount); - output.Write("]]"); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperOutputTest.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperOutputTest.cs index 12067006ee..8b329da271 100644 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperOutputTest.cs +++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperOutputTest.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNet.Razor.Runtime.TagHelpers.Test; using Xunit; namespace Microsoft.AspNet.Razor.Runtime.TagHelpers @@ -33,326 +32,45 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers } [Fact] - public void GenerateStartTag_ReturnsFullStartTag() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p", attributes: - new Dictionary - { - { "class", "btn" }, - { "something", " spaced " } - }, - htmlEncoder: new NullHtmlEncoder()); - - // Act - var output = tagHelperOutput.GenerateStartTag(); - - // Assert - Assert.Equal("

", output); - } - - [Fact] - public void GenerateStartTag_ReturnsNoAttributeStartTag() + public void PreContent_SetContent_ChangesValue() { // Arrange var tagHelperOutput = new TagHelperOutput("p"); + tagHelperOutput.PreContent.SetContent("Hello World"); - // Act - var output = tagHelperOutput.GenerateStartTag(); - - // Assert - Assert.Equal("

", output); + // Act & Assert + Assert.NotNull(tagHelperOutput.PreContent); + Assert.NotNull(tagHelperOutput.Content); + Assert.NotNull(tagHelperOutput.PostContent); + Assert.Equal("Hello World", tagHelperOutput.PreContent.GetContent()); } [Fact] - public void GenerateStartTag_ReturnsSelfClosingStartTag_Attributes() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p", - attributes: new Dictionary - { - { "class", "btn" }, - { "something", " spaced " } - }, - htmlEncoder: new NullHtmlEncoder()); - - tagHelperOutput.SelfClosing = true; - - // Act - var output = tagHelperOutput.GenerateStartTag(); - - // Assert - Assert.Equal("

", output); - } - - [Fact] - public void GenerateStartTag_ReturnsSelfClosingStartTag_NoAttributes() + public void Content_SetContent_ChangesValue() { // Arrange var tagHelperOutput = new TagHelperOutput("p"); + tagHelperOutput.Content.SetContent("Hello World"); - tagHelperOutput.SelfClosing = true; - - // Act - var output = tagHelperOutput.GenerateStartTag(); - - // Assert - Assert.Equal("

", output); + // Act & Assert + Assert.NotNull(tagHelperOutput.PreContent); + Assert.NotNull(tagHelperOutput.Content); + Assert.NotNull(tagHelperOutput.PostContent); + Assert.Equal("Hello World", tagHelperOutput.Content.GetContent()); } [Fact] - public void GenerateStartTag_UsesProvidedHtmlEncoder() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p", - attributes: new Dictionary - { - { "hello", "world" }, - }, - htmlEncoder: new PseudoHtmlEncoder()); - - tagHelperOutput.SelfClosing = true; - - // Act - var output = tagHelperOutput.GenerateStartTag(); - - // Assert - Assert.Equal("

", output); - } - - [Fact] - public void GenerateStartTag_ReturnsNothingIfWhitespaceTagName() - { - // Arrange - var tagHelperOutput = new TagHelperOutput(" ", - attributes: new Dictionary - { - { "class", "btn" }, - { "something", " spaced " } - }, - htmlEncoder: new NullHtmlEncoder()) - { - SelfClosing = true - }; - - // Act - var output = tagHelperOutput.GenerateStartTag(); - - // Assert - Assert.Empty(output); - } - - - [Fact] - public void GenerateEndTag_ReturnsNothingIfWhitespaceTagName() - { - // Arrange - var tagHelperOutput = new TagHelperOutput(" "); - tagHelperOutput.Content.Append("Hello World"); - - // Act - var output = tagHelperOutput.GenerateEndTag(); - - // Assert - Assert.Empty(output); - } - - [Fact] - public void GeneratePreContent_ReturnsPreContent() + public void PostContent_SetContent_ChangesValue() { // Arrange var tagHelperOutput = new TagHelperOutput("p"); - tagHelperOutput.PreContent.Append("Hello World"); + tagHelperOutput.PostContent.SetContent("Hello World"); - // Act - var output = tagHelperOutput.GeneratePreContent(); - - // Assert - var result = Assert.IsType(output); - Assert.Equal("Hello World", result.GetContent()); - } - - [Fact] - public void GeneratePreContent_ReturnsNothingIfSelfClosingWhenTagNameIsNotNullOrWhitespace() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p") - { - SelfClosing = true - }; - tagHelperOutput.PreContent.Append("Hello World"); - - // Act - var output = tagHelperOutput.GeneratePreContent(); - - // Assert - Assert.Null(output); - } - - [Theory] - [InlineData(null, true)] - [InlineData("\t", true )] - [InlineData(null, false)] - [InlineData("\t", false)] - public void GeneratePreContent_ReturnsPreContentIfTagNameIsNullOrWhitespace(string tagName, bool selfClosing) - { - // Arrange - var expectedContent = "Hello World"; - - var tagHelperOutput = new TagHelperOutput(tagName) - { - SelfClosing = selfClosing - }; - tagHelperOutput.PreContent.Append(expectedContent); - - // Act - var output = tagHelperOutput.GeneratePreContent(); - - // Assert - var result = Assert.IsType(output); - Assert.Equal(expectedContent, result.GetContent()); - } - - [Fact] - public void GenerateContent_ReturnsContent() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p"); - tagHelperOutput.Content.Append("Hello World"); - - // Act - var output = tagHelperOutput.GenerateContent(); - - // Assert - var result = Assert.IsType(output); - Assert.Equal("Hello World", result.GetContent()); - } - - - [Fact] - public void GenerateContent_ReturnsNothingIfSelfClosingWhenTagNameIsNotNullOrWhitespace() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p") - { - SelfClosing = true - }; - tagHelperOutput.Content.Append("Hello World"); - - // Act - var output = tagHelperOutput.GenerateContent(); - - // Assert - Assert.Null(output); - } - - [Theory] - [InlineData(null, true)] - [InlineData("\t", true )] - [InlineData(null, false)] - [InlineData("\t", false)] - public void GenerateContent_ReturnsContentIfTagNameIsNullOrWhitespace(string tagName, bool selfClosing) - { - // Arrange - var expectedContent = "Hello World"; - - var tagHelperOutput = new TagHelperOutput(tagName) - { - SelfClosing = selfClosing - }; - tagHelperOutput.Content.Append(expectedContent); - - // Act - var output = tagHelperOutput.GenerateContent(); - - // Assert - var result = Assert.IsType(output); - Assert.Equal(expectedContent, result.GetContent()); - } - - [Fact] - public void GeneratePostContent_ReturnsPostContent() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p"); - tagHelperOutput.PostContent.Append("Hello World"); - - // Act - var output = tagHelperOutput.GeneratePostContent(); - - // Assert - var result = Assert.IsType(output); - Assert.Equal("Hello World", result.GetContent()); - } - - [Fact] - public void GeneratePostContent_ReturnsNothingIfSelfClosingWhenTagNameIsNotNullOrWhitespace() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p") - { - SelfClosing = true - }; - tagHelperOutput.PostContent.Append("Hello World"); - - // Act - var output = tagHelperOutput.GeneratePostContent(); - - // Assert - Assert.Null(output); - } - - [Fact] - public void GenerateEndTag_ReturnsEndTag() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p"); - - // Act - var output = tagHelperOutput.GenerateEndTag(); - - // Assert - Assert.Equal("

", output); - } - - [Theory] - [InlineData(null, true)] - [InlineData("\t", true )] - [InlineData(null, false)] - [InlineData("\t", false)] - public void GeneratePostContent_ReturnsPostContentIfTagNameIsNullOrWhitespace(string tagName, bool selfClosing) - { - // Arrange - var expectedContent = "Hello World"; - - var tagHelperOutput = new TagHelperOutput(tagName) - { - SelfClosing = selfClosing - }; - tagHelperOutput.PostContent.Append(expectedContent); - - // Act - var output = tagHelperOutput.GeneratePostContent(); - - // Assert - var result = Assert.IsType(output); - Assert.Equal(expectedContent, result.GetContent()); - } - - [Fact] - public void GenerateEndTag_ReturnsNothingIfSelfClosing() - { - // Arrange - var tagHelperOutput = new TagHelperOutput("p") - { - SelfClosing = true - }; - - // Act - var output = tagHelperOutput.GenerateEndTag(); - - // Assert - Assert.Empty(output); + // Act & Assert + Assert.NotNull(tagHelperOutput.PreContent); + Assert.NotNull(tagHelperOutput.Content); + Assert.NotNull(tagHelperOutput.PostContent); + Assert.Equal("Hello World", tagHelperOutput.PostContent.GetContent()); } [Fact] @@ -369,12 +87,12 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers // Assert Assert.Null(tagHelperOutput.TagName); - var result = Assert.IsType(tagHelperOutput.PreContent); - Assert.Empty(result.GetContent()); - result = Assert.IsType(tagHelperOutput.Content); - Assert.Empty(result.GetContent()); - result = Assert.IsType(tagHelperOutput.PostContent); - Assert.Empty(result.GetContent()); + Assert.NotNull(tagHelperOutput.PreContent); + Assert.Empty(tagHelperOutput.PreContent.GetContent()); + Assert.NotNull(tagHelperOutput.Content); + Assert.Empty(tagHelperOutput.Content.GetContent()); + Assert.NotNull(tagHelperOutput.PostContent); + Assert.Empty(tagHelperOutput.PostContent.GetContent()); } [Fact] @@ -386,8 +104,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers { { "class", "btn" }, { "something", " spaced " } - }, - htmlEncoder: new NullHtmlEncoder()); + }); tagHelperOutput.PreContent.Append("Pre Content"); tagHelperOutput.Content.Append("Content"); tagHelperOutput.PostContent.Append("Post Content"); @@ -396,14 +113,12 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers tagHelperOutput.SuppressOutput(); // Assert - Assert.Empty(tagHelperOutput.GenerateStartTag()); - var result = Assert.IsType(tagHelperOutput.GeneratePreContent()); - Assert.Empty(result.GetContent()); - result = Assert.IsType(tagHelperOutput.GenerateContent()); - Assert.Empty(result.GetContent()); - result = Assert.IsType(tagHelperOutput.GeneratePostContent()); - Assert.Empty(result.GetContent()); - Assert.Empty(tagHelperOutput.GenerateEndTag()); + Assert.NotNull(tagHelperOutput.PreContent); + Assert.Empty(tagHelperOutput.PreContent.GetContent()); + Assert.NotNull(tagHelperOutput.Content); + Assert.Empty(tagHelperOutput.Content.GetContent()); + Assert.NotNull(tagHelperOutput.PostContent); + Assert.Empty(tagHelperOutput.PostContent.GetContent()); } [Theory] @@ -417,8 +132,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers attributes: new Dictionary { { originalName, "btn" }, - }, - htmlEncoder: new NullHtmlEncoder()); + }); // Act tagHelperOutput.Attributes[updateName] = "super button"; diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperRunnerTest.cs b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperRunnerTest.cs index 6bb8296178..499452d490 100644 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperRunnerTest.cs +++ b/test/Microsoft.AspNet.Razor.Runtime.Test/TagHelpers/TagHelperRunnerTest.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; -using Microsoft.AspNet.Razor.Runtime.TagHelpers.Test; using Xunit; namespace Microsoft.AspNet.Razor.Runtime.TagHelpers @@ -62,7 +61,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers int[] expectedTagHelperOrders) { // Arrange - var runner = new TagHelperRunner(new NullHtmlEncoder()); + var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var processOrder = new List(); @@ -88,7 +87,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers public async Task RunAsync_SetTagHelperOutputSelfClosing(bool selfClosing) { // Arrange - var runner = new TagHelperRunner(new NullHtmlEncoder()); + var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing); var tagHelper = new TagHelperContextTouchingTagHelper(); @@ -106,7 +105,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers public async Task RunAsync_ProcessesAllTagHelpers() { // Arrange - var runner = new TagHelperRunner(new NullHtmlEncoder()); + var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var executableTagHelper1 = new ExecutableTagHelper(); var executableTagHelper2 = new ExecutableTagHelper(); @@ -125,7 +124,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers public async Task RunAsync_AllowsModificationOfTagHelperOutput() { // Arrange - var runner = new TagHelperRunner(new NullHtmlEncoder()); + var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var executableTagHelper = new ExecutableTagHelper(); @@ -145,7 +144,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers public async Task RunAsync_AllowsDataRetrievalFromTagHelperContext() { // Arrange - var runner = new TagHelperRunner(new NullHtmlEncoder()); + var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var tagHelper = new TagHelperContextTouchingTagHelper(); @@ -162,7 +161,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers public async Task RunAsync_ConfiguresTagHelperContextWithExecutionContextsItems() { // Arrange - var runner = new TagHelperRunner(new NullHtmlEncoder()); + var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var tagHelper = new ContextInspectingTagHelper(); executionContext.Add(tagHelper); @@ -175,22 +174,6 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers Assert.Same(tagHelper.ContextProcessedWith.Items, executionContext.Items); } - [Fact] - public async Task RunAsync_CreatesTagHelperOutput_WithProvidedEncoder() - { - // Arrange - var runner = new TagHelperRunner(new PseudoHtmlEncoder()); - var executionContext = new TagHelperExecutionContext("p", selfClosing: true); - executionContext.AddHtmlAttribute("Hello", "World"); - - // Act - var tagHelperOutput = await runner.RunAsync(executionContext); - var output = tagHelperOutput.GenerateStartTag(); - - // Assert - Assert.Equal("

", output); - } - private class ExecutableTagHelper : TagHelper { public bool Processed { get; set; } diff --git a/test/Microsoft.AspNet.Razor.Runtime.Test/project.json b/test/Microsoft.AspNet.Razor.Runtime.Test/project.json index 9ddaed1335..1e7e17a924 100644 --- a/test/Microsoft.AspNet.Razor.Runtime.Test/project.json +++ b/test/Microsoft.AspNet.Razor.Runtime.Test/project.json @@ -9,11 +9,7 @@ "test": "xunit.runner.aspnet" }, "frameworks": { - "dnx451": { - "dependencies": { - "Moq": "4.2.1312.1622" - } - }, + "dnx451": { }, "dnxcore50": { "dependencies": { "System.Reflection.TypeExtensions": "4.0.0-beta-*", diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.CustomAttributeCodeGenerator.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.CustomAttributeCodeGenerator.cs index 4186815163..41d1f138c8 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.CustomAttributeCodeGenerator.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.CustomAttributeCodeGenerator.cs @@ -24,7 +24,7 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(HtmlEncoder); + __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 49, true); WriteLiteral("\r\n

\r\n "); Instrumentation.EndContext(); @@ -36,22 +36,7 @@ namespace TestOutput __PTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { @@ -65,22 +50,7 @@ namespace TestOutput __tagHelperExecutionContext.Add(__InputTagHelper2); __InputTagHelper2.Type = __InputTagHelper.Type; __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { @@ -100,22 +70,7 @@ namespace TestOutput #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -124,22 +79,7 @@ namespace TestOutput __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.AddHtmlAttribute("class", "Hello World"); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(212, 8, true); WriteLiteral("\r\n
"); diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.Prefixed.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.Prefixed.cs index 71b1a04cbc..402e864d64 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.Prefixed.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.Prefixed.cs @@ -25,7 +25,7 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(HtmlEncoder); + __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(57, 52, true); WriteLiteral("\r\n\r\n "); Instrumentation.EndContext(); @@ -48,22 +48,7 @@ namespace TestOutput #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -72,22 +57,7 @@ namespace TestOutput __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.AddHtmlAttribute("class", "Hello World"); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(249, 11, true); WriteLiteral("\r\n"); diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.cs index a4dfe83901..18527be872 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/BasicTagHelpers.cs @@ -25,7 +25,7 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(HtmlEncoder); + __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 49, true); WriteLiteral("\r\n
\r\n "); Instrumentation.EndContext(); @@ -37,22 +37,7 @@ namespace TestOutput __PTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { @@ -66,22 +51,7 @@ namespace TestOutput __tagHelperExecutionContext.Add(__InputTagHelper2); __InputTagHelper2.Type = __InputTagHelper.Type; __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { @@ -101,22 +71,7 @@ namespace TestOutput #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -125,22 +80,7 @@ namespace TestOutput __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.AddHtmlAttribute("class", "Hello World"); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(212, 8, true); WriteLiteral("\r\n
"); diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ComplexTagHelpers.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ComplexTagHelpers.cs index b191f07523..ad6f6f7ce4 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ComplexTagHelpers.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ComplexTagHelpers.cs @@ -25,7 +25,7 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(HtmlEncoder); + __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); @@ -72,44 +72,14 @@ namespace TestOutput __tagHelperExecutionContext.AddHtmlAttribute("value", ""); __tagHelperExecutionContext.AddHtmlAttribute("placeholder", "Enter in a new time..."); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n"); #line 13 "ComplexTagHelpers.cshtml" @@ -147,44 +117,14 @@ Write(checkbox); #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { @@ -205,22 +145,7 @@ Write(true ? "checkbox" : "anything"); __tagHelperExecutionContext.Add(__InputTagHelper2); __InputTagHelper2.Type = __InputTagHelper.Type; __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { @@ -256,22 +181,7 @@ if(true) { __tagHelperExecutionContext.Add(__InputTagHelper2); __InputTagHelper2.Type = __InputTagHelper.Type; __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n"); #line 19 "ComplexTagHelpers.cshtml" @@ -295,22 +205,7 @@ Write(DateTime.Now); __tagHelperStringValueBuffer = EndTagHelperWritingScope(); __tagHelperExecutionContext.AddHtmlAttribute("time", __tagHelperStringValueBuffer.ToString()); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(672, 10, true); WriteLiteral("\r\n "); @@ -344,22 +239,7 @@ __InputTagHelper2.Checked = @object; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -373,22 +253,7 @@ __PTagHelper.Age = DateTimeOffset.Now.Year - 1970; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(819, 10, true); WriteLiteral("\r\n "); @@ -409,22 +274,7 @@ __InputTagHelper2.Checked = DateTimeOffset.Now.Year > 2014; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -438,22 +288,7 @@ __PTagHelper.Age = -1970 + DateTimeOffset.Now.Year; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(952, 10, true); WriteLiteral("\r\n "); @@ -474,22 +309,7 @@ __InputTagHelper2.Checked = DateTimeOffset.Now.Year > 2014; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -503,22 +323,7 @@ __PTagHelper.Age = DateTimeOffset.Now.Year - 1970; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(1080, 10, true); WriteLiteral("\r\n "); @@ -539,22 +344,7 @@ __InputTagHelper2.Checked = DateTimeOffset.Now.Year > 2014 ; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -568,22 +358,7 @@ __PTagHelper.Age = "My age is this long.".Length; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(1223, 14, true); WriteLiteral("\r\n \r\n"); diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/EmptyAttributeTagHelpers.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/EmptyAttributeTagHelpers.cs index ff01872b87..b1036b8f6b 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/EmptyAttributeTagHelpers.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/EmptyAttributeTagHelpers.cs @@ -25,7 +25,7 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(HtmlEncoder); + __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(27, 13, true); WriteLiteral("\r\n
\r\n "); Instrumentation.EndContext(); @@ -47,22 +47,7 @@ __InputTagHelper2.Checked = ; __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.AddHtmlAttribute("class", ""); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(74, 6, true); WriteLiteral("\r\n "); @@ -87,22 +72,7 @@ __InputTagHelper2.Checked = ; __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.AddHtmlAttribute("class", ""); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -116,22 +86,7 @@ __PTagHelper.Age = ; #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(144, 8, true); WriteLiteral("\r\n
"); diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/EscapedTagHelpers.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/EscapedTagHelpers.cs index da8ec326db..033450f381 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/EscapedTagHelpers.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/EscapedTagHelpers.cs @@ -24,7 +24,7 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(HtmlEncoder); + __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(27, 72, true); WriteLiteral("\r\n
\r\n
"); diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/SingleTagHelper.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/SingleTagHelper.cs index 5da65e0fec..f17063a6aa 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/SingleTagHelper.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/SingleTagHelper.cs @@ -23,7 +23,7 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(HtmlEncoder); + __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); @@ -41,22 +41,7 @@ namespace TestOutput __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.AddHtmlAttribute("class", "Hello World"); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); } #pragma warning restore 1998 diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/TagHelpersInHelper.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/TagHelpersInHelper.cs index 7a9682d40f..2cb75d6991 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/TagHelpersInHelper.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/TagHelpersInHelper.cs @@ -38,22 +38,7 @@ MyHelper(string val) __NestedTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__NestedTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -80,24 +65,7 @@ Write(DateTime.Now); __tagHelperStringValueBuffer = EndTagHelperWritingScope(); __tagHelperExecutionContext.AddHtmlAttribute("unboundproperty", __tagHelperStringValueBuffer.ToString()); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteralTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GenerateStartTag()); - WriteTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - WriteTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - WriteTo(__razor_helper_writer, __tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - StartTagHelperWritingScope(__razor_helper_writer); - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - EndTagHelperWritingScope(); - } - WriteTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteralTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperToAsync(__razor_helper_writer, __tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(342, 14, true); WriteLiteralTo(__razor_helper_writer, "\r\n \r\n"); @@ -132,7 +100,7 @@ Write(DateTime.Now); #pragma warning disable 1998 public override async Task ExecuteAsync() { - __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(HtmlEncoder); + __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); @@ -146,24 +114,7 @@ Write(MyHelper(item => new Template((__razor_template_writer) => { __NestedTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__NestedTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteralTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateStartTag()); - WriteTo(__razor_template_writer, __tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - WriteTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - WriteTo(__razor_template_writer, __tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - StartTagHelperWritingScope(__razor_template_writer); - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - EndTagHelperWritingScope(); - } - WriteTo(__razor_template_writer, __tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteralTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperToAsync(__razor_template_writer, __tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); } ) @@ -176,22 +127,7 @@ Write(MyHelper(item => new Template((__razor_template_writer) => { __MyTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__MyTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(445, 2, true); WriteLiteral("\r\n"); diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/TagHelpersInSection.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/TagHelpersInSection.cs index 31387a6e04..4ed70ec2c7 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/TagHelpersInSection.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/TagHelpersInSection.cs @@ -54,22 +54,7 @@ namespace TestOutput __NestedTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__NestedTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Write(__tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - Write(__tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - Write(__tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - } - Write(__tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperAsync(__tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); } @@ -96,24 +81,7 @@ Write(DateTime.Now); __tagHelperStringValueBuffer = EndTagHelperWritingScope(); __tagHelperExecutionContext.AddHtmlAttribute("unboundproperty", __tagHelperStringValueBuffer.ToString()); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; - WriteLiteralTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateStartTag()); - WriteTo(__razor_template_writer, __tagHelperExecutionContext.Output.GeneratePreContent()); - if (__tagHelperExecutionContext.Output.IsContentModified) - { - WriteTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateContent()); - } - else if (__tagHelperExecutionContext.ChildContentRetrieved) - { - WriteTo(__razor_template_writer, __tagHelperExecutionContext.GetChildContentAsync().Result); - } - else - { - StartTagHelperWritingScope(__razor_template_writer); - __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); - EndTagHelperWritingScope(); - } - WriteTo(__razor_template_writer, __tagHelperExecutionContext.Output.GeneratePostContent()); - WriteLiteralTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateEndTag()); + WriteTagHelperToAsync(__razor_template_writer, __tagHelperExecutionContext).Wait(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(359, 14, true); WriteLiteralTo(__razor_template_writer, "\r\n \r\n");