public void SetTitle_AlreadyGotTitle_ThrowsInvalidOperationException() { // Arrange var context = new PanelContext(); context.SetTitle(new HtmlString("Title")); // Act var ex = Record.Exception(() => context.SetTitle(new HtmlString("Title"))); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("Only one <govuk-panel-title> element is permitted within each <govuk-panel>.", ex.Message); }
public async Task ProcessAsync_ParentAlreadyHasTitle_ThrowsInvalidOperationException() { // Arrange var panelContext = new PanelContext(); panelContext.SetTitle(new HtmlString("The title")); var context = new TagHelperContext( tagName: "govuk-panel-title", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(PanelContext), panelContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-panel-title", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("The title"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new PanelTitleTagHelper(); // Act var ex = await Record.ExceptionAsync(() => tagHelper.ProcessAsync(context, output)); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("Only one <govuk-panel-title> element is permitted within each <govuk-panel>.", ex.Message); }
public void SetTitle_AlreadyGotBody_ThrowsInvalidOperationException() { // Arrange var context = new PanelContext(); context.SetBody(new HtmlString("Body")); // Act var ex = Record.Exception(() => context.SetTitle(new HtmlString("Title"))); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("<govuk-panel-title> must be specified before <govuk-panel-body>.", ex.Message); }