#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => { Instrumentation.BeginContext(69, 11, true); WriteLiteral("Body of Tag"); Instrumentation.EndContext(); } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("Hello World")); #line 3 "SingleTagHelper.cshtml" __PTagHelper.Age = 1337; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(35, 49, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); }
/// <summary> /// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s. /// </summary> /// <param name="executionContext">Contains information associated with running <see cref="ITagHelper"/>s. /// </param> /// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the /// <paramref name="executionContext"/>'s <see cref="ITagHelper"/>s.</returns> public async Task<TagHelperOutput> RunAsync(TagHelperExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException(nameof(executionContext)); } var tagHelperContext = new TagHelperContext( executionContext.AllAttributes, executionContext.Items, executionContext.UniqueId, executionContext.GetChildContentAsync); var tagHelperOutput = new TagHelperOutput( executionContext.TagName, executionContext.HTMLAttributes) { TagMode = executionContext.TagMode, }; var orderedTagHelpers = executionContext.TagHelpers.OrderBy(tagHelper => tagHelper.Order); foreach (var tagHelper in orderedTagHelpers) { await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput); } return tagHelperOutput; }
#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __InputTagHelper = CreateTagHelper<InputTagHelper>(); __tagHelperExecutionContext.Add(__InputTagHelper); __InputTagHelper.Type = "checkbox"; __tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type); #line 3 "DuplicateTargetTagHelper.cshtml" __InputTagHelper.Checked = true; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper.Checked); __CatchAllTagHelper = CreateTagHelper<CatchAllTagHelper>(); __tagHelperExecutionContext.Add(__CatchAllTagHelper); __CatchAllTagHelper.Type = __InputTagHelper.Type; __CatchAllTagHelper.Checked = __InputTagHelper.Checked; __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); await WriteTagHelperAsync(__tagHelperExecutionContext); __tagHelperExecutionContext = __tagHelperScopeManager.End(); }
public async Task GetChildContentAsync_CachesValue() { // Arrange var defaultTagHelperContent = new DefaultTagHelperContent(); var content = string.Empty; var expectedContent = string.Empty; var executionContext = new TagHelperExecutionContext( "p", tagMode: TagMode.StartTagAndEndTag, items: new Dictionary<object, object>(), uniqueId: string.Empty, executeChildContentAsync: () => { if (string.IsNullOrEmpty(expectedContent)) { content = "Hello from child content: " + Guid.NewGuid().ToString(); expectedContent = $"HtmlEncode[[{content}]]"; } defaultTagHelperContent.SetContent(content); return Task.FromResult(result: true); }, startTagHelperWritingScope: () => { }, endTagHelperWritingScope: () => defaultTagHelperContent); // Act var content1 = await executionContext.GetChildContentAsync(useCachedResult: true); var content2 = await executionContext.GetChildContentAsync(useCachedResult: true); // Assert Assert.Equal(expectedContent, content1.GetContent(new HtmlTestEncoder())); Assert.Equal(expectedContent, content2.GetContent(new HtmlTestEncoder())); }
/// <summary> /// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s. /// </summary> /// <param name="executionContext">Contains information associated with running <see cref="ITagHelper"/>s. /// </param> /// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the /// <paramref name="executionContext"/>'s <see cref="ITagHelper"/>s.</returns> public async Task<TagHelperOutput> RunAsync(TagHelperExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException(nameof(executionContext)); } var tagHelperContext = new TagHelperContext( executionContext.AllAttributes, executionContext.Items, executionContext.UniqueId); OrderTagHelpers(executionContext.TagHelpers); for (var i = 0; i < executionContext.TagHelpers.Count; i++) { executionContext.TagHelpers[i].Init(tagHelperContext); } var tagHelperOutput = new TagHelperOutput( executionContext.TagName, executionContext.HTMLAttributes, executionContext.GetChildContentAsync) { TagMode = executionContext.TagMode, }; for (var i = 0; i < executionContext.TagHelpers.Count; i++) { await executionContext.TagHelpers[i].ProcessAsync(tagHelperContext, tagHelperOutput); } return tagHelperOutput; }
public async Task RunAsync_CallsInitPriorToProcessAsync() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); var incrementer = 0; var callbackTagHelper = new CallbackTagHelper( initCallback: () => { Assert.Equal(0, incrementer); incrementer++; }, processAsyncCallback: () => { Assert.Equal(1, incrementer); incrementer++; }); executionContext.Add(callbackTagHelper); // Act await runner.RunAsync(executionContext); // Assert Assert.Equal(2, incrementer); }
/// <summary> /// Starts a <see cref="TagHelperExecutionContext"/> scope. /// </summary> /// <param name="tagName">The HTML tag name that the scope is associated with.</param> /// <param name="selfClosing"> /// <see cref="bool"/> indicating whether or not the tag of this scope is self-closing. /// </param> /// <param name="uniqueId">An identifier unique to the HTML element this scope is for.</param> /// <param name="executeChildContentAsync">A delegate used to execute the child content asynchronously.</param> /// <param name="startTagHelperWritingScope">A delegate used to start a writing scope in a Razor page.</param> /// <param name="endTagHelperWritingScope">A delegate used to end a writing scope in a Razor page.</param> /// <returns>A <see cref="TagHelperExecutionContext"/> to use.</returns> public TagHelperExecutionContext Begin( [NotNull] string tagName, bool selfClosing, [NotNull] string uniqueId, [NotNull] Func<Task> executeChildContentAsync, [NotNull] Action startTagHelperWritingScope, [NotNull] Func<TagHelperContent> endTagHelperWritingScope) { IDictionary<object, object> items; // If we're not wrapped by another TagHelper, then there will not be a parentExecutionContext. if (_executionScopes.Count > 0) { items = new CopyOnWriteDictionary<object, object>( _executionScopes.Peek().Items, comparer: EqualityComparer<object>.Default); } else { items = new Dictionary<object, object>(); } var executionContext = new TagHelperExecutionContext( tagName, selfClosing, items, uniqueId, executeChildContentAsync, startTagHelperWritingScope, endTagHelperWritingScope); _executionScopes.Push(executionContext); return executionContext; }
public async Task GetChildContentAsync_CachesValue() { // Arrange var defaultTagHelperContent = new DefaultTagHelperContent(); var expectedContent = string.Empty; var executionContext = new TagHelperExecutionContext( "p", selfClosing: false, items: null, uniqueId: string.Empty, executeChildContentAsync: () => { if (string.IsNullOrEmpty(expectedContent)) { expectedContent = "Hello from child content: " + Guid.NewGuid().ToString(); } defaultTagHelperContent.SetContent(expectedContent); return Task.FromResult(result: true); }, startTagHelperWritingScope: () => { }, endTagHelperWritingScope: () => defaultTagHelperContent); // Act var content1 = await executionContext.GetChildContentAsync(); var content2 = await executionContext.GetChildContentAsync(); // Assert Assert.Equal(expectedContent, content1.GetContent()); Assert.Equal(expectedContent, content2.GetContent()); }
public void SelfClosing_ReturnsTrueOrFalseAsExpected(bool selfClosing) { // Arrange & Act var executionContext = new TagHelperExecutionContext("p", selfClosing); // Assert Assert.Equal(selfClosing, executionContext.SelfClosing); }
public void TagMode_ReturnsExpectedValue(TagMode tagMode) { // Arrange & Act var executionContext = new TagHelperExecutionContext("p", tagMode); // Assert Assert.Equal(tagMode, executionContext.TagMode); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(27, 13, true); WriteLiteral("\r\n<div>\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __InputTagHelper = CreateTagHelper<InputTagHelper>(); __tagHelperExecutionContext.Add(__InputTagHelper); __InputTagHelper.Type = ""; __tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type); __InputTagHelper2 = CreateTagHelper<InputTagHelper2>(); __tagHelperExecutionContext.Add(__InputTagHelper2); __InputTagHelper2.Type = __InputTagHelper.Type; #line 4 "EmptyAttributeTagHelpers.cshtml" __InputTagHelper2.Checked = ; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("")); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); await WriteTagHelperAsync(__tagHelperExecutionContext); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(74, 6, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", false, "test", async() => { WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __InputTagHelper = CreateTagHelper<InputTagHelper>(); __tagHelperExecutionContext.Add(__InputTagHelper); __InputTagHelper.Type = ""; __tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type); __InputTagHelper2 = CreateTagHelper<InputTagHelper2>(); __tagHelperExecutionContext.Add(__InputTagHelper2); __InputTagHelper2.Type = __InputTagHelper.Type; #line 6 "EmptyAttributeTagHelpers.cshtml" __InputTagHelper2.Checked = ; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("")); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); await WriteTagHelperAsync(__tagHelperExecutionContext); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 49, true); WriteLiteral("\r\n<div class=\"randomNonTagHelperAttribute\">\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", false, "test", async() => { WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", false, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); await WriteTagHelperAsync(__tagHelperExecutionContext); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __InputTagHelper = CreateTagHelper<InputTagHelper>(); __tagHelperExecutionContext.Add(__InputTagHelper); __InputTagHelper.Type = **From custom attribute code renderer**: "text"; __tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type); __InputTagHelper2 = CreateTagHelper<InputTagHelper2>(); __tagHelperExecutionContext.Add(__InputTagHelper2); __InputTagHelper2.Type = __InputTagHelper.Type; __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); await WriteTagHelperAsync(__tagHelperExecutionContext); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", true, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __InputTagHelper = CreateTagHelper<InputTagHelper>(); __tagHelperExecutionContext.Add(__InputTagHelper); __InputTagHelper.Type = **From custom attribute code renderer**: "checkbox"; __tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type); __InputTagHelper2 = CreateTagHelper<InputTagHelper2>(); __tagHelperExecutionContext.Add(__InputTagHelper2); __InputTagHelper2.Type = __InputTagHelper.Type; #line 7 "BasicTagHelpers.cshtml" __InputTagHelper2.Checked = **From custom attribute code renderer**: true; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); await WriteTagHelperAsync(__tagHelperExecutionContext); __tagHelperExecutionContext = __tagHelperScopeManager.End(); WriteLiteral("\r\n "); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { WriteLiteral("\r\n"); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("inputTest"); __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper <Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>(); __tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper); __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__model => __model.Now); __tagHelperExecutionContext.AddTagHelperAttribute("For", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); }
public async Task RunAsync_WithContentSetsOutputsContent() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p"); var tagHelper = new ExecutableTagHelper(); var contentWriter = new StringWriter(new StringBuilder("Hello World")); // Act executionContext.Add(tagHelper); var output = await runner.RunAsync(executionContext, contentWriter); // Assert Assert.Equal(output.Content, "Hello World"); }
public void HtmlAttributes_IgnoresCase(string originalName, string updatedName) { // Arrange var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); executionContext.HTMLAttributes[originalName] = "hello"; // Act executionContext.HTMLAttributes[updatedName] = "something else"; // Assert var attribute = Assert.Single(executionContext.HTMLAttributes); Assert.Equal(new TagHelperAttribute(originalName, "something else"), attribute); }
public void AllAttributes_IgnoresCase(string originalName, string updatedName) { // Arrange var executionContext = new TagHelperExecutionContext("p"); executionContext.AllAttributes[originalName] = false; // Act executionContext.AllAttributes[updatedName] = true; // Assert var attribute = Assert.Single(executionContext.AllAttributes); Assert.Equal(new KeyValuePair <string, object>(originalName, true), attribute); }
public void HtmlAttributes_IgnoresCase(string originalName, string updatedName) { // Arrange var executionContext = new TagHelperExecutionContext("p"); executionContext.HTMLAttributes[originalName] = "hello"; // Act executionContext.HTMLAttributes[updatedName] = "something else"; // Assert var attribute = Assert.Single(executionContext.HTMLAttributes); Assert.Equal(new KeyValuePair <string, string>(originalName, "something else"), attribute); }
public async Task RunAsync_AllowsDataRetrievalFromTagHelperContext() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); var tagHelper = new TagHelperContextTouchingTagHelper(); // Act executionContext.Add(tagHelper); executionContext.AddTagHelperAttribute("foo", true); var output = await runner.RunAsync(executionContext); // Assert Assert.Equal("True", output.Attributes["foo"].Value); }
public void AllAttributes_IgnoresCase(string originalName, string updatedName) { // Arrange var executionContext = new TagHelperExecutionContext("p", tagMode: TagMode.StartTagAndEndTag); executionContext.AllAttributes.Add(originalName, value: false); // Act executionContext.AllAttributes[updatedName].Value = true; // Assert var attribute = Assert.Single(executionContext.AllAttributes); Assert.Equal(new TagHelperAttribute(originalName, true), attribute); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(27, 72, true); WriteLiteral("\r\n<div class=\"randomNonTagHelperAttribute\">\r\n <p class=\"Hello World\" "); Instrumentation.EndContext(); Instrumentation.BeginContext(102, 12, false); #line 4 "EscapedTagHelpers.cshtml" Write(DateTime.Now); #line default #line hidden Instrumentation.EndContext(); Instrumentation.BeginContext(114, 69, true); WriteLiteral(">\r\n <input type=\"text\" />\r\n <em>Not a TagHelper: </em> "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input", TagMode.SelfClosing, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __InputTagHelper = CreateTagHelper<InputTagHelper>(); __tagHelperExecutionContext.Add(__InputTagHelper); __InputTagHelper2 = CreateTagHelper<InputTagHelper2>(); __tagHelperExecutionContext.Add(__InputTagHelper2); StartTagHelperWritingScope(); #line 6 "EscapedTagHelpers.cshtml" WriteLiteral(DateTime.Now); #line default #line hidden __tagHelperStringValueBuffer = EndTagHelperWritingScope(); __InputTagHelper.Type = __tagHelperStringValueBuffer.GetContent(HtmlEncoder); __tagHelperExecutionContext.AddTagHelperAttribute("type", __InputTagHelper.Type); __InputTagHelper2.Type = __InputTagHelper.Type; #line 6 "EscapedTagHelpers.cshtml" __InputTagHelper2.Checked = true; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("checked", __InputTagHelper2.Checked); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(186, 45, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(231, 18, true); WriteLiteral("\r\n </p>\r\n</div>"); Instrumentation.EndContext(); }
public async Task RunAsync_SetsTagHelperOutputTagMode(TagMode tagMode) { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", tagMode); var tagHelper = new TagHelperContextTouchingTagHelper(); executionContext.Add(tagHelper); executionContext.AddTagHelperAttribute("foo", true); // Act var output = await runner.RunAsync(executionContext); // Assert Assert.Equal(tagMode, output.TagMode); }
/// <summary> /// Starts a <see cref="TagHelperExecutionContext"/> scope. /// </summary> /// <param name="tagName">The HTML tag name that the scope is associated with.</param> /// <param name="uniqueId">An identifier unique to the HTML element this scope is for.</param> /// <param name="executeChildContentAsync">A delegate used to execute the child content asynchronously.</param> /// <param name="startWritingScope">A delegate used to start a writing scope in a Razor page.</param> /// <param name="endWritingScope">A delegate used to end a writing scope in a Razor page.</param> /// <returns>A <see cref="TagHelperExecutionContext"/> to use.</returns> public TagHelperExecutionContext Begin([NotNull] string tagName, [NotNull] string uniqueId, [NotNull] Func <Task> executeChildContentAsync, [NotNull] Action startWritingScope, [NotNull] Func <TextWriter> endWritingScope) { var executionContext = new TagHelperExecutionContext(tagName, uniqueId, executeChildContentAsync, startWritingScope, endWritingScope); _executionScopes.Push(executionContext); return(executionContext); }
public async Task RunAsync_SetTagHelperOutputSelfClosing(bool selfClosing) { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing); var tagHelper = new TagHelperContextTouchingTagHelper(); executionContext.Add(tagHelper); executionContext.AddTagHelperAttribute("foo", true); // Act var output = await runner.RunAsync(executionContext); // Assert Assert.Equal(selfClosing, output.SelfClosing); }
public async Task RunAsync_ConfiguresTagHelperContextWithExecutionContextsItems() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var tagHelper = new ContextInspectingTagHelper(); executionContext.Add(tagHelper); // Act await runner.RunAsync(executionContext); // Assert Assert.NotNull(tagHelper.ContextProcessedWith); Assert.Same(tagHelper.ContextProcessedWith.Items, executionContext.Items); }
public void AddHtmlAttribute_MaintainsHTMLAttributes() { // Arrange var executionContext = new TagHelperExecutionContext("p"); var expectedAttributes = new Dictionary <string, string> { { "class", "btn" }, { "foo", "bar" } }; // Act executionContext.AddHtmlAttribute("class", "btn"); executionContext.AddHtmlAttribute("foo", "bar"); // Assert Assert.Equal(expectedAttributes, executionContext.HTMLAttributes); }
public async Task RunAsync_ProcessesAllTagHelpers() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var executableTagHelper1 = new ExecutableTagHelper(); var executableTagHelper2 = new ExecutableTagHelper(); // Act executionContext.Add(executableTagHelper1); executionContext.Add(executableTagHelper2); await runner.RunAsync(executionContext); // Assert Assert.True(executableTagHelper1.Processed); Assert.True(executableTagHelper2.Processed); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperRunner(); BeginContext(120, 2, true); WriteLiteral("\r\n"); EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", TagMode.SelfClosing, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper <Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>(); __tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper); #line 5 "TestFiles/Input/ModelExpressionTagHelper.cshtml" __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__model => __model.Now); #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); BeginContext(122, 24, false); await WriteTagHelperAsync(__tagHelperExecutionContext); EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); BeginContext(146, 2, true); WriteLiteral("\r\n"); EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", TagMode.SelfClosing, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper <Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>(); __tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper); #line 6 "TestFiles/Input/ModelExpressionTagHelper.cshtml" __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__model => Model); #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); BeginContext(148, 27, false); await WriteTagHelperAsync(__tagHelperExecutionContext); EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); }
public void Add_MaintainsMultipleTagHelpers() { // Arrange var executionContext = new TagHelperExecutionContext("p"); var tagHelper1 = new PTagHelper(); var tagHelper2 = new PTagHelper(); // Act executionContext.Add(tagHelper1); executionContext.Add(tagHelper2); // Assert var tagHelpers = executionContext.TagHelpers.ToArray(); Assert.Equal(2, tagHelpers.Length); Assert.Same(tagHelper1, tagHelpers[0]); Assert.Same(tagHelper2, tagHelpers[1]); }
public async Task RunAsync_AllowsModificationOfTagHelperOutput() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var executableTagHelper = new ExecutableTagHelper(); // Act executionContext.Add(executableTagHelper); executionContext.AddHtmlAttribute("class", "btn"); var output = await runner.RunAsync(executionContext); // Assert Assert.Equal("foo", output.TagName); Assert.Equal("somethingelse", output.Attributes["class"]); Assert.Equal("world", output.Attributes["hello"]); Assert.Equal(true, output.SelfClosing); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("")); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(35, 10, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); }
public void TagHelperExecutionContext_MaintainsAllAttributes() { // Arrange var executionContext = new TagHelperExecutionContext("p"); var expectedAttributes = new Dictionary <string, object> { { "class", "btn" }, { "something", true }, { "foo", "bar" } }; // Act executionContext.AddHtmlAttribute("class", "btn"); executionContext.AddTagHelperAttribute("something", true); executionContext.AddHtmlAttribute("foo", "bar"); // Assert Assert.Equal(expectedAttributes, executionContext.AllAttributes); }
public void AddHtmlAttribute_MaintainsHTMLAttributes() { // Arrange var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var expectedAttributes = new TagHelperAttributeList { { "class", "btn" }, { "foo", "bar" } }; // Act executionContext.AddHtmlAttribute("class", "btn"); executionContext.AddHtmlAttribute("foo", "bar"); // Assert Assert.Equal( expectedAttributes, executionContext.HTMLAttributes, CaseSensitiveTagHelperAttributeComparer.Default); }
public void ParentItems_SetsItemsProperty() { // Arrange var expectedItems = new Dictionary<object, object> { { "test-entry", 1234 } }; // Act var executionContext = new TagHelperExecutionContext( "p", selfClosing: false, items: expectedItems, uniqueId: string.Empty, executeChildContentAsync: async () => await Task.FromResult(result: true), startTagHelperWritingScope: () => { }, endTagHelperWritingScope: () => new DefaultTagHelperContent()); // Assert Assert.NotNull(executionContext.Items); Assert.Same(expectedItems, executionContext.Items); }
public void TagHelperExecutionContext_MaintainsAllAttributes() { // Arrange var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); var expectedAttributes = new TagHelperAttributeList { { "class", "btn" }, { "something", true }, { "foo", "bar" } }; // Act executionContext.AddHtmlAttribute("class", "btn"); executionContext.AddTagHelperAttribute("something", true); executionContext.AddHtmlAttribute("foo", "bar"); // Assert Assert.Equal( expectedAttributes, executionContext.AllAttributes, CaseSensitiveTagHelperAttributeComparer.Default); }
/// <summary> /// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s. /// </summary> /// <param name="executionContext">Contains information associated with running <see cref="ITagHelper"/>s. /// </param> /// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the /// <paramref name="executionContext"/>'s <see cref="ITagHelper"/>s.</returns> public async Task <TagHelperOutput> RunAsync([NotNull] TagHelperExecutionContext executionContext) { var tagHelperContext = new TagHelperContext( executionContext.AllAttributes, executionContext.Items, executionContext.UniqueId, executionContext.GetChildContentAsync); var tagHelperOutput = new TagHelperOutput( executionContext.TagName, executionContext.HTMLAttributes) { TagMode = executionContext.TagMode, }; var orderedTagHelpers = executionContext.TagHelpers.OrderBy(tagHelper => tagHelper.Order); foreach (var tagHelper in orderedTagHelpers) { await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput); } return(tagHelperOutput); }
public void ParentItems_SetsItemsProperty() { // Arrange var expectedItems = new Dictionary <object, object> { { "test-entry", 1234 } }; // Act var executionContext = new TagHelperExecutionContext( "p", selfClosing: false, items: expectedItems, uniqueId: string.Empty, executeChildContentAsync: async() => await Task.FromResult(result: true), startTagHelperWritingScope: () => { }, endTagHelperWritingScope: () => new DefaultTagHelperContent()); // Assert Assert.NotNull(executionContext.Items); Assert.Same(expectedItems, executionContext.Items); }
public void AddMinimizedHtmlAttribute_MaintainsHTMLAttributes() { // Arrange var executionContext = new TagHelperExecutionContext("input", selfClosing: true); var expectedAttributes = new TagHelperAttributeList { ["checked"] = new TagHelperAttribute { Name = "checked", Minimized = true }, ["visible"] = new TagHelperAttribute { Name = "visible", Minimized = true } }; // Act executionContext.AddMinimizedHtmlAttribute("checked"); executionContext.AddMinimizedHtmlAttribute("visible"); // Assert Assert.Equal( expectedAttributes, executionContext.HTMLAttributes, CaseSensitiveTagHelperAttributeComparer.Default); }
public async Task RunAsync_OrdersTagHelpers( int[] tagHelperOrders, int[] expectedTagHelperOrders) { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var processOrder = new List <int>(); foreach (var order in tagHelperOrders) { var orderedTagHelper = new OrderedTagHelper(order) { ProcessOrderTracker = processOrder }; executionContext.Add(orderedTagHelper); } // Act await runner.RunAsync(executionContext); // Assert Assert.Equal(expectedTagHelperOrders, processOrder); }
public async Task RunAsync_OrdersTagHelpers( int[] tagHelperOrders, int[] expectedTagHelperOrders) { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); var processOrder = new List<int>(); foreach (var order in tagHelperOrders) { var orderedTagHelper = new OrderedTagHelper(order) { ProcessOrderTracker = processOrder }; executionContext.Add(orderedTagHelper); } // Act await runner.RunAsync(executionContext); // Assert Assert.Equal(expectedTagHelperOrders, processOrder); }
public void AllAttributes_IgnoresCase(string originalName, string updatedName) { // Arrange var executionContext = new TagHelperExecutionContext("p", selfClosing: false); executionContext.AllAttributes[originalName] = false; // Act executionContext.AllAttributes[updatedName] = true; // Assert var attribute = Assert.Single(executionContext.AllAttributes); Assert.Equal(new KeyValuePair<string, object>(originalName, true), attribute); }
public void HtmlAttributes_IgnoresCase(string originalName, string updatedName) { // Arrange var executionContext = new TagHelperExecutionContext("p", selfClosing: false); executionContext.HTMLAttributes[originalName] = "hello"; // Act executionContext.HTMLAttributes[updatedName] = "something else"; // Assert var attribute = Assert.Single(executionContext.HTMLAttributes); Assert.Equal(new KeyValuePair<string, object>(originalName, "something else"), attribute); }
public async Task ExecuteChildContentAsync_IsNotMemoized() { // Arrange var childContentExecutionCount = 0; var executionContext = new TagHelperExecutionContext( "p", selfClosing: false, items: null, uniqueId: string.Empty, executeChildContentAsync: () => { childContentExecutionCount++; return Task.FromResult(result: true); }, startTagHelperWritingScope: () => { }, endTagHelperWritingScope: () => new DefaultTagHelperContent()); // Act await executionContext.ExecuteChildContentAsync(); await executionContext.ExecuteChildContentAsync(); await executionContext.ExecuteChildContentAsync(); // Assert Assert.Equal(3, childContentExecutionCount); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); Instrumentation.BeginContext(33, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); #line 3 "TagHelpersInSection.cshtml" var code = "some code"; #line default #line hidden Instrumentation.BeginContext(69, 4, true); WriteLiteral("\r\n\r\n"); Instrumentation.EndContext(); DefineSection("MySection", async(__razor_template_writer) => { Instrumentation.BeginContext(93, 21, true); WriteLiteralTo(__razor_template_writer, "\r\n <div>\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("mytaghelper", false, "test", async() => { Instrumentation.BeginContext(217, 52, true); WriteLiteral("\r\n In None ContentBehavior.\r\n "); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("nestedtaghelper", false, "test", async() => { Instrumentation.BeginContext(286, 26, true); WriteLiteral("Some buffered values with "); Instrumentation.EndContext(); Instrumentation.BeginContext(313, 4, false); #line 11 "TagHelpersInSection.cshtml" Write(code); #line default #line hidden Instrumentation.EndContext(); } , StartTagHelperWritingScope, EndTagHelperWritingScope); __NestedTagHelper = CreateTagHelper<NestedTagHelper>(); __tagHelperExecutionContext.Add(__NestedTagHelper); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(269, 66, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(335, 10, true); WriteLiteral("\r\n "); Instrumentation.EndContext(); } , StartTagHelperWritingScope, EndTagHelperWritingScope); __MyTagHelper = CreateTagHelper<MyTagHelper>(); __tagHelperExecutionContext.Add(__MyTagHelper); StartTagHelperWritingScope(); WriteLiteral("Current Time: "); #line 9 "TagHelpersInSection.cshtml" WriteLiteral(DateTime.Now); #line default #line hidden __tagHelperStringValueBuffer = EndTagHelperWritingScope(); __MyTagHelper.BoundProperty = __tagHelperStringValueBuffer.ToString(); __tagHelperExecutionContext.AddTagHelperAttribute("boundproperty", __MyTagHelper.BoundProperty); StartTagHelperWritingScope(); WriteLiteral("Current Time: "); #line 9 "TagHelpersInSection.cshtml" Write(DateTime.Now); #line default #line hidden __tagHelperStringValueBuffer = EndTagHelperWritingScope(); __tagHelperExecutionContext.AddHtmlAttribute("unboundproperty", Html.Raw(__tagHelperStringValueBuffer.ToString())); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(114, 245, false); await WriteTagHelperToAsync(__razor_template_writer, __tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(359, 14, true); WriteLiteralTo(__razor_template_writer, "\r\n </div>\r\n"); Instrumentation.EndContext(); } ); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { BeginContext(120, 2, true); WriteLiteral("\r\n"); EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", "test", async() => { } , StartWritingScope, EndWritingScope); __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper <Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>(); __tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper); #line 5 "TestFiles/Input/ModelExpressionTagHelper.cshtml" __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__model => __model.Now); #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GeneratePreContent()); if (__tagHelperExecutionContext.Output.ContentSet) { WriteLiteral(__tagHelperExecutionContext.Output.GenerateContent()); } else if (__tagHelperExecutionContext.ChildContentRetrieved) { WriteLiteral(__tagHelperExecutionContext.GetChildContentAsync().Result); } else { __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); } WriteLiteral(__tagHelperExecutionContext.Output.GeneratePostContent()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); BeginContext(146, 2, true); WriteLiteral("\r\n"); EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", "test", async() => { } , StartWritingScope, EndWritingScope); __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper = CreateTagHelper <Microsoft.AspNet.Mvc.Razor.InputTestTagHelper>(); __tagHelperExecutionContext.Add(__Microsoft_AspNet_Mvc_Razor_InputTestTagHelper); #line 6 "TestFiles/Input/ModelExpressionTagHelper.cshtml" __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For = CreateModelExpression(__model => Model); #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNet_Mvc_Razor_InputTestTagHelper.For); __tagHelperExecutionContext.Output = __tagHelperRunner.RunAsync(__tagHelperExecutionContext).Result; WriteLiteral(__tagHelperExecutionContext.Output.GenerateStartTag()); WriteLiteral(__tagHelperExecutionContext.Output.GeneratePreContent()); if (__tagHelperExecutionContext.Output.ContentSet) { WriteLiteral(__tagHelperExecutionContext.Output.GenerateContent()); } else if (__tagHelperExecutionContext.ChildContentRetrieved) { WriteLiteral(__tagHelperExecutionContext.GetChildContentAsync().Result); } else { __tagHelperExecutionContext.ExecuteChildContentAsync().Wait(); } WriteLiteral(__tagHelperExecutionContext.Output.GeneratePostContent()); WriteLiteral(__tagHelperExecutionContext.Output.GenerateEndTag()); __tagHelperExecutionContext = __tagHelperScopeManager.End(); }
public void Add_MaintainsMultipleTagHelpers() { // Arrange var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var tagHelper1 = new PTagHelper(); var tagHelper2 = new PTagHelper(); // Act executionContext.Add(tagHelper1); executionContext.Add(tagHelper2); // Assert var tagHelpers = executionContext.TagHelpers.ToArray(); Assert.Equal(2, tagHelpers.Length); Assert.Same(tagHelper1, tagHelpers[0]); Assert.Same(tagHelper2, tagHelpers[1]); }
public void Add_MaintainsTagHelpers() { // Arrange var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); var tagHelper = new PTagHelper(); // Act executionContext.Add(tagHelper); // Assert var singleTagHelper = Assert.Single(executionContext.TagHelpers); Assert.Same(tagHelper, singleTagHelper); }
/// <summary> /// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s. /// </summary> /// <param name="context">Contains information associated with running <see cref="ITagHelper"/>s.</param> /// <param name="bufferedBody">Contains the buffered content of the current HTML tag.</param> /// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the /// <paramref name="context"/>'s <see cref="ITagHelper"/>s.</returns> public async Task <TagHelperOutput> RunAsync([NotNull] TagHelperExecutionContext context, [NotNull] TextWriter bufferedBody) { return(await RunAsyncCore(context, bufferedBody.ToString())); }
public void TagHelperExecutionContext_MaintainsAllAttributes() { // Arrange var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var expectedAttributes = new Dictionary<string, object> { { "class", "btn" }, { "something", true }, { "foo", "bar" } }; // Act executionContext.AddHtmlAttribute("class", "btn"); executionContext.AddTagHelperAttribute("something", true); executionContext.AddHtmlAttribute("foo", "bar"); // Assert Assert.Equal(expectedAttributes, executionContext.AllAttributes); }
public void Add_MaintainsTagHelpers() { // Arrange var executionContext = new TagHelperExecutionContext("p", selfClosing: false); var tagHelper = new PTagHelper(); // Act executionContext.Add(tagHelper); // Assert var singleTagHelper = Assert.Single(executionContext.TagHelpers); Assert.Same(tagHelper, singleTagHelper); }
public async Task GetChildContentAsync_CanExecuteChildrenMoreThanOnce() { // Arrange var executionCount = 0; var executionContext = new TagHelperExecutionContext( "p", tagMode: TagMode.StartTagAndEndTag, items: new Dictionary<object, object>(), uniqueId: string.Empty, executeChildContentAsync: () => { executionCount++; return Task.FromResult(result: true); }, startTagHelperWritingScope: () => { }, endTagHelperWritingScope: () => new DefaultTagHelperContent()); // Act await executionContext.GetChildContentAsync(useCachedResult: false); await executionContext.GetChildContentAsync(useCachedResult: false); // Assert Assert.Equal(2, executionCount); }
public void AddMinimizedHtmlAttribute_MaintainsHTMLAttributes() { // Arrange var executionContext = new TagHelperExecutionContext("input", tagMode: TagMode.StartTagOnly); var expectedAttributes = new TagHelperAttributeList { ["checked"] = new TagHelperAttribute { Name = "checked", Minimized = true }, ["visible"] = new TagHelperAttribute { Name = "visible", Minimized = true } }; // Act executionContext.AddMinimizedHtmlAttribute("checked"); executionContext.AddMinimizedHtmlAttribute("visible"); // Assert Assert.Equal( expectedAttributes, executionContext.HTMLAttributes, CaseSensitiveTagHelperAttributeComparer.Default); }
/// <summary> /// Calls the <see cref="ITagHelper.ProcessAsync"/> method on <see cref="ITagHelper"/>s. /// </summary> /// <param name="context">Contains information associated with running <see cref="ITagHelper"/>s.</param> /// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the /// <paramref name="context"/>'s <see cref="ITagHelper"/>s.</returns> public async Task <TagHelperOutput> RunAsync([NotNull] TagHelperExecutionContext context) { return(await RunAsyncCore(context, string.Empty)); }
public async Task GetChildContentAsync_ReturnsNewObjectEveryTimeItIsCalled() { // Arrange var defaultTagHelperContent = new DefaultTagHelperContent(); var executionContext = new TagHelperExecutionContext( "p", selfClosing: false, items: null, uniqueId: string.Empty, executeChildContentAsync: () => { return Task.FromResult(result: true); }, startTagHelperWritingScope: () => { }, endTagHelperWritingScope: () => defaultTagHelperContent); // Act var content1 = await executionContext.GetChildContentAsync(); content1.Append("Hello"); var content2 = await executionContext.GetChildContentAsync(); content2.Append("World!"); // Assert Assert.NotSame(content1, content2); Assert.Empty((await executionContext.GetChildContentAsync()).GetContent()); }
public void AddMinimizedHtmlAttribute_MaintainsHTMLAttributes_SomeMinimized() { // Arrange var executionContext = new TagHelperExecutionContext("input", tagMode: TagMode.SelfClosing); var expectedAttributes = new TagHelperAttributeList { { "class", "btn" }, { "foo", "bar" } }; expectedAttributes.Add(new TagHelperAttribute { Name = "checked", Minimized = true }); expectedAttributes.Add(new TagHelperAttribute { Name = "visible", Minimized = true }); // Act executionContext.AddHtmlAttribute("class", "btn"); executionContext.AddHtmlAttribute("foo", "bar"); executionContext.AddMinimizedHtmlAttribute("checked"); executionContext.AddMinimizedHtmlAttribute("visible"); // Assert Assert.Equal( expectedAttributes, executionContext.HTMLAttributes, CaseSensitiveTagHelperAttributeComparer.Default); }
#pragma warning disable 1998 public override async Task ExecuteAsync() { __tagHelperRunner = __tagHelperRunner ?? new TagHelperRunner(); #line 2 "TransitionsInTagHelperAttributes.cshtml" var @class = "container-fluid"; var @int = 1; #line default #line hidden Instrumentation.BeginContext(97, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => { Instrumentation.BeginContext(128, 11, true); WriteLiteral("Body of Tag"); Instrumentation.EndContext(); } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); AddHtmlAttributeValues("class", __tagHelperExecutionContext, Tuple.Create(Tuple.Create("", 109), Tuple.Create<System.Object, System.Int32>(new Template((__razor_attribute_value_writer) => { } ), 109), false)); #line 7 "TransitionsInTagHelperAttributes.cshtml" __PTagHelper.Age = 1337; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(99, 44, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(143, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); AddHtmlAttributeValues("class", __tagHelperExecutionContext, Tuple.Create(Tuple.Create("", 155), Tuple.Create<System.Object, System.Int32>(@class, 155), false)); #line 8 "TransitionsInTagHelperAttributes.cshtml" __PTagHelper.Age = 42; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(145, 34, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(179, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("test")); #line 9 "TransitionsInTagHelperAttributes.cshtml" __PTagHelper.Age = 42 + @int; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(181, 36, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(217, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("test")); #line 10 "TransitionsInTagHelperAttributes.cshtml" __PTagHelper.Age = int; #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(219, 31, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(250, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); __tagHelperExecutionContext.AddHtmlAttribute("class", Html.Raw("test")); #line 11 "TransitionsInTagHelperAttributes.cshtml" __PTagHelper.Age = (@int); #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(252, 34, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(286, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("p", TagMode.StartTagAndEndTag, "test", async() => { } , StartTagHelperWritingScope, EndTagHelperWritingScope); __PTagHelper = CreateTagHelper<PTagHelper>(); __tagHelperExecutionContext.Add(__PTagHelper); AddHtmlAttributeValues("class", __tagHelperExecutionContext, Tuple.Create(Tuple.Create("", 298), Tuple.Create("custom-", 298), true), Tuple.Create(Tuple.Create("", 305), Tuple.Create<System.Object, System.Int32>(@class, 305), false)); #line 12 "TransitionsInTagHelperAttributes.cshtml" __PTagHelper.Age = 4 * @(@int + 2); #line default #line hidden __tagHelperExecutionContext.AddTagHelperAttribute("age", __PTagHelper.Age); __tagHelperExecutionContext.Output = await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); Instrumentation.BeginContext(288, 54, false); await WriteTagHelperAsync(__tagHelperExecutionContext); Instrumentation.EndContext(); __tagHelperExecutionContext = __tagHelperScopeManager.End(); Instrumentation.BeginContext(342, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); }