// TODO: https://github.com/aspnet/Razor/issues/89 - We will not need this method once #89 is completed. private static Dictionary<string, object> GetRouteValues( TagHelperOutput output, IEnumerable<KeyValuePair<string, object>> routePrefixedAttributes) { Dictionary<string, object> routeValues = null; if (routePrefixedAttributes.Any()) { // Prefixed values should be treated as bound attributes, remove them from the output. output.RemoveRange(routePrefixedAttributes); // Remove prefix from keys and convert all values to strings. HtmlString and similar classes are not // meaningful to routing. routeValues = routePrefixedAttributes.ToDictionary( attribute => attribute.Key.Substring(RouteAttributePrefix.Length), attribute => (object)attribute.Value.ToString()); } return routeValues; }
public void RemoveRange_RemovesProvidedAttributes() { // Arrange var tagHelperOutput = new TagHelperOutput( "p", attributes: new Dictionary<string, object>() { { "route-Hello", "World" }, { "Route-I", "Am" } }); var expectedAttribute = new KeyValuePair<string, object>("type", "btn"); tagHelperOutput.Attributes.Add(expectedAttribute); var attributes = tagHelperOutput.FindPrefixedAttributes("route-"); // Act tagHelperOutput.RemoveRange(attributes); // Assert var attribute = Assert.Single(tagHelperOutput.Attributes); Assert.Equal(expectedAttribute, attribute); }