public void SetSummary_StageAtSummaryThrowsInvalidOperationException() { // Arrange var ctx = new DetailsContext(); ctx.SetSummary(attributes: null, new HtmlString("Summary")); // Act & Assert Assert.Equal(DetailsRenderStage.Summary, ctx.RenderStage); var ex = Assert.Throws <InvalidOperationException>(() => ctx.SetSummary(attributes: null, new HtmlString("Summary"))); Assert.Equal("Cannot render <govuk-details-summary> here.", ex.Message); }
public async Task ProcessAsync_SetsContentOnContext() { // Arrange var detailsContext = new DetailsContext(); detailsContext.SetSummary(attributes: null, new HtmlString("The summary")); var context = new TagHelperContext( tagName: "govuk-details-text", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(DetailsContext), detailsContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-details-text", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("The text"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new DetailsTextTagHelper(); // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.Equal("The text", detailsContext.Text?.content.AsString()); }
public async Task ProcessAsync_ParentAlreadyHasSummary_ThrowsInvalidOperationException() { // Arrange var detailsContext = new DetailsContext(); detailsContext.SetSummary(new AttributeDictionary(), new HtmlString("The summary")); 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("Only one <govuk-details-summary> element is permitted within each <govuk-details>.", ex.Message); }
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(); }
public void ThrowIfStagesIncomplete_StageAtSummaryThrowsInvalidOperationException() { // Arrange var ctx = new DetailsContext(); ctx.SetSummary(attributes: null, new HtmlString("Summary")); // Act & Assert Assert.Equal(DetailsRenderStage.Summary, ctx.RenderStage); var ex = Assert.Throws <InvalidOperationException>(() => ctx.ThrowIfStagesIncomplete()); Assert.Equal("Missing one or more child elements.", ex.Message); }