public async Task ProcessAsync_SetsContentOnContext() { // Arrange var detailsContext = new DetailsContext(); 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 await tagHelper.ProcessAsync(context, output); // Assert Assert.Equal("The summary", detailsContext.Summary?.content.AsString()); }
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); }