public async Task ProcessAsync_MissingLegend_ThrowsInvalidOperationException() { // Arrange var context = new TagHelperContext( tagName: "govuk-fieldset", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var output = new TagHelperOutput( "govuk-fieldset", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var fieldsetContext = context.GetContextItem <FieldsetContext>(); var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Main content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new FieldsetTagHelper() { DescribedBy = "describedby", Role = "therole" }; // Act var ex = await Record.ExceptionAsync(() => tagHelper.ProcessAsync(context, output)); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("A <govuk-fieldset-legend> element must be provided.", ex.Message); }
public async Task ProcessAsync_IsPageHeadingGeneratesExpectedOutput() { // Arrange var context = new TagHelperContext( tagName: "govuk-fieldset", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var output = new TagHelperOutput( "govuk-fieldset", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var fieldsetContext = (FieldsetContext)context.Items[typeof(FieldsetContext)]; fieldsetContext.TrySetLegend( isPageHeading: true, attributes: null, content: new HtmlString("Legend text")); var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Main text"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new FieldsetTagHelper(new DefaultGovUkHtmlGenerator()) { DescribedBy = "describedby", Role = "therole" }; // Act await tagHelper.ProcessAsync(context, output); // Assert var html = output.AsString(); Assert.Equal( "<fieldset aria-describedby=\"describedby\" class=\"govuk-fieldset\" role=\"therole\">" + "<legend class=\"govuk-fieldset__legend\">" + "<h1 class=\"govuk-fieldset__heading\">Legend text</h1>" + "</legend>" + "Main text" + "</fieldset>", html); }
public async Task ProcessAsync_LegendHasIsPageHeading_GeneratesExpectedOutput() { // Arrange var context = new TagHelperContext( tagName: "govuk-fieldset", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var output = new TagHelperOutput( "govuk-fieldset", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var fieldsetContext = context.GetContextItem <FieldsetContext>(); fieldsetContext.SetLegend( isPageHeading: true, attributes: null, content: new HtmlString("Legend text")); var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Main content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new FieldsetTagHelper() { DescribedBy = "describedby", Role = "therole" }; // Act await tagHelper.ProcessAsync(context, output); // Assert var expectedHtml = @" <fieldset aria-describedby=""describedby"" class=""govuk-fieldset"" role=""therole""> <legend class=""govuk-fieldset__legend""> <h1 class=""govuk-fieldset__heading"">Legend text</h1> </legend> Main content </fieldset>"; AssertEx.HtmlEqual(expectedHtml, output.RenderToString()); }