public async Task ProcessAsync_SetsLabelOnContext() { // Arrange var itemContext = new DateInputItemContext("govuk-date-input-day", "govuk-date-input-day-label"); var context = new TagHelperContext( tagName: "govuk-date-input-day-label", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>() { { typeof(DateInputItemContext), itemContext } }, uniqueId: "test"); var output = new TagHelperOutput( "govuk-date-input-day-label", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Label"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new DateInputItemLabelTagHelper(); // Act await tagHelper.ProcessAsync(context, output); // Assert Assert.Equal("Label", itemContext.Label?.Content?.ToString()); }
public void SetLabel_SetsLabelOnContext() { // Arrange var context = new DateInputItemContext("govuk-date-input-day", "govuk-date-input-day-label"); // Act context.SetLabel(content: new HtmlString("Label"), attributes: new AttributeDictionary()); // Assert Assert.Equal("Label", context.Label?.Content?.RenderToString()); }
public void SetLabel_AlreadyGotLabel_ThrowsInvalidOperationException() { // Arrange var context = new DateInputItemContext("govuk-date-input-day", "govuk-date-input-day-label"); context.SetLabel(content: new HtmlString("Existing label"), attributes: new AttributeDictionary()); // Act var ex = Record.Exception(() => context.SetLabel(content: new HtmlString("Label"), attributes: new AttributeDictionary())); // Assert Assert.IsType <InvalidOperationException>(ex); Assert.Equal("Only one <govuk-date-input-day-label> element is permitted within each <govuk-date-input-day>.", ex.Message); }