コード例 #1
0
        public void Should_overwrite_existing_attributes_for_outline_style()
        {
            // Given
            var context = MakeTagHelperContext(
                "heroicon-outline",
                new TagHelperAttributeList
            {
                { "fill", "blue" },
                { "stroke", "blue" },
                { "viewbox", "0 0 1 1" },
            });
            var output = MakeTagHelperOutput(
                "heroicon-outline",
                new TagHelperAttributeList
            {
                { "fill", "blue" },
                { "stroke", "blue" },
                { "viewbox", "0 0 1 1" },
            });

            var options = Options.Create(new HeroiconOptions());
            var helper  = new IconTagHelper(options)
            {
                Icon = IconSymbol.Bell,
            };

            // When
            helper.Process(context, output);

            // Then
            AssertAttributeValue(output.Attributes, "fill", "none");
            AssertAttributeValue(output.Attributes, "stroke", "currentColor");
            AssertAttributeValue(output.Attributes, "viewbox", "0 0 24 24");
        }
コード例 #2
0
        public void Should_apply_custom_attributes(string attributeName, string attributeValue)
        {
            // Given
            var context = MakeTagHelperContext(
                "heroicon-solid",
                new TagHelperAttributeList
            {
                { attributeName, attributeValue },
            });
            var output = MakeTagHelperOutput(
                "heroicon-solid",
                new TagHelperAttributeList
            {
                { attributeName, attributeValue },
            });

            var options = Options.Create(new HeroiconOptions());
            var helper  = new IconTagHelper(options)
            {
                Icon = IconSymbol.Bell,
            };

            // When
            helper.Process(context, output);

            // Then
            AssertAttributeValue(output.Attributes, attributeName, attributeValue);
        }
コード例 #3
0
ファイル: IconTagHelperTest.cs プロジェクト: thinhils/Util
        /// <summary>
        /// 获取结果
        /// </summary>
        private string GetResult(IconTagHelper icon, TagHelperAttributeList contextAttributes = null, TagHelperAttributeList outputAttributes = null, TagHelperContent content = null)
        {
            var context = new TagHelperContext("", contextAttributes ?? new TagHelperAttributeList(), new Dictionary <object, object>(), Id.Guid());
            var output  = new TagHelperOutput("", outputAttributes ?? new TagHelperAttributeList(), (useCachedResult, encoder) => Task.FromResult(content ?? new DefaultTagHelperContent()));

            icon.Process(context, output);
            var writer = new StringWriter();

            output.WriteTo(writer, HtmlEncoder.Default);
            var result = writer.ToString();

            _output.WriteLine(result);
            return(result);
        }
コード例 #4
0
        public void Should_set_svg_attributes()
        {
            // Given
            var context = MakeTagHelperContext("heroicon-outline");
            var output  = MakeTagHelperOutput("heroicon-outline");

            var options = Options.Create(new HeroiconOptions());
            var helper  = new IconTagHelper(options);

            // When
            helper.Process(context, output);

            // Then
            output.TagMode.ShouldBe(TagMode.StartTagAndEndTag);
            output.TagName.ShouldBe("svg");
            AssertAttributeValue(output.Attributes, "viewbox", "0 0 24 24");
        }
コード例 #5
0
        public void Should_include_html_comment_when_IncludeComments_is_true()
        {
            // Given
            var context = MakeTagHelperContext("heroicon-outline");
            var output  = MakeTagHelperOutput("heroicon-outline");

            var options = Options.Create(new HeroiconOptions
            {
                IncludeComments = true,
            });
            var helper = new IconTagHelper(options)
            {
                Icon = IconSymbol.Bell,
            };

            // When
            helper.Process(context, output);

            // Then
            output.PreElement.GetContent().ShouldBe("<!-- Heroicon name: outline bell -->");
        }
コード例 #6
0
        public void Should_output_outline_bell_icon(string tagName)
        {
            // Given
            var context = MakeTagHelperContext(tagName);
            var output  = MakeTagHelperOutput(tagName);

            var options = Options.Create(new HeroiconOptions());
            var helper  = new IconTagHelper(options)
            {
                Icon = IconSymbol.Bell,
            };

            // When
            helper.Process(context, output);

            // Then
            AssertAttributeValue(output.Attributes, "fill", "none");
            AssertAttributeValue(output.Attributes, "stroke", "currentColor");
            AssertAttributeValue(output.Attributes, "stroke-width", "2");
            AssertAttributeValue(output.Attributes, "viewbox", "0 0 24 24");
            output.Content.GetContent().ShouldBe("<path stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9\"/>");
        }
コード例 #7
0
        public void Should_output_solid_bell_icon(string tagName)
        {
            // Given
            var context = MakeTagHelperContext(tagName);
            var output  = MakeTagHelperOutput(tagName);

            var options = Options.Create(new HeroiconOptions());
            var helper  = new IconTagHelper(options)
            {
                Icon = IconSymbol.Bell,
            };

            // When
            helper.Process(context, output);

            // Then
            AssertAttributeValue(output.Attributes, "fill", "currentColor");
            AssertAttributeValue(output.Attributes, "viewbox", "0 0 20 20");
            output.Attributes.ShouldNotContain(a => a.Name == "stroke");
            output.Attributes.ShouldNotContain(a => a.Name == "stroke-width");
            output.Content.GetContent().ShouldBe("<path d=\"M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zM10 18a3 3 0 01-3-3h6a3 3 0 01-3 3z\"/>");
        }