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.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 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(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.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);
        }
        public void AddHtmlAttribute_MaintainsMinimizedHtmlAttributes()
        {
            // Arrange
            var executionContext   = new TagHelperExecutionContext("input", tagMode: TagMode.StartTagOnly);
            var expectedAttributes = new TagHelperAttributeList
            {
                new TagHelperAttribute("checked"),
                new TagHelperAttribute("visible"),
            };

            // Act
            executionContext.AddHtmlAttribute(new TagHelperAttribute("checked"));
            executionContext.AddHtmlAttribute(new TagHelperAttribute("visible"));
            var output = executionContext.Output;

            // Assert
            Assert.Equal(
                expectedAttributes,
                output.Attributes,
                CaseSensitiveTagHelperAttributeComparer.Default);
        }
        public void AddHtmlAttribute_MaintainsHtmlAttributes()
        {
            // Arrange
            var executionContext   = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag);
            var expectedAttributes = new TagHelperAttributeList
            {
                { "class", "btn" },
                { "foo", "bar" }
            };

            // Act
            executionContext.AddHtmlAttribute("class", "btn");
            executionContext.AddHtmlAttribute("foo", "bar");
            var output = executionContext.Output;

            // Assert
            Assert.Equal(
                expectedAttributes,
                output.Attributes,
                CaseSensitiveTagHelperAttributeComparer.Default);
        }
        public void AddHtmlAttribute_MaintainsHtmlAttributes_VariousStyles()
        {
            // Arrange
            var executionContext   = new TagHelperExecutionContext("input", tagMode: TagMode.SelfClosing);
            var expectedAttributes = new TagHelperAttributeList
            {
                { "class", "btn" },
                { "foo", "bar" }
            };

            expectedAttributes.Add(new TagHelperAttribute("valid", "true", HtmlAttributeValueStyle.NoQuotes));
            expectedAttributes.Add(new TagHelperAttribute("type", "text", HtmlAttributeValueStyle.SingleQuotes));
            expectedAttributes.Add(new TagHelperAttribute(name: "checked"));
            expectedAttributes.Add(new TagHelperAttribute(name: "visible"));

            // Act
            executionContext.AddHtmlAttribute("class", "btn", HtmlAttributeValueStyle.DoubleQuotes);
            executionContext.AddHtmlAttribute("foo", "bar", HtmlAttributeValueStyle.DoubleQuotes);
            executionContext.AddHtmlAttribute("valid", "true", HtmlAttributeValueStyle.NoQuotes);
            executionContext.AddHtmlAttribute("type", "text", HtmlAttributeValueStyle.SingleQuotes);
            executionContext.AddHtmlAttribute(new TagHelperAttribute("checked"));
            executionContext.AddHtmlAttribute(new TagHelperAttribute("visible"));
            var output = executionContext.Output;

            // Assert
            Assert.Equal(
                expectedAttributes,
                output.Attributes,
                CaseSensitiveTagHelperAttributeComparer.Default);
        }
        public void AddHtmlAttribute_MaintainsHtmlAttributes()
        {
            // Arrange
            var executionContext   = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag);
            var expectedAttributes = new TagHelperAttributeList
            {
                { "class", "btn" },
            };

            expectedAttributes.Add(new TagHelperAttribute("type", "text", HtmlAttributeValueStyle.SingleQuotes));

            // Act
            executionContext.AddHtmlAttribute("class", "btn", HtmlAttributeValueStyle.DoubleQuotes);
            executionContext.AddHtmlAttribute("type", "text", HtmlAttributeValueStyle.SingleQuotes);
            var output = executionContext.Output;

            // Assert
            Assert.Equal(
                expectedAttributes,
                output.Attributes,
                CaseSensitiveTagHelperAttributeComparer.Default);
        }
        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");
            var context = executionContext.Context;

            // Assert
            Assert.Equal(
                expectedAttributes,
                context.AllAttributes,
                CaseSensitiveTagHelperAttributeComparer.Default);
        }
Exemple #10
0
        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 void TagHelperExecutionContext_MaintainsAllAttributes()
        {
            // Arrange
            var executionContext = new TagHelperExecutionContext("p", TagMode.StartTagAndEndTag);
            var expectedAttributes = new TagHelperAttributeList
            {
                { "class", "btn" },
            };
            expectedAttributes.Add(new TagHelperAttribute("something", true, HtmlAttributeValueStyle.SingleQuotes));
            expectedAttributes.Add(new TagHelperAttribute("type", "text", HtmlAttributeValueStyle.NoQuotes));

            // Act
            executionContext.AddHtmlAttribute("class", "btn", HtmlAttributeValueStyle.DoubleQuotes);
            executionContext.AddTagHelperAttribute("something", true, HtmlAttributeValueStyle.SingleQuotes);
            executionContext.AddHtmlAttribute("type", "text", HtmlAttributeValueStyle.NoQuotes);
            var context = executionContext.Context;

            // Assert
            Assert.Equal(
                expectedAttributes,
                context.AllAttributes,
                CaseSensitiveTagHelperAttributeComparer.Default);
        }
        public void AddHtmlAttribute_MaintainsHtmlAttributes_VariousStyles()
        {
            // Arrange
            var executionContext = new TagHelperExecutionContext("input", tagMode: TagMode.SelfClosing);
            var expectedAttributes = new TagHelperAttributeList
            {
                { "class", "btn" },
                { "foo", "bar" }
            };
            expectedAttributes.Add(new TagHelperAttribute("valid", "true", HtmlAttributeValueStyle.NoQuotes));
            expectedAttributes.Add(new TagHelperAttribute("type", "text", HtmlAttributeValueStyle.SingleQuotes));
            expectedAttributes.Add(new TagHelperAttribute(name: "checked"));
            expectedAttributes.Add(new TagHelperAttribute(name: "visible"));

            // Act
            executionContext.AddHtmlAttribute("class", "btn", HtmlAttributeValueStyle.DoubleQuotes);
            executionContext.AddHtmlAttribute("foo", "bar", HtmlAttributeValueStyle.DoubleQuotes);
            executionContext.AddHtmlAttribute("valid", "true", HtmlAttributeValueStyle.NoQuotes);
            executionContext.AddHtmlAttribute("type", "text", HtmlAttributeValueStyle.SingleQuotes);
            executionContext.AddHtmlAttribute(new TagHelperAttribute("checked"));
            executionContext.AddHtmlAttribute(new TagHelperAttribute("visible"));
            var output = executionContext.Output;

            // Assert
            Assert.Equal(
                expectedAttributes,
                output.Attributes,
                CaseSensitiveTagHelperAttributeComparer.Default);
        }
        public void AddHtmlAttribute_MaintainsMinimizedHtmlAttributes()
        {
            // Arrange
            var executionContext = new TagHelperExecutionContext("input", tagMode: TagMode.StartTagOnly);
            var expectedAttributes = new TagHelperAttributeList
            {
                new TagHelperAttribute("checked"),
                new TagHelperAttribute("visible"),
            };

            // Act
            executionContext.AddHtmlAttribute(new TagHelperAttribute("checked"));
            executionContext.AddHtmlAttribute(new TagHelperAttribute("visible"));
            var output = executionContext.Output;

            // Assert
            Assert.Equal(
                expectedAttributes,
                output.Attributes,
                CaseSensitiveTagHelperAttributeComparer.Default);
        }
        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(attribute.Name, "Another attribute");
            Assert.Equal(updatedUniqueId, context.UniqueId);
            Assert.Same(updatedItems, context.Items);
        }
Exemple #15
0
        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);
        }