public async Task ProcessAsync_ItemAlreadyHasHeaderThrowsInvalidOperationException() { // Arrange var accordionContext = new AccordionContext(); var itemContext = new AccordionItemContext(); itemContext.TrySetHeading(attributes: null, content: new HtmlString("Existing heading")); var context = new TagHelperContext( tagName: "govuk-accordion-item-heading", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(AccordionContext), accordionContext }, { typeof(AccordionItemContext), itemContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-accordion-item-heading", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Summary content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new AccordionItemHeadingTagHelper(); // Act & Assert var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => tagHelper.ProcessAsync(context, output)); Assert.Equal("Cannot render <govuk-accordion-item-heading> here.", ex.Message); }
public async Task ProcessAsync_AddsHeadingToContext() { // Arrange var accordionContext = new AccordionContext(); var itemContext = new AccordionItemContext(); var context = new TagHelperContext( tagName: "govuk-accordion-item-heading", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(AccordionContext), accordionContext }, { typeof(AccordionItemContext), itemContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-accordion-item-heading", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Summary content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new AccordionItemHeadingTagHelper(); // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.NotNull(itemContext.Heading); Assert.Equal("Summary content", itemContext.Heading?.Content.RenderToString()); }
public async Task ProcessAsync_ItemAlreadyHasSummary_ThrowsInvalidOperationException() { // Arrange var accordionContext = new AccordionContext(); var itemContext = new AccordionItemContext(); itemContext.SetSummary(attributes: new AttributeDictionary(), content: new HtmlString("Summary")); var context = new TagHelperContext( tagName: "govuk-accordion-item-heading", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(AccordionContext), accordionContext }, { typeof(AccordionItemContext), itemContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-accordion-item-heading", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Summary content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new AccordionItemHeadingTagHelper(); // Act var ex = await Record.ExceptionAsync(() => tagHelper.ProcessAsync(context, output)); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("<govuk-accordion-item-heading> must be specified before <govuk-accordion-item-summary>.", ex.Message); }
public async Task ProcessAsync_InvalidLevelThrowsInvalidOperationException(int level) { // Arrange var accordionContext = new AccordionContext(); var itemContext = new AccordionItemContext(); var context = new TagHelperContext( tagName: "govuk-accordion-item-heading", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(AccordionContext), accordionContext }, { typeof(AccordionItemContext), itemContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-accordion-item-heading", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Summary content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new AccordionItemHeadingTagHelper() { Level = level }; // Act & Assert var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => tagHelper.ProcessAsync(context, output)); Assert.Equal("The 'level' attribute must be between 1 and 6.", ex.Message); }