public async Task ProcessAsync_AlreadyHaveDescriptionThrowsInvalidOperationException() { // Arrange var errorSummaryContext = new ErrorSummaryContext(); errorSummaryContext.TrySetDescription(attributes: null, new HtmlString("Existing description")); var context = new TagHelperContext( tagName: "govuk-error-summary-description", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(ErrorSummaryContext), errorSummaryContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-error-summary-description", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Some description"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new ErrorSummaryDescriptionTagHelper(); // Act var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => tagHelper.ProcessAsync(context, output)); Assert.Equal("Cannot render <govuk-error-summary-description> here.", ex.Message); }
public async Task ProcessAsync_AddsDescriptionToContext() { // Arrange var errorSummaryContext = new ErrorSummaryContext(); var context = new TagHelperContext( tagName: "govuk-error-summary-description", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(ErrorSummaryContext), errorSummaryContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-error-summary-description", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Some description"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new ErrorSummaryDescriptionTagHelper(); // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.Equal("Some description", errorSummaryContext.Description?.content.AsString()); }