Fix a bug in GetUriByRouteValues
Pride cometh before the fall...
This commit is contained in:
parent
6353e7b15e
commit
7c16c92317
|
|
@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
throw new ArgumentNullException(nameof(httpContext));
|
throw new ArgumentNullException(nameof(httpContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
var address = CreateAddress(httpContext: null, routeName, values);
|
var address = CreateAddress(httpContext, routeName, values);
|
||||||
return generator.GetUriByAddress<RouteValuesAddress>(
|
return generator.GetUriByAddress<RouteValuesAddress>(
|
||||||
httpContext,
|
httpContext,
|
||||||
address,
|
address,
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,38 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
Assert.Equal("http://example.com/Foo/Bar%3Fencodeme%3F/Home/Index/?query=some%3Fquery#Fragment?", uri);
|
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]
|
[Fact]
|
||||||
public void GetTemplateByRouteValues_CreatesTemplate()
|
public void GetTemplateByRouteValues_CreatesTemplate()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue