public async Task ProcessAsync_LabelNotSpecifiedThrowsInvalidOperationException() { // Arrange var context = new TagHelperContext( tagName: "govuk-tabs-item", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var tabsContext = new TabsContext(idPrefix: null); context.Items.Add(typeof(TabsContext), tabsContext); var output = new TagHelperOutput( "govuk-tabs-item", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new TabsItemTagHelper() { }; // Act & Assert var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => tagHelper.ProcessAsync(context, output)); Assert.Equal("The 'label' attribute must be specified.", ex.Message); }
public async Task ProcessAsync_NoIdSpecifiedUsesIdDerivedFromPrefixAndIndex() { // Arrange var context = new TagHelperContext( tagName: "govuk-tabs-item", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var tabsContext = new TabsContext(idPrefix: "myprefix"); tabsContext.AddItem(new TabsItem() { Id = "first", Label = "First", PanelContent = new HtmlString("First panel content") }); tabsContext.AddItem(new TabsItem() { Id = "second", Label = "Second", PanelContent = new HtmlString("Second panel content") }); context.Items.Add(typeof(TabsContext), tabsContext); var output = new TagHelperOutput( "govuk-tabs-item", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new TabsItemTagHelper() { Label = "Third" }; // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.Equal("myprefix-2", tabsContext.Items.Last().Id); }