public async Task ProcessAsync_NoHeadingThrowsInvalidOperationException() { // Arrange var accordionContext = new AccordionContext(); var context = new TagHelperContext( tagName: "govuk-accordion-item", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(AccordionContext), accordionContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-accordion-item", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var itemContext = (AccordionItemContext)context.Items[typeof(AccordionItemContext)]; itemContext.TrySetSummary(attributes: null, new HtmlString("Summary")); var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new AccordionItemTagHelper(); // Act & Assert var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => tagHelper.ProcessAsync(context, output)); Assert.Equal("Missing <govuk-accordion-item-heading> element.", ex.Message); }
public async Task ProcessAsync_AddsItemToContext() { // Arrange var accordionContext = new AccordionContext(); var context = new TagHelperContext( tagName: "govuk-accordion-item", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(AccordionContext), accordionContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-accordion-item", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var itemContext = (AccordionItemContext)context.Items[typeof(AccordionItemContext)]; itemContext.TrySetHeading(1, attributes: null, new HtmlString("Heading")); itemContext.TrySetSummary(attributes: null, new HtmlString("Summary")); var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new AccordionItemTagHelper(); // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.Equal(1, accordionContext.Items.Count); var firstItem = accordionContext.Items.First(); Assert.Equal(1, firstItem.HeadingLevel.Value); Assert.Equal("Heading", firstItem.HeadingContent.AsString()); Assert.Equal("Summary", firstItem.SummaryContent.AsString()); Assert.Equal("Content", firstItem.Content.AsString()); }