Fix a bug in GetUriByRouteValues

Pride cometh before the fall...
This commit is contained in:
Ryan Nowak 2018-09-24 20:01:36 -07:00
parent 6353e7b15e
commit 7c16c92317
2 changed files with 33 additions and 1 deletions

View File

@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Routing
throw new ArgumentNullException(nameof(httpContext));
}
var address = CreateAddress(httpContext: null, routeName, values);
var address = CreateAddress(httpContext, routeName, values);
return generator.GetUriByAddress<RouteValuesAddress>(
httpContext,
address,

View File

@ -170,6 +170,38 @@ namespace Microsoft.AspNetCore.Routing
Assert.Equal("http://example.com/Foo/Bar%3Fencodeme%3F/Home/Index/?query=some%3Fquery#Fragment?", uri);
}
[Fact]
public void GetUriByRouteValues_WithHttpContext_CanUseAmbientValues()
{
// Arrange
var endpoint1 = EndpointFactory.CreateRouteEndpoint(
"Home/Index/{id}",
defaults: new { controller = "Home", action = "Index", },
metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) });
var endpoint2 = EndpointFactory.CreateRouteEndpoint(
"Home/Index/{id?}",
defaults: new { controller = "Home", action = "Index", },
metadata: new[] { new RouteValuesAddressMetadata(routeName: null, new RouteValueDictionary(new { controller = "Home", action = "Index", })) });
var linkGenerator = CreateLinkGenerator(endpoint1, endpoint2);
var httpContext = CreateHttpContext(new { controller = "Home", });
httpContext.Request.Scheme = "http";
httpContext.Request.Host = new HostString("example.com");
httpContext.Request.PathBase = new PathString("/Foo/Bar?encodeme?");
// Act
var uri = linkGenerator.GetUriByRouteValues(
httpContext,
routeName: null,
values: new RouteValueDictionary(new { action = "Index", query = "some?query" }),
fragment: new FragmentString("#Fragment?"),
options: new LinkOptions() { AppendTrailingSlash = true, });
// Assert
Assert.Equal("http://example.com/Foo/Bar%3Fencodeme%3F/Home/Index/?query=some%3Fquery#Fragment?", uri);
}
[Fact]
public void GetTemplateByRouteValues_CreatesTemplate()
{