From 7db4ed7f7e7bdc58ffe9647028168f6027155cb9 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 16 Sep 2014 23:00:26 -0700 Subject: [PATCH] Add tests to validate @addtaghelper directive. - Fixed existing tests to work with new RazorParser. - Validated directive syntax tree creation, errors and code generation. #111 --- .../Framework/TestSpanBuilder.cs | 5 + .../Generator/CSharpRazorCodeGeneratorTest.cs | 35 +++++- .../Generator/CSharpTagHelperRenderingTest.cs | 111 +++++++++++------- .../CodeTree/CSharpPaddingBuilderTests.cs | 5 +- ...TagHelperAttributeValueCodeRendererTest.cs | 37 +++--- .../Generator/TagHelperTestBase.cs | 52 +++++--- .../Parser/CSharp/CSharpDirectivesTest.cs | 87 ++++++++++++++ .../Parser/RazorParserTest.cs | 23 ++-- .../CS/Output/AddTagHelperDirective.cs | 33 ++++++ ...TagHelpers.CustomAttributeCodeGenerator.cs | 16 +-- .../CS/Output/BasicTagHelpers.cs | 16 +-- .../CS/Output/ComplexTagHelpers.cs | 53 +++++---- .../CS/Output/ContentBehaviorTagHelpers.cs | 5 +- .../CS/Output/SingleTagHelper.cs | 7 +- .../CS/Output/TagHelpersInHelper.cs | 33 +++--- .../CS/Output/TagHelpersInSection.cs | 23 ++-- .../CS/Source/AddTagHelperDirective.cshtml | 1 + .../CS/Source/BasicTagHelpers.cshtml | 4 +- .../CS/Source/ComplexTagHelpers.cshtml | 4 +- .../Source/ContentBehaviorTagHelpers.cshtml | 4 +- .../CS/Source/SingleTagHelper.cshtml | 4 +- .../CS/Source/TagHelpersInHelper.cshtml | 4 +- .../CS/Source/TagHelpersInSection.cshtml | 4 +- 23 files changed, 390 insertions(+), 176 deletions(-) create mode 100644 test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/AddTagHelperDirective.cs create mode 100644 test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/AddTagHelperDirective.cshtml diff --git a/test/Microsoft.AspNet.Razor.Test/Framework/TestSpanBuilder.cs b/test/Microsoft.AspNet.Razor.Test/Framework/TestSpanBuilder.cs index 62d2be11f0..8574c48b20 100644 --- a/test/Microsoft.AspNet.Razor.Test/Framework/TestSpanBuilder.cs +++ b/test/Microsoft.AspNet.Razor.Test/Framework/TestSpanBuilder.cs @@ -300,6 +300,11 @@ namespace Microsoft.AspNet.Razor.Test.Framework return _self.With(new RazorDirectiveAttributeCodeGenerator(key, value)); } + public SpanConstructor AsAddTagHelper(string lookupText) + { + return _self.With(new AddTagHelperCodeGenerator(lookupText)); + } + public SpanConstructor As(ISpanCodeGenerator codeGenerator) { return _self.With(codeGenerator); diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs index 67924d4e23..501e9e9c98 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs @@ -492,16 +492,41 @@ namespace Microsoft.AspNet.Razor.Test.Generator }); } - private static LineMapping BuildLineMapping(int documentAbsoluteIndex, int documentLineIndex, int generatedAbsoluteIndex, int generatedLineIndex, int characterOffsetIndex, int contentLength) + protected static LineMapping BuildLineMapping(int documentAbsoluteIndex, + int documentLineIndex, + int generatedAbsoluteIndex, + int generatedLineIndex, + int characterOffsetIndex, + int contentLength) { - return BuildLineMapping(documentAbsoluteIndex, documentLineIndex, characterOffsetIndex, generatedAbsoluteIndex, generatedLineIndex, characterOffsetIndex, contentLength); + return BuildLineMapping(documentAbsoluteIndex, + documentLineIndex, + characterOffsetIndex, + generatedAbsoluteIndex, + generatedLineIndex, + characterOffsetIndex, + contentLength); } - private static LineMapping BuildLineMapping(int documentAbsoluteIndex, int documentLineIndex, int documentCharacterOffsetIndex, int generatedAbsoluteIndex, int generatedLineIndex, int generatedCharacterOffsetIndex, int contentLength) + protected static LineMapping BuildLineMapping(int documentAbsoluteIndex, + int documentLineIndex, + int documentCharacterOffsetIndex, + int generatedAbsoluteIndex, + int generatedLineIndex, + int generatedCharacterOffsetIndex, + int contentLength) { return new LineMapping( - documentLocation: new MappingLocation(new SourceLocation(documentAbsoluteIndex, documentLineIndex, documentCharacterOffsetIndex), contentLength), - generatedLocation: new MappingLocation(new SourceLocation(generatedAbsoluteIndex, generatedLineIndex, generatedCharacterOffsetIndex), contentLength) + documentLocation: new MappingLocation( + new SourceLocation(documentAbsoluteIndex, + documentLineIndex, + documentCharacterOffsetIndex), + contentLength), + generatedLocation: new MappingLocation( + new SourceLocation(generatedAbsoluteIndex, + generatedLineIndex, + generatedCharacterOffsetIndex), + contentLength) ); } } diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpTagHelperRenderingTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpTagHelperRenderingTest.cs index c0a9efe8ed..9aff6822f0 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpTagHelperRenderingTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpTagHelperRenderingTest.cs @@ -1,7 +1,9 @@ // 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.Collections.Generic; using System.Reflection; +using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.TagHelpers; using Moq; using Xunit; @@ -10,6 +12,34 @@ namespace Microsoft.AspNet.Razor.Test.Generator { public class CSharpTagHelperRenderingTest : TagHelperTestBase { + [Fact] + public void CSharpCodeGenerator_CorrectlyGeneratesMappings_ForAddTagHelperDirective() + { + // Act & Assert + RunTagHelperTest("AddTagHelperDirective", + designTimeMode: true, + expectedDesignTimePragmas: new List() + { + BuildLineMapping(documentAbsoluteIndex: 14, + documentLineIndex: 0, + generatedAbsoluteIndex: 433, + generatedLineIndex: 14, + characterOffsetIndex: 14, + contentLength: 11) + }); + } + + [Fact] + public void TagHelpers_Directive_GenerateDesignTimeMappings() + { + // Act & Assert + RunTagHelperTest("AddTagHelperDirective", + designTimeMode: true, + tagHelperDescriptors: new[] { + new TagHelperDescriptor("p", "pTagHelper", ContentBehavior.None) + }); + } + [Theory] [InlineData("TagHelpersInSection")] [InlineData("TagHelpersInHelper")] @@ -19,21 +49,20 @@ namespace Microsoft.AspNet.Razor.Test.Generator var propertyInfoMock = new Mock(); propertyInfoMock.Setup(propertyInfo => propertyInfo.PropertyType).Returns(typeof(string)); propertyInfoMock.Setup(propertyInfo => propertyInfo.Name).Returns("BoundProperty"); - var tagHelperDescriptorProvider = new TagHelperDescriptorProvider( - new TagHelperDescriptor[] - { - new TagHelperDescriptor("MyTagHelper", - "MyTagHelper", - ContentBehavior.None, - new [] { - new TagHelperAttributeDescriptor("BoundProperty", - propertyInfoMock.Object) - }), - new TagHelperDescriptor("NestedTagHelper", "NestedTagHelper", ContentBehavior.Modify) - }); + var tagHelperDescriptors = new TagHelperDescriptor[] + { + new TagHelperDescriptor("MyTagHelper", + "MyTagHelper", + ContentBehavior.None, + new [] { + new TagHelperAttributeDescriptor("BoundProperty", + propertyInfoMock.Object) + }), + new TagHelperDescriptor("NestedTagHelper", "NestedTagHelper", ContentBehavior.Modify) + }; // Act & Assert - RunTagHelperTest(testType, tagHelperDescriptorProvider: tagHelperDescriptorProvider); + RunTagHelperTest(testType, tagHelperDescriptors: tagHelperDescriptors); } [Theory] @@ -52,50 +81,48 @@ namespace Microsoft.AspNet.Razor.Test.Generator var checkedPropertyInfo = new Mock(); checkedPropertyInfo.Setup(propertyInfo => propertyInfo.PropertyType).Returns(typeof(bool)); checkedPropertyInfo.Setup(propertyInfo => propertyInfo.Name).Returns("Checked"); - var tagHelperDescriptorProvider = new TagHelperDescriptorProvider( - new TagHelperDescriptor[] - { - new TagHelperDescriptor("p", - "PTagHelper", - ContentBehavior.None, - new [] { - new TagHelperAttributeDescriptor("foo", pFooPropertyInfo.Object) - }), - new TagHelperDescriptor("input", - "InputTagHelper", - ContentBehavior.None, - new TagHelperAttributeDescriptor[] { - new TagHelperAttributeDescriptor("type", inputTypePropertyInfo.Object) - }), - new TagHelperDescriptor("input", - "InputTagHelper2", - ContentBehavior.None, - new TagHelperAttributeDescriptor[] { - new TagHelperAttributeDescriptor("type", inputTypePropertyInfo.Object), - new TagHelperAttributeDescriptor("checked", checkedPropertyInfo.Object) - }), - }); + var tagHelperDescriptors = new TagHelperDescriptor[] + { + new TagHelperDescriptor("p", + "PTagHelper", + ContentBehavior.None, + new [] { + new TagHelperAttributeDescriptor("foo", pFooPropertyInfo.Object) + }), + new TagHelperDescriptor("input", + "InputTagHelper", + ContentBehavior.None, + new TagHelperAttributeDescriptor[] { + new TagHelperAttributeDescriptor("type", inputTypePropertyInfo.Object) + }), + new TagHelperDescriptor("input", + "InputTagHelper2", + ContentBehavior.None, + new TagHelperAttributeDescriptor[] { + new TagHelperAttributeDescriptor("type", inputTypePropertyInfo.Object), + new TagHelperAttributeDescriptor("checked", checkedPropertyInfo.Object) + }) + }; // Act & Assert - RunTagHelperTest(testType, tagHelperDescriptorProvider: tagHelperDescriptorProvider); + RunTagHelperTest(testType, tagHelperDescriptors: tagHelperDescriptors); } [Fact] public void TagHelpers_WithContentBehaviors_GenerateExpectedOutput() { // Arrange - var tagHelperDescriptorProvider = new TagHelperDescriptorProvider( - new TagHelperDescriptor[] - { + var tagHelperDescriptors = new TagHelperDescriptor[] + { new TagHelperDescriptor("modify", "ModifyTagHelper", ContentBehavior.Modify), new TagHelperDescriptor("none", "NoneTagHelper", ContentBehavior.None), new TagHelperDescriptor("append", "AppendTagHelper", ContentBehavior.Append), new TagHelperDescriptor("prepend", "PrependTagHelper", ContentBehavior.Prepend), new TagHelperDescriptor("replace", "ReplaceTagHelper", ContentBehavior.Replace), - }); + }; // Act & Assert - RunTagHelperTest("ContentBehaviorTagHelpers", tagHelperDescriptorProvider: tagHelperDescriptorProvider); + RunTagHelperTest("ContentBehaviorTagHelpers", tagHelperDescriptors: tagHelperDescriptors); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CSharpPaddingBuilderTests.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CSharpPaddingBuilderTests.cs index 226357cc66..23b5534154 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CSharpPaddingBuilderTests.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CSharpPaddingBuilderTests.cs @@ -8,6 +8,7 @@ using System.Linq; using Microsoft.AspNet.Razor.Generator.Compiler.CSharp; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.AspNet.Razor.TagHelpers; using Xunit; namespace Microsoft.AspNet.Razor.Test.Generator @@ -221,7 +222,9 @@ namespace Microsoft.AspNet.Razor.Test.Generator { Assert.True(spanIndex > 0); - var parser = new RazorParser(new CSharpCodeParser(), new HtmlMarkupParser()); + var parser = new RazorParser(new CSharpCodeParser(), + new HtmlMarkupParser(), + tagHelperDescriptorResolver: null); Span[] spans; diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/TagHelperAttributeValueCodeRendererTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/TagHelperAttributeValueCodeRendererTest.cs index 404cd0de10..82ba7ff1fb 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/TagHelperAttributeValueCodeRendererTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/TagHelperAttributeValueCodeRendererTest.cs @@ -24,29 +24,28 @@ namespace Microsoft.AspNet.Razor.Test.Generator var checkedPropertyInfo = new Mock(); checkedPropertyInfo.Setup(propertyInfo => propertyInfo.PropertyType).Returns(typeof(bool)); checkedPropertyInfo.Setup(propertyInfo => propertyInfo.Name).Returns("Checked"); - var tagHelperDescriptorProvider = new TagHelperDescriptorProvider( - new TagHelperDescriptor[] - { - new TagHelperDescriptor("p", "PTagHelper", ContentBehavior.None), - new TagHelperDescriptor("input", - "InputTagHelper", - ContentBehavior.None, - new TagHelperAttributeDescriptor[] { - new TagHelperAttributeDescriptor("type", inputTypePropertyInfo.Object) - }), - new TagHelperDescriptor("input", - "InputTagHelper2", - ContentBehavior.None, - new TagHelperAttributeDescriptor[] { - new TagHelperAttributeDescriptor("type", inputTypePropertyInfo.Object), - new TagHelperAttributeDescriptor("checked", checkedPropertyInfo.Object) - }), - }); + var tagHelperDescriptors = new TagHelperDescriptor[] + { + new TagHelperDescriptor("p", "PTagHelper", ContentBehavior.None), + new TagHelperDescriptor("input", + "InputTagHelper", + ContentBehavior.None, + new TagHelperAttributeDescriptor[] { + new TagHelperAttributeDescriptor("type", inputTypePropertyInfo.Object) + }), + new TagHelperDescriptor("input", + "InputTagHelper2", + ContentBehavior.None, + new TagHelperAttributeDescriptor[] { + new TagHelperAttributeDescriptor("type", inputTypePropertyInfo.Object), + new TagHelperAttributeDescriptor("checked", checkedPropertyInfo.Object) + }) + }; // Act & Assert RunTagHelperTest(testName: "BasicTagHelpers", baseLineName: "BasicTagHelpers.CustomAttributeCodeGenerator", - tagHelperDescriptorProvider: tagHelperDescriptorProvider, + tagHelperDescriptors: tagHelperDescriptors, hostConfig: (host) => { return new CodeBuilderReplacingHost(host); diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/TagHelperTestBase.cs b/test/Microsoft.AspNet.Razor.Test/Generator/TagHelperTestBase.cs index 5ca58a9c06..b88c31f367 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/TagHelperTestBase.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/TagHelperTestBase.cs @@ -2,9 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Linq; +using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Parser; -using Microsoft.AspNet.Razor.Parser.TagHelpers.Internal; using Microsoft.AspNet.Razor.TagHelpers; namespace Microsoft.AspNet.Razor.Test.Generator @@ -13,43 +14,56 @@ namespace Microsoft.AspNet.Razor.Test.Generator { protected void RunTagHelperTest(string testName, string baseLineName = null, - TagHelperDescriptorProvider tagHelperDescriptorProvider = null, - Func hostConfig = null) + bool designTimeMode = false, + IEnumerable tagHelperDescriptors = null, + Func hostConfig = null, + IList expectedDesignTimePragmas = null) { RunTest(name: testName, baselineName: baseLineName, + designTimeMode: designTimeMode, + tabTest: TabTest.NoTabs, templateEngineConfig: (engine) => { - return new TagHelperTemplateEngine(engine, tagHelperDescriptorProvider); + return new TagHelperTemplateEngine(engine, tagHelperDescriptors); }, - hostConfig: hostConfig); + hostConfig: hostConfig, + expectedDesignTimePragmas: expectedDesignTimePragmas); + } + + private class CustomTagHelperDescriptorResolver : ITagHelperDescriptorResolver + { + private IEnumerable _tagHelperDescriptors; + + public CustomTagHelperDescriptorResolver(IEnumerable tagHelperDescriptors) + { + _tagHelperDescriptors = tagHelperDescriptors ?? Enumerable.Empty(); + } + + public IEnumerable Resolve(string lookupText) + { + return _tagHelperDescriptors; + } } private class TagHelperTemplateEngine : RazorTemplateEngine { - private TagHelperDescriptorProvider _tagHelperDescriptorProvider; + private IEnumerable _tagHelperDescriptors; - public TagHelperTemplateEngine(RazorTemplateEngine engine, TagHelperDescriptorProvider tagHelperDescriptorProvider) + public TagHelperTemplateEngine(RazorTemplateEngine engine, + IEnumerable tagHelperDescriptors) : base(engine.Host) { - _tagHelperDescriptorProvider = tagHelperDescriptorProvider; + _tagHelperDescriptors = tagHelperDescriptors; } protected internal override RazorParser CreateParser() { var parser = base.CreateParser(); - var tagHelperParseTreeRewriter = new TagHelperParseTreeRewriter(_tagHelperDescriptorProvider); - for (var i = 0; i < parser.Optimizers.Count; i++) - { - if (parser.Optimizers[i] is TagHelperParseTreeRewriter) - { - parser.Optimizers[i] = tagHelperParseTreeRewriter; - break; - } - } - - return parser; + return new RazorParser(parser.CodeParser, + parser.MarkupParser, + new CustomTagHelperDescriptorResolver(_tagHelperDescriptors)); } } } diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpDirectivesTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpDirectivesTest.cs index 42d100a4f6..07e1234ad6 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpDirectivesTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpDirectivesTest.cs @@ -12,6 +12,93 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp { public class CSharpDirectivesTest : CsHtmlCodeParserTestBase { + [Fact] + public void AddTagHelperDirective_Succeeds() + { + ParseBlockTest("@addtaghelper \"Foo\"", + new DirectiveBlock( + Factory.CodeTransition(), + Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ") + .Accepts(AcceptedCharacters.None), + Factory.Code("\"Foo\"").AsAddTagHelper("Foo"))); + } + + [Fact] + public void AddTagHelperDirectiveSupportsSpaces() + { + ParseBlockTest("@addtaghelper \" Foo, Bar \" ", + new DirectiveBlock( + Factory.CodeTransition(), + Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ") + .Accepts(AcceptedCharacters.None), + Factory.Code("\" Foo, Bar \" ").AsAddTagHelper(" Foo, Bar "))); + } + + [Fact] + public void AddTagHelperDirectiveRequiresValue() + { + ParseBlockTest("@addtaghelper ", + new DirectiveBlock( + Factory.CodeTransition(), + Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ") + .Accepts(AcceptedCharacters.None), + Factory.EmptyCSharp().AsAddTagHelper(string.Empty)), + new RazorError( + RazorResources.FormatParseError_DirectiveMustHaveValue(SyntaxConstants.CSharp.AddTagHelperKeyword), + absoluteIndex: 14, lineIndex: 0, columnIndex: 14)); + } + + [Fact] + public void AddTagHelperDirectiveWithStartQuoteRequiresDoubleQuotesAroundValue() + { + ParseBlockTest("@addtaghelper \"Foo", + new DirectiveBlock( + Factory.CodeTransition(), + Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ") + .Accepts(AcceptedCharacters.None), + Factory.Code("\"Foo").AsAddTagHelper("Foo")), + new RazorError( + RazorResources.ParseError_Unterminated_String_Literal, + absoluteIndex: 14, lineIndex: 0, columnIndex: 14), + new RazorError( + RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( + SyntaxConstants.CSharp.AddTagHelperKeyword), + absoluteIndex: 14, lineIndex: 0, columnIndex: 14)); + } + + [Fact] + public void AddTagHelperDirectiveWithEndQuoteRequiresDoubleQuotesAroundValue() + { + ParseBlockTest("@addtaghelper Foo\"", + new DirectiveBlock( + Factory.CodeTransition(), + Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ") + .Accepts(AcceptedCharacters.None), + Factory.Code("Foo\"").AsAddTagHelper("Foo")), + new RazorError( + RazorResources.ParseError_Unterminated_String_Literal, + absoluteIndex: 17, lineIndex: 0, columnIndex: 17), + new RazorError( + RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( + SyntaxConstants.CSharp.AddTagHelperKeyword), + absoluteIndex: 14, lineIndex: 0, columnIndex: 14)); + } + + [Fact] + public void AddTagHelperDirectiveRequiresDoubleQuotesAroundValue() + { + ParseBlockTest("@addtaghelper Foo", + new DirectiveBlock( + Factory.CodeTransition(), + Factory.MetaCode(SyntaxConstants.CSharp.AddTagHelperKeyword + " ") + .Accepts(AcceptedCharacters.None), + Factory.Code("Foo").AsAddTagHelper("Foo")), + new RazorError( + RazorResources.FormatParseError_DirectiveMustBeSurroundedByQuotes( + SyntaxConstants.CSharp.AddTagHelperKeyword), + absoluteIndex: 14, lineIndex: 0, columnIndex: 14)); + } + [Fact] public void InheritsDirective() { diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/RazorParserTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/RazorParserTest.cs index 61c027c41b..ac99c0450b 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/RazorParserTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/RazorParserTest.cs @@ -5,6 +5,7 @@ using System; using System.IO; using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser.SyntaxTree; +using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.Test.Framework; using Xunit; @@ -12,25 +13,15 @@ namespace Microsoft.AspNet.Razor.Test.Parser { public class RazorParserTest { - [Fact] - public void ConstructorRequiresNonNullCodeParser() - { - Assert.Throws("codeParser", () => new RazorParser(null, new HtmlMarkupParser())); - } - - [Fact] - public void ConstructorRequiresNonNullMarkupParser() - { - Assert.Throws("markupParser", () => new RazorParser(new CSharpCodeParser(), null)); - } - [Fact] public void ParseMethodCallsParseDocumentOnMarkupParserAndReturnsResults() { var factory = SpanFactory.CreateCsHtml(); // Arrange - RazorParser parser = new RazorParser(new CSharpCodeParser(), new HtmlMarkupParser()); + RazorParser parser = new RazorParser(new CSharpCodeParser(), + new HtmlMarkupParser(), + tagHelperDescriptorResolver: null); // Act/Assert ParserTestBase.EvaluateResults(parser.Parse(new StringReader("foo @bar baz")), @@ -50,7 +41,9 @@ namespace Microsoft.AspNet.Razor.Test.Parser var factory = SpanFactory.CreateCsHtml(); // Arrange - RazorParser parser = new RazorParser(new CSharpCodeParser(), new HtmlMarkupParser()); + RazorParser parser = new RazorParser(new CSharpCodeParser(), + new HtmlMarkupParser(), + tagHelperDescriptorResolver: null); // Act ParserResults results = parser.Parse(new StringReader("foo @bar baz")); @@ -78,7 +71,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser // Arrange ParserBase markupParser = new MockMarkupParser(); ParserBase codeParser = new CSharpCodeParser(); - RazorParser parser = new RazorParser(codeParser, markupParser); + RazorParser parser = new RazorParser(codeParser, markupParser, tagHelperDescriptorResolver: null); TextReader expectedReader = new StringReader("foo"); // Act diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/AddTagHelperDirective.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/AddTagHelperDirective.cs new file mode 100644 index 0000000000..aadc028436 --- /dev/null +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/AddTagHelperDirective.cs @@ -0,0 +1,33 @@ +namespace TestOutput +{ + using System; + using System.Threading.Tasks; + + public class AddTagHelperDirective + { + private static object @__o; + private void @__RazorDesignTimeHelpers__() + { + #pragma warning disable 219 + string __tagHelperDirectiveSyntaxHelper = null; + __tagHelperDirectiveSyntaxHelper = +#line 1 "AddTagHelperDirective.cshtml" + "something" + +#line default +#line hidden + ; + #pragma warning restore 219 + } + #line hidden + public AddTagHelperDirective() + { + } + + #pragma warning disable 1998 + public override async Task ExecuteAsync() + { + } + #pragma warning restore 1998 + } +} 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 62df1e570a..0db29ec3af 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 @@ -1,4 +1,4 @@ -#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "8d60e58d54168749dc71a0d6d3a95887b2adb5e7" +#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "897cb2042003c7f319b5265ba8e1878fb3043e8e" namespace TestOutput { using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -22,8 +22,8 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - Instrumentation.BeginContext(0, 47, true); - WriteLiteral("
\r\n "); + Instrumentation.BeginContext(27, 49, true); + WriteLiteral("\r\n
\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p"); __PTagHelper = CreateTagHelper(); @@ -31,7 +31,7 @@ namespace TestOutput __tagHelperExecutionContext.AddHtmlAttribute("class", "Hello World"); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(70, 10, true); + Instrumentation.BeginContext(99, 10, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p"); @@ -41,7 +41,7 @@ namespace TestOutput WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(87, 10, true); + Instrumentation.BeginContext(116, 10, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input"); @@ -56,7 +56,7 @@ namespace TestOutput WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(118, 10, true); + Instrumentation.BeginContext(147, 10, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input"); @@ -73,12 +73,12 @@ namespace TestOutput WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(167, 6, true); + Instrumentation.BeginContext(196, 6, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(177, 8, true); + Instrumentation.BeginContext(206, 8, true); WriteLiteral("\r\n
"); Instrumentation.EndContext(); } 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 85f57d07cc..174c0d754a 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 @@ -1,4 +1,4 @@ -#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "8d60e58d54168749dc71a0d6d3a95887b2adb5e7" +#pragma checksum "BasicTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "897cb2042003c7f319b5265ba8e1878fb3043e8e" namespace TestOutput { using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -23,8 +23,8 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { - Instrumentation.BeginContext(0, 47, true); - WriteLiteral("
\r\n "); + Instrumentation.BeginContext(27, 49, true); + WriteLiteral("\r\n
\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p"); __PTagHelper = CreateTagHelper(); @@ -32,7 +32,7 @@ namespace TestOutput __tagHelperExecutionContext.AddHtmlAttribute("class", "Hello World"); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(70, 10, true); + Instrumentation.BeginContext(99, 10, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p"); @@ -42,7 +42,7 @@ namespace TestOutput WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(87, 10, true); + Instrumentation.BeginContext(116, 10, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input"); @@ -57,7 +57,7 @@ namespace TestOutput WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(118, 10, true); + Instrumentation.BeginContext(147, 10, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input"); @@ -74,12 +74,12 @@ namespace TestOutput WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(167, 6, true); + Instrumentation.BeginContext(196, 6, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(177, 8, true); + Instrumentation.BeginContext(206, 8, true); WriteLiteral("\r\n
"); Instrumentation.EndContext(); } 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 6d1a6ad451..09148a9f90 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 @@ -1,4 +1,4 @@ -#pragma checksum "ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "7540f76029963ad4e3c0a02077a63d0fe2cb0157" +#pragma checksum "ComplexTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "cce31144cd1c3c35d241b49e41c4fc04ff044565" namespace TestOutput { using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -23,7 +23,10 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { -#line 1 "ComplexTagHelpers.cshtml" + Instrumentation.BeginContext(27, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); +#line 3 "ComplexTagHelpers.cshtml" if (true) { var checkbox = "checkbox"; @@ -32,7 +35,7 @@ namespace TestOutput #line default #line hidden - Instrumentation.BeginContext(49, 55, true); + Instrumentation.BeginContext(78, 55, true); WriteLiteral("
\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p"); @@ -40,7 +43,7 @@ namespace TestOutput __tagHelperExecutionContext.Add(__PTagHelper); StartWritingScope(); WriteLiteral("Current Time: "); -#line 6 "ComplexTagHelpers.cshtml" +#line 8 "ComplexTagHelpers.cshtml" Write(DateTime.Now); #line default @@ -49,23 +52,23 @@ Write(DateTime.Now); __tagHelperExecutionContext.AddHtmlAttribute("time", __tagHelperStringValueBuffer.ToString()); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(142, 34, true); + Instrumentation.BeginContext(171, 34, true); WriteLiteral("\r\n

Set Time:

\r\n"); Instrumentation.EndContext(); -#line 8 "ComplexTagHelpers.cshtml" +#line 10 "ComplexTagHelpers.cshtml" #line default #line hidden -#line 8 "ComplexTagHelpers.cshtml" +#line 10 "ComplexTagHelpers.cshtml" if (false) { #line default #line hidden - Instrumentation.BeginContext(216, 16, true); + Instrumentation.BeginContext(245, 16, true); WriteLiteral(" "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p"); @@ -73,7 +76,7 @@ Write(DateTime.Now); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(235, 10, true); + Instrumentation.BeginContext(264, 10, true); WriteLiteral("New Time: "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input"); @@ -92,10 +95,10 @@ Write(DateTime.Now); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(315, 2, true); + Instrumentation.BeginContext(344, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); -#line 11 "ComplexTagHelpers.cshtml" +#line 13 "ComplexTagHelpers.cshtml" } else { @@ -103,7 +106,7 @@ Write(DateTime.Now); #line default #line hidden - Instrumentation.BeginContext(365, 16, true); + Instrumentation.BeginContext(394, 16, true); WriteLiteral(" "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p"); @@ -111,14 +114,14 @@ Write(DateTime.Now); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(384, 14, true); + Instrumentation.BeginContext(413, 14, true); WriteLiteral("Current Time: "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input"); __InputTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__InputTagHelper); StartWritingScope(); -#line 14 "ComplexTagHelpers.cshtml" +#line 16 "ComplexTagHelpers.cshtml" Write(checkbox); #line default @@ -137,14 +140,14 @@ Write(checkbox); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(439, 18, true); + Instrumentation.BeginContext(468, 18, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input"); __InputTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__InputTagHelper); StartWritingScope(); -#line 15 "ComplexTagHelpers.cshtml" +#line 17 "ComplexTagHelpers.cshtml" Write(true ? "checkbox" : "anything"); #line default @@ -159,28 +162,28 @@ Write(true ? "checkbox" : "anything"); WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(507, 18, true); + Instrumentation.BeginContext(536, 18, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input"); __InputTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__InputTagHelper); StartWritingScope(); -#line 16 "ComplexTagHelpers.cshtml" +#line 18 "ComplexTagHelpers.cshtml" if(true) { #line default #line hidden WriteLiteral(" checkbox "); -#line 16 "ComplexTagHelpers.cshtml" +#line 18 "ComplexTagHelpers.cshtml" } else { #line default #line hidden WriteLiteral(" anything "); -#line 16 "ComplexTagHelpers.cshtml" +#line 18 "ComplexTagHelpers.cshtml" } #line default @@ -196,24 +199,24 @@ if(true) { WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(608, 2, true); + Instrumentation.BeginContext(637, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); -#line 17 "ComplexTagHelpers.cshtml" +#line 19 "ComplexTagHelpers.cshtml" } #line default #line hidden - Instrumentation.BeginContext(625, 8, true); + Instrumentation.BeginContext(654, 8, true); WriteLiteral(" "); Instrumentation.EndContext(); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(637, 14, true); + Instrumentation.BeginContext(666, 14, true); WriteLiteral("\r\n
\r\n"); Instrumentation.EndContext(); -#line 20 "ComplexTagHelpers.cshtml" +#line 22 "ComplexTagHelpers.cshtml" } #line default diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ContentBehaviorTagHelpers.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ContentBehaviorTagHelpers.cs index f671242af7..c9e8f1adc3 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ContentBehaviorTagHelpers.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ContentBehaviorTagHelpers.cs @@ -1,4 +1,4 @@ -#pragma checksum "ContentBehaviorTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "27af4f673a178e8b27e320ea0d869aaf6a16a18b" +#pragma checksum "ContentBehaviorTagHelpers.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "5aeeb0a2b5283b353efaff2cd2fb0c739020b899" namespace TestOutput { using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -25,6 +25,9 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(27, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("modify"); __ModifyTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__ModifyTagHelper); 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 6b54ef7b48..45a3fb4fd2 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 @@ -1,4 +1,4 @@ -#pragma checksum "SingleTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "2c9b5f2ce383fe784f68f84cbb669ab04077c417" +#pragma checksum "SingleTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "61bf4cc89584cdbbac4478b202fe04797ddeb68a" namespace TestOutput { using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -21,6 +21,9 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(27, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p"); __PTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__PTagHelper); @@ -29,7 +32,7 @@ namespace TestOutput __tagHelperExecutionContext.AddHtmlAttribute("class", "Hello World"); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(34, 11, true); + Instrumentation.BeginContext(63, 11, true); WriteLiteral("Body of Tag"); Instrumentation.EndContext(); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); 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 1251dbf24c..c24bfdee97 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 @@ -1,4 +1,4 @@ -#pragma checksum "TagHelpersInHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "522348d1a7650330b24372fade70f418f61027bd" +#pragma checksum "TagHelpersInHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "864bdf0afabc2aecf57904d5793a20bb6d12a6a3" namespace TestOutput { using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -8,20 +8,20 @@ namespace TestOutput public class TagHelpersInHelper { public static Template -#line 1 "TagHelpersInHelper.cshtml" +#line 3 "TagHelpersInHelper.cshtml" MyHelper(string val) { #line default #line hidden return new Template((__razor_helper_writer) => { -#line 2 "TagHelpersInHelper.cshtml" +#line 4 "TagHelpersInHelper.cshtml" #line default #line hidden - Instrumentation.BeginContext(33, 19, true); + Instrumentation.BeginContext(62, 19, true); WriteLiteralTo(__razor_helper_writer, "
\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("mytaghelper"); @@ -29,7 +29,7 @@ MyHelper(string val) __tagHelperExecutionContext.Add(__MyTagHelper); StartWritingScope(); WriteLiteral("Current Time: "); -#line 4 "TagHelpersInHelper.cshtml" +#line 6 "TagHelpersInHelper.cshtml" Write(DateTime.Now); #line default @@ -39,7 +39,7 @@ Write(DateTime.Now); __tagHelperExecutionContext.AddTagHelperAttribute("BoundProperty", __MyTagHelper.BoundProperty); StartWritingScope(); WriteLiteral("Current Time: "); -#line 4 "TagHelpersInHelper.cshtml" +#line 6 "TagHelpersInHelper.cshtml" Write(DateTime.Now); #line default @@ -48,7 +48,7 @@ Write(DateTime.Now); __tagHelperExecutionContext.AddHtmlAttribute("unboundproperty", __tagHelperStringValueBuffer.ToString()); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteralTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(155, 52, true); + Instrumentation.BeginContext(184, 52, true); WriteLiteralTo(__razor_helper_writer, "\r\n In None ContentBehavior.\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("nestedtaghelper"); @@ -56,7 +56,7 @@ Write(DateTime.Now); __tagHelperExecutionContext.Add(__NestedTagHelper); StartWritingScope(); WriteLiteral("Some buffered values with a value of "); -#line 6 "TagHelpersInHelper.cshtml" +#line 8 "TagHelpersInHelper.cshtml" Write(val); #line default @@ -67,22 +67,22 @@ Write(DateTime.Now); WriteLiteralTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GenerateContent()); WriteLiteralTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(283, 10, true); + Instrumentation.BeginContext(312, 10, true); WriteLiteralTo(__razor_helper_writer, "\r\n "); Instrumentation.EndContext(); WriteLiteralTo(__razor_helper_writer, __tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(307, 14, true); + Instrumentation.BeginContext(336, 14, true); WriteLiteralTo(__razor_helper_writer, "\r\n
\r\n"); Instrumentation.EndContext(); -#line 9 "TagHelpersInHelper.cshtml" +#line 11 "TagHelpersInHelper.cshtml" #line default #line hidden } ); -#line 9 "TagHelpersInHelper.cshtml" +#line 11 "TagHelpersInHelper.cshtml" } #line default @@ -103,13 +103,16 @@ Write(DateTime.Now); #pragma warning disable 1998 public override async Task ExecuteAsync() { + Instrumentation.BeginContext(27, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("mytaghelper"); __MyTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__MyTagHelper); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(338, 9, false); -#line 10 "TagHelpersInHelper.cshtml" + Instrumentation.BeginContext(367, 9, false); +#line 12 "TagHelpersInHelper.cshtml" Write(MyHelper(item => new Template((__razor_template_writer) => { __tagHelperExecutionContext = __tagHelperScopeManager.Begin("nestedtaghelper"); __NestedTagHelper = CreateTagHelper(); @@ -131,7 +134,7 @@ Write(MyHelper(item => new Template((__razor_template_writer) => { Instrumentation.EndContext(); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(410, 2, true); + Instrumentation.BeginContext(439, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); } 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 fc12441f5a..ada5cafd0e 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 @@ -1,4 +1,4 @@ -#pragma checksum "TagHelpersInSection.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "bfe8d61279682f87dc473aa71134e86af554f55e" +#pragma checksum "TagHelpersInSection.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "2571c1678f925672aa18f5e7ae50916089e8f5cb" namespace TestOutput { using System; @@ -21,18 +21,21 @@ namespace TestOutput #pragma warning disable 1998 public override async Task ExecuteAsync() { -#line 1 "TagHelpersInSection.cshtml" + Instrumentation.BeginContext(27, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); +#line 3 "TagHelpersInSection.cshtml" var code = "some code"; #line default #line hidden - Instrumentation.BeginContext(34, 4, true); + Instrumentation.BeginContext(63, 4, true); WriteLiteral("\r\n\r\n"); Instrumentation.EndContext(); DefineSection("MySection", new Template((__razor_template_writer) => { - Instrumentation.BeginContext(58, 21, true); + Instrumentation.BeginContext(87, 21, true); WriteLiteralTo(__razor_template_writer, "\r\n
\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("mytaghelper"); @@ -40,7 +43,7 @@ namespace TestOutput __tagHelperExecutionContext.Add(__MyTagHelper); StartWritingScope(); WriteLiteral("Current Time: "); -#line 7 "TagHelpersInSection.cshtml" +#line 9 "TagHelpersInSection.cshtml" Write(DateTime.Now); #line default @@ -50,7 +53,7 @@ Write(DateTime.Now); __tagHelperExecutionContext.AddTagHelperAttribute("BoundProperty", __MyTagHelper.BoundProperty); StartWritingScope(); WriteLiteral("Current Time: "); -#line 7 "TagHelpersInSection.cshtml" +#line 9 "TagHelpersInSection.cshtml" Write(DateTime.Now); #line default @@ -59,7 +62,7 @@ Write(DateTime.Now); __tagHelperExecutionContext.AddHtmlAttribute("unboundproperty", __tagHelperStringValueBuffer.ToString()); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteralTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateStartTag()); - Instrumentation.BeginContext(182, 52, true); + Instrumentation.BeginContext(211, 52, true); WriteLiteralTo(__razor_template_writer, "\r\n In None ContentBehavior.\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("nestedtaghelper"); @@ -67,7 +70,7 @@ Write(DateTime.Now); __tagHelperExecutionContext.Add(__NestedTagHelper); StartWritingScope(); WriteLiteral("Some buffered values with "); -#line 9 "TagHelpersInSection.cshtml" +#line 11 "TagHelpersInSection.cshtml" Write(code); #line default @@ -78,12 +81,12 @@ Write(DateTime.Now); WriteLiteralTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateContent()); WriteLiteralTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(300, 10, true); + Instrumentation.BeginContext(329, 10, true); WriteLiteralTo(__razor_template_writer, "\r\n "); Instrumentation.EndContext(); WriteLiteralTo(__razor_template_writer, __tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); - Instrumentation.BeginContext(324, 14, true); + Instrumentation.BeginContext(353, 14, true); WriteLiteralTo(__razor_template_writer, "\r\n
\r\n"); Instrumentation.EndContext(); } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/AddTagHelperDirective.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/AddTagHelperDirective.cshtml new file mode 100644 index 0000000000..097df41a31 --- /dev/null +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/AddTagHelperDirective.cshtml @@ -0,0 +1 @@ +@addtaghelper "something" \ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/BasicTagHelpers.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/BasicTagHelpers.cshtml index e180b12d53..6afc249a24 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/BasicTagHelpers.cshtml +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/BasicTagHelpers.cshtml @@ -1,4 +1,6 @@ -
+@addtaghelper "something" + +

diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/ComplexTagHelpers.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/ComplexTagHelpers.cshtml index eb28e6a594..7ba3c6db48 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/ComplexTagHelpers.cshtml +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/ComplexTagHelpers.cshtml @@ -1,4 +1,6 @@ -@if (true) +@addtaghelper "something" + +@if (true) { var checkbox = "checkbox"; diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/ContentBehaviorTagHelpers.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/ContentBehaviorTagHelpers.cshtml index 1856158b6b..90f4fcd204 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/ContentBehaviorTagHelpers.cshtml +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/ContentBehaviorTagHelpers.cshtml @@ -1,4 +1,6 @@ - +@addtaghelper "something" + + diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/SingleTagHelper.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/SingleTagHelper.cshtml index 832b95049d..32411e496b 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/SingleTagHelper.cshtml +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/SingleTagHelper.cshtml @@ -1 +1,3 @@ -

Body of Tag

\ No newline at end of file +@addtaghelper "something" + +

Body of Tag

\ No newline at end of file diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/TagHelpersInHelper.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/TagHelpersInHelper.cshtml index 28a7219bc1..e2c881377b 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/TagHelpersInHelper.cshtml +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/TagHelpersInHelper.cshtml @@ -1,4 +1,6 @@ -@helper MyHelper(string val) +@addtaghelper "something" + +@helper MyHelper(string val) {
diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/TagHelpersInSection.cshtml b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/TagHelpersInSection.cshtml index f87c72a863..d205cd041a 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/TagHelpersInSection.cshtml +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Source/TagHelpersInSection.cshtml @@ -1,4 +1,6 @@ -@{ +@addtaghelper "something" + +@{ var code = "some code"; }