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); }
public void Add_MaintainsMultipleTagHelpers() { // Arrange var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); 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); }
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, HtmlAttributeValueStyle.DoubleQuotes); await runner.RunAsync(executionContext); // Assert Assert.Equal("True", executionContext.Output.Attributes["foo"].Value); }
public async Task RunAsync_ConfiguresTagHelperContextWithExecutionContextsItems() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); 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 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, HtmlAttributeValueStyle.DoubleQuotes); // Act await runner.RunAsync(executionContext); // Assert Assert.Equal(tagMode, executionContext.Output.TagMode); }
public async Task RunAsync_AllowsModificationOfTagHelperOutput() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); var executableTagHelper = new ExecutableTagHelper(); // Act executionContext.Add(executableTagHelper); executionContext.AddHtmlAttribute("class", "btn", HtmlAttributeValueStyle.DoubleQuotes); await runner.RunAsync(executionContext); // Assert var output = executionContext.Output; Assert.Equal("foo", output.TagName); Assert.Equal("somethingelse", output.Attributes["class"].Value); Assert.Equal("world", output.Attributes["hello"].Value); Assert.Equal(TagMode.SelfClosing, output.TagMode); }
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 Add_MaintainsMultipleTagHelpers() { // Arrange var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); 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); }
public async Task RunAsync_ProcessesAllTagHelpers() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); 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); }
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 async Task RunAsync_ConfiguresTagHelperContextWithExecutionContextsItems() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); 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 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, HtmlAttributeValueStyle.DoubleQuotes); await runner.RunAsync(executionContext); // Assert Assert.Equal("True", executionContext.Output.Attributes["foo"].Value); }
public async Task RunAsync_AllowsModificationOfTagHelperOutput() { // Arrange var runner = new TagHelperRunner(); var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag); var executableTagHelper = new ExecutableTagHelper(); // Act executionContext.Add(executableTagHelper); executionContext.AddHtmlAttribute("class", "btn", HtmlAttributeValueStyle.DoubleQuotes); await runner.RunAsync(executionContext); // Assert var output = executionContext.Output; Assert.Equal("foo", output.TagName); Assert.Equal("somethingelse", output.Attributes["class"].Value); Assert.Equal("world", output.Attributes["hello"].Value); Assert.Equal(TagMode.SelfClosing, output.TagMode); }
public async Task Process_AddsHiddenInputTag_FromEndOfFormContent_WithCachedBody( List<TagBuilder> tagBuilderList, string expectedOutput) { // Arrange var viewContext = new ViewContext(); var runner = new TagHelperRunner(); var tagHelperExecutionContext = new TagHelperExecutionContext( "form", TagMode.StartTagAndEndTag, items: new Dictionary<object, object>(), uniqueId: string.Empty, executeChildContentAsync: () => { foreach (var item in tagBuilderList) { viewContext.FormContext.EndOfFormContent.Add(item); } return Task.FromResult(true); }, startTagHelperWritingScope: _ => { }, endTagHelperWritingScope: () => new DefaultTagHelperContent()); // This TagHelper will pre-execute the child content forcing the body to be cached. tagHelperExecutionContext.Add(new ChildContentInvoker()); tagHelperExecutionContext.Add(new RenderAtEndOfFormTagHelper { ViewContext = viewContext }); // Act await runner.RunAsync(tagHelperExecutionContext); // Assert Assert.Equal(expectedOutput, tagHelperExecutionContext.Output.PostContent.GetContent()); }
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, HtmlAttributeValueStyle.DoubleQuotes); // Act await runner.RunAsync(executionContext); // Assert Assert.Equal(tagMode, executionContext.Output.TagMode); }