Ejemplo n.º 1
0
        public async Task ProcessAsync_SetsConditionalOnContext()
        {
            // Arrange
            var checkboxesItemContext = new CheckboxesItemContext();

            var context = new TagHelperContext(
                tagName: "govuk-checkboxes-item-Conditional",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(CheckboxesItemContext), checkboxesItemContext }
            },
                uniqueId: "test");

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

            var tagHelper = new CheckboxesItemConditionalTagHelper();

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

            // Assert
            Assert.Equal("Conditional", checkboxesItemContext.Conditional?.Content?.RenderToString());
        }
Ejemplo n.º 2
0
        public async Task ProcessAsync_AddItemsToContext()
        {
            // Arrange
            var itemContext = new CheckboxesItemContext();

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

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

            var tagHelper = new CheckboxesItemHintTagHelper();

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

            // Assert
            Assert.Equal("Hint", itemContext.Hint?.content.AsString());
        }
Ejemplo n.º 3
0
        public void SetHint_SetsHintOnContext()
        {
            // Arrange
            var context = new CheckboxesItemContext();

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

            // Assert
            Assert.Equal("Hint", context.Hint?.Content?.ToString());
        }
Ejemplo n.º 4
0
        public void SetConditional_SetsConditionalOnContext()
        {
            // Arrange
            var context = new CheckboxesItemContext();

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

            // Assert
            Assert.Equal("Conditional", context.Conditional?.Content?.ToString());
        }
Ejemplo n.º 5
0
        public void SetHint_AlreadyGotHint_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new CheckboxesItemContext();

            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-checkboxes-item-hint> element is permitted within each <govuk-checkboxes-item>.", ex.Message);
        }
Ejemplo n.º 6
0
        public void SetHint_AlreadyGotConditional_ThrowsInvalidOperationException()
        {
            // Arrange
            var context = new CheckboxesItemContext();

            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-checkboxes-item-hint> must be specified before <govuk-checkboxes-item-conditional>.", ex.Message);
        }