public async Task ExecutionContext_Reinitialize_UpdatesTagHelperOutputAsExpected() { // Arrange var tagName = "div"; var tagMode = TagMode.StartTagOnly; var callCount = 0; Func <Task> executeChildContentAsync = () => { callCount++; return(Task.FromResult(true)); }; Action <HtmlEncoder> startTagHelperWritingScope = _ => { }; Func <TagHelperContent> endTagHelperWritingScope = () => null; var executionContext = new TagHelperExecutionContext( tagName, tagMode, items: new Dictionary <object, object>(), uniqueId: string.Empty, executeChildContentAsync: executeChildContentAsync, startTagHelperWritingScope: startTagHelperWritingScope, endTagHelperWritingScope: endTagHelperWritingScope); var updatedTagName = "p"; var updatedTagMode = TagMode.SelfClosing; var updatedCallCount = 0; Func <Task> updatedExecuteChildContentAsync = () => { updatedCallCount++; return(Task.FromResult(true)); }; executionContext.AddHtmlAttribute(new TagHelperAttribute("something")); // Act - 1 executionContext.Reinitialize( updatedTagName, updatedTagMode, items: new Dictionary <object, object>(), uniqueId: string.Empty, executeChildContentAsync: updatedExecuteChildContentAsync); executionContext.AddHtmlAttribute(new TagHelperAttribute("Another attribute")); // Assert - 1 var output = executionContext.Output; Assert.Equal(updatedTagName, output.TagName); Assert.Equal(updatedTagMode, output.TagMode); var attribute = Assert.Single(output.Attributes); Assert.Equal("Another attribute", attribute.Name); // Act - 2 await output.GetChildContentAsync(); // Assert - 2 Assert.Equal(0, callCount); Assert.Equal(1, updatedCallCount); }
public void ExecutionContext_Reinitialize_UpdatesTagHelperContextAsExpected() { // Arrange var tagName = "div"; var tagMode = TagMode.StartTagOnly; var items = new Dictionary <object, object>(); var uniqueId = "some unique id"; var callCount = 0; Func <Task> executeChildContentAsync = () => { callCount++; return(Task.FromResult(true)); }; Action <HtmlEncoder> startWritingScope = _ => { }; Func <TagHelperContent> endWritingScope = () => null; var executionContext = new TagHelperExecutionContext( tagName, tagMode, items, uniqueId, executeChildContentAsync, startWritingScope, endWritingScope); var updatedItems = new Dictionary <object, object>(); var updatedUniqueId = "another unique id"; executionContext.AddHtmlAttribute(new TagHelperAttribute("something")); // Act executionContext.Reinitialize( tagName, tagMode, updatedItems, updatedUniqueId, executeChildContentAsync); executionContext.AddHtmlAttribute(new TagHelperAttribute("Another attribute")); // Assert var context = executionContext.Context; var attribute = Assert.Single(context.AllAttributes); Assert.Equal(tagName, context.TagName); Assert.Equal("Another attribute", attribute.Name); Assert.Equal(updatedUniqueId, context.UniqueId); Assert.Same(updatedItems, context.Items); }