public async Task ProcessAsync_SetsHintOnContext()
        {
            // Arrange
            var radiosItemContext = new RadiosItemContext();

            var context = new TagHelperContext(
                tagName: "govuk-radios-item-hint",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(RadiosItemContext), radiosItemContext }
            },
                uniqueId: "test");

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

            var tagHelper = new RadiosItemHintTagHelper();

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

            // Assert
            Assert.Equal("Hint", radiosItemContext.Hint?.Content?.RenderToString());
        }
Exemplo n.º 2
0
        public async Task ProcessAsync_AddItemsToContext()
        {
            // Arrange
            var itemContext = new RadiosItemContext();

            var context = new TagHelperContext(
                tagName: "govuk-radios-item-conditional",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(RadiosItemContext), itemContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-radios-item-conditional",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.AppendHtml(new HtmlString("Conditional"));
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new RadiosItemConditionalTagHelper();

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

            // Assert
            Assert.Equal("Conditional", itemContext.Conditional?.content.AsString());
        }
        public void SetHint_SetsHintOnContext()
        {
            // Arrange
            var context = new RadiosItemContext();

            // Act
            context.SetHint(attributes: null, content: new HtmlString("Hint"));

            // Assert
            Assert.Equal("Hint", context.Hint?.Content?.ToString());
        }
        public void SetConditional_SetsConditionalOnContext()
        {
            // Arrange
            var context = new RadiosItemContext();

            // Act
            context.SetConditional(attributes: null, content: new HtmlString("Conditional"));

            // Assert
            Assert.Equal("Conditional", context.Conditional?.Content?.ToString());
        }
        public void SetHint_AlreadyGotHint_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new RadiosItemContext();

            context.SetHint(attributes: null, content: new HtmlString("Existing hint"));

            // Act
            var ex = Record.Exception(() => context.SetHint(attributes: null, content: new HtmlString("Hint")));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal <object>("Only one <govuk-radios-item-hint> element is permitted within each <govuk-radios-item>.", ex.Message);
        }
        public void SetHint_AlreadyGotConditional_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new RadiosItemContext();

            context.SetConditional(attributes: null, content: new HtmlString("Existing conditional"));

            // Act
            var ex = Record.Exception(() => context.SetHint(attributes: null, content: new HtmlString("Hint")));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal <object>("<govuk-radios-item-hint> must be specified before <govuk-radios-item-conditional>.", ex.Message);
        }