Exemplo n.º 1
0
        public async Task ProcessAsync_GeneratesExpectedOutput()
        {
            // Arrange
            var context = new TagHelperContext(
                tagName: "govuk-hint",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>(),
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-hint",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Hint text");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new HintTagHelper(new DefaultGovUkHtmlGenerator());

            // Act
            await tagHelper.ProcessAsync(context, output);

            // Assert
            var html = output.AsString();

            Assert.Equal("<span class=\"govuk-hint\">Hint text</span>", html);
        }
Exemplo n.º 2
0
        public async Task ProcessAsync_WithIdSpecifiedIncludesIdInOutput()
        {
            // Arrange
            var context = new TagHelperContext(
                tagName: "govuk-hint",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>(),
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-hint",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Hint text");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new HintTagHelper(new DefaultGovUkHtmlGenerator())
            {
                Id = "some-id"
            };

            // Act
            await tagHelper.ProcessAsync(context, output);

            // Assert
            Assert.Equal("some-id", output.Attributes["id"].Value);
        }
        public async Task WhenHintTagHelperCalled_ThenCorrectClassCalled()
        {
            var tagHelper = Substitute.For <IMockViewComponentHelper>();

            var componentTag = new HintTagHelper(tagHelper);

            componentTag.HintText        = "HintText";
            componentTag.AdditionalClass = "AdditionalClass";
            componentTag.Id = "Id";

            await ViewComponentTestHelper.CallTagHelper("Hint", tagHelper, componentTag);
        }