Esempio n. 1
0
        public async Task ProcessAsync_AddsValueToContext()
        {
            // Arrange
            var summaryListContext = new SummaryListContext();

            var rowContext = new SummaryListRowContext();

            var context = new TagHelperContext(
                tagName: "govuk-summary-list-row-key",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(SummaryListContext), summaryListContext },
                { typeof(SummaryListRowContext), rowContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-summary-list-row-key",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Key content");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new SummaryListRowKeyTagHelper();

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

            // Assert
            Assert.Equal("Key content", rowContext.Key.Value.Content.RenderToString());
        }
Esempio n. 2
0
        public async Task ProcessAsync_RowAlreadyHasValueThrowsInvalidOperationException()
        {
            // Arrange
            var summaryListContext = new SummaryListContext();
            var rowContext         = new SummaryListRowContext();

            rowContext.TrySetKey(new HtmlString("Existing key"));

            var context = new TagHelperContext(
                tagName: "govuk-summary-list-row-key",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(SummaryListContext), summaryListContext },
                { typeof(SummaryListRowContext), rowContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-summary-list-row-key",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Key content");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new SummaryListRowKeyTagHelper();

            // Act & Assert
            var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => tagHelper.ProcessAsync(context, output));

            Assert.Equal("Cannot render <govuk-summary-list-row-key> here.", ex.Message);
        }
Esempio n. 3
0
        public async Task ProcessAsync_ParentAlreadyHasAction_ThrowsInvalidOperationException()
        {
            // Arrange
            var summaryListContext = new SummaryListContext();

            var rowContext = new SummaryListRowContext();

            rowContext.AddAction(new HtmlGeneration.SummaryListRowAction()
            {
                Content = new HtmlString("Action")
            });

            var context = new TagHelperContext(
                tagName: "govuk-summary-list-row-key",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(SummaryListContext), summaryListContext },
                { typeof(SummaryListRowContext), rowContext }
            },
                uniqueId: "test");

            var output = new TagHelperOutput(
                "govuk-summary-list-row-key",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("Key content");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            var tagHelper = new SummaryListRowKeyTagHelper();

            // Act
            var ex = await Record.ExceptionAsync(() => tagHelper.ProcessAsync(context, output));

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-summary-list-row-key> must be specified before <govuk-summary-list-row-action>.", ex.Message);
        }