public void Set_AddsNewQueryParameter() { const string path = "/6/7/8"; var routeValues = new RouteValueDictionary(); var templateMatcher = new TemplateMatcher(TemplateParser.Parse("/{a}/{b}/{c}"), new RouteValueDictionary()); templateMatcher.TryMatch(path, routeValues); var httpContext = new DefaultHttpContext(); httpContext.Request.RouteValues = routeValues; var context = new RequestTransformContext() { Path = path, Query = new QueryTransformContext(httpContext.Request), HttpContext = httpContext }; var transform = new QueryParameterRouteTransform(QueryStringTransformMode.Set, "z", "a"); transform.ApplyAsync(context); Assert.Equal("?z=6", context.Query.QueryString.Value); }
public async Task Append_AddsQueryParameterWithRouteValue(string pattern, string routeValueKey, string expected) { const string path = "/6/7/8"; var routeValues = new RouteValueDictionary(); var templateMatcher = new TemplateMatcher(TemplateParser.Parse(pattern), new RouteValueDictionary()); templateMatcher.TryMatch(path, routeValues); var httpContext = new DefaultHttpContext(); httpContext.Request.RouteValues = routeValues; var context = new RequestTransformContext() { Path = path, Query = new QueryTransformContext(httpContext.Request), HttpContext = httpContext }; var transform = new QueryParameterRouteTransform(QueryStringTransformMode.Append, "z", routeValueKey); await transform.ApplyAsync(context); Assert.Equal(expected, context.Query.QueryString.Value); }