Пример #1
0
        public FormInputTagHelperTests()
        {
            TagHelperContent content  = new DefaultTagHelperContent();
            ModelMetadata    metadata = Substitute.For <ModelMetadata>(ModelMetadataIdentity.ForType(typeof(String)));

            context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <Object, Object>(), "test");
            output  = new TagHelperOutput("input", new TagHelperAttributeList(), (_, __) => Task.FromResult(content));
            helper  = new FormInputTagHelper()
            {
                For = new ModelExpression("IsChecked", new ModelExplorer(new EmptyModelMetadataProvider(), metadata, null))
            };
        }
Пример #2
0
        public void Process_Boolean()
        {
            ModelMetadata      metadata = Substitute.For <ModelMetadata>(ModelMetadataIdentity.ForType(typeof(Boolean)));
            TagHelperOutput    output   = new TagHelperOutput("input", new TagHelperAttributeList(), (useCache, encoder) => null);
            FormInputTagHelper helper   = new FormInputTagHelper {
                For = new ModelExpression("IsChecked", new ModelExplorer(new EmptyModelMetadataProvider(), metadata, null))
            };

            helper.Process(null, output);

            Assert.Empty(output.Attributes);
            Assert.Empty(output.Content.GetContent());
        }
Пример #3
0
        public void Process_Input()
        {
            ModelMetadata      metadata = Substitute.For <ModelMetadata>(ModelMetadataIdentity.ForType(typeof(String)));
            TagHelperOutput    output   = new TagHelperOutput("input", new TagHelperAttributeList(), (useCache, encoder) => null);
            FormInputTagHelper helper   = new FormInputTagHelper {
                For = new ModelExpression("IsChecked", new ModelExplorer(new EmptyModelMetadataProvider(), metadata, null))
            };

            helper.Process(null, output);

            Assert.Equal(2, output.Attributes.Count);
            Assert.Empty(output.Content.GetContent());
            Assert.Equal("off", output.Attributes["autocomplete"].Value);
            Assert.Equal("form-control", output.Attributes["class"].Value);
        }
        public void Process_Class(String value, String expectedValue)
        {
            Task <TagHelperContent> content  = Task.FromResult <TagHelperContent>(new DefaultTagHelperContent());
            ModelMetadata           metadata = Substitute.For <ModelMetadata>(ModelMetadataIdentity.ForType(typeof(String)));
            TagHelperOutput         output   = new TagHelperOutput("input", new TagHelperAttributeList(), (_, __) => content);
            FormInputTagHelper      helper   = new FormInputTagHelper {
                For = new ModelExpression("IsChecked", new ModelExplorer(new EmptyModelMetadataProvider(), metadata, null))
            };

            output.Attributes.Add("class", value);

            helper.Process(null, output);

            Assert.Equal(2, output.Attributes.Count);
            Assert.Empty(output.Content.GetContent());
            Assert.Equal("off", output.Attributes["autocomplete"].Value);
            Assert.Equal(expectedValue, output.Attributes["class"].Value);
        }