public async Task ProcessAsync_WithNoHrefSpecified_UsesDefaultHref() { // Arrange var context = new TagHelperContext( tagName: "govuk-skip-link", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var output = new TagHelperOutput( "govuk-skip-link", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Link content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new SkipLinkTagHelper(); // Act await tagHelper.ProcessAsync(context, output); // Assert var element = output.RenderToElement(); Assert.Equal("#content", element.GetAttribute("href")); }
public async Task ProcessAsync_WithHrefSpecified_GeneratesExpectedOutput() { // Arrange var context = new TagHelperContext( tagName: "govuk-skip-link", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var output = new TagHelperOutput( "govuk-skip-link", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("Link content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); var tagHelper = new SkipLinkTagHelper() { Href = "#main" }; // Act await tagHelper.ProcessAsync(context, output); // Assert var expectedHtml = @" <a class=""govuk-skip-link"" href=""#main"" data-module=""govuk-skip-link"">Link content</a>"; AssertEx.HtmlEqual(expectedHtml, output.RenderToString()); }
public async Task ProcessAsync_WithContentGeneratesExpectedOutput() { // Arrange var context = new TagHelperContext( tagName: "govuk-skip-link", allAttributes: new TagHelperAttributeList(), items: new Dictionary <object, object>(), uniqueId: "test"); var output = new TagHelperOutput( "govuk-skip-link", attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent("My custom link content"); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); output.Content.SetContent("My custom link content"); var tagHelper = new SkipLinkTagHelper( new DefaultGovUkHtmlGenerator(), Mock.Of <IUrlHelperFactory>()) { Href = "http://foo.com" }; // Act await tagHelper.ProcessAsync(context, output); // Assert var html = output.AsString(); Assert.Equal("<a class=\"govuk-skip-link\" href=\"http://foo.com\">My custom link content</a>", html); }