public async Task ProcessAsync_ParentAlreadyHasText_ThrowsInvalidOperationException()
        {
            // Arrange
            var detailsContext = new DetailsContext();

            detailsContext.SetText(new AttributeDictionary(), new HtmlString("The text"));

            var context = new TagHelperContext(
                tagName: "govuk-details-summary",
                allAttributes: new TagHelperAttributeList(),
                items: new Dictionary <object, object>()
            {
                { typeof(DetailsContext), detailsContext }
            },
                uniqueId: "test");

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

            var tagHelper = new DetailsSummaryTagHelper();

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

            // Assert
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal("<govuk-details-summary> must be specified before <govuk-details-text>.", ex.Message);
        }
Exemplo n.º 2
0
        public void ThrowIfStagesIncomplete_StageAtTextDoesNotThrow()
        {
            // Arrange
            var ctx = new DetailsContext();

            ctx.SetSummary(attributes: null, new HtmlString("Summary"));
            ctx.SetText(attributes: null, new HtmlString("Text"));

            // Act & Assert
            Assert.Equal(DetailsRenderStage.Text, ctx.RenderStage);
            ctx.ThrowIfStagesIncomplete();
        }
Exemplo n.º 3
0
        public void SetSummary_StageAtTextThrowsInvalidOperationException()
        {
            // Arrange
            var ctx = new DetailsContext();

            ctx.SetSummary(attributes: null, new HtmlString("Summary"));
            ctx.SetText(attributes: null, new HtmlString("Text"));

            // Act & Assert
            Assert.Equal(DetailsRenderStage.Text, ctx.RenderStage);
            var ex = Assert.Throws <InvalidOperationException>(() => ctx.SetSummary(attributes: null, new HtmlString("Summary")));

            Assert.Equal("Cannot render <govuk-details-summary> here.", ex.Message);
        }