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")); expectedAttributes.Add(new TagHelperAttribute(name: "visible")); // Act executionContext.AddHtmlAttribute("class", "btn"); executionContext.AddHtmlAttribute("foo", "bar"); executionContext.AddMinimizedHtmlAttribute("checked"); executionContext.AddMinimizedHtmlAttribute("visible"); var output = executionContext.Output; // Assert Assert.Equal( expectedAttributes, output.Attributes, CaseSensitiveTagHelperAttributeComparer.Default); }
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.AddMinimizedHtmlAttribute("something"); // Act - 1 executionContext.Reinitialize( updatedTagName, updatedTagMode, items: new Dictionary <object, object>(), uniqueId: string.Empty, executeChildContentAsync: updatedExecuteChildContentAsync); executionContext.AddMinimizedHtmlAttribute("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(callCount, 0); Assert.Equal(updatedCallCount, 1); }
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.AddMinimizedHtmlAttribute("something"); // Act executionContext.Reinitialize( tagName, tagMode, updatedItems, updatedUniqueId, executeChildContentAsync); executionContext.AddMinimizedHtmlAttribute("Another attribute"); // Assert var context = executionContext.Context; var attribute = Assert.Single(context.AllAttributes); Assert.Equal(attribute.Name, "Another attribute"); Assert.Equal(updatedUniqueId, context.UniqueId); Assert.Same(updatedItems, context.Items); }
public void AddMinimizedHtmlAttribute_MaintainsHtmlAttributes() { // Arrange var executionContext = new TagHelperExecutionContext("input", tagMode: TagMode.StartTagOnly); var expectedAttributes = new TagHelperAttributeList { new TagHelperAttribute("checked"), new TagHelperAttribute("visible"), }; // Act executionContext.AddMinimizedHtmlAttribute("checked"); executionContext.AddMinimizedHtmlAttribute("visible"); var output = executionContext.Output; // Assert Assert.Equal( expectedAttributes, output.Attributes, CaseSensitiveTagHelperAttributeComparer.Default); }