* #4847 Fix MapAreaRoute override existing area constraint Modify Test project Modify web test routing * wrong field tested * IntRouteConstraint expected * Default for area route on Travel area * Removed commented code simplify constraintsDictionary area assign renamed test method * test name * renamedd test to MapAreaRoute_DoesNotReplaceValuesForAreaIfAlreadyPresentInConstraintsOrDefaults
This commit is contained in:
parent
3d2bb673ee
commit
b4677a44da
|
|
@ -128,10 +128,10 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultsDictionary = new RouteValueDictionary(defaults);
|
var defaultsDictionary = new RouteValueDictionary(defaults);
|
||||||
defaultsDictionary["area"] = areaName;
|
defaultsDictionary["area"] = defaultsDictionary["area"] ?? areaName;
|
||||||
|
|
||||||
var constraintsDictionary = new RouteValueDictionary(constraints);
|
var constraintsDictionary = new RouteValueDictionary(constraints);
|
||||||
constraintsDictionary["area"] = areaName;
|
constraintsDictionary["area"] = constraintsDictionary["area"] ?? areaName;
|
||||||
|
|
||||||
routeBuilder.MapRoute(name, template, defaultsDictionary, constraintsDictionary, dataTokens);
|
routeBuilder.MapRoute(name, template, defaultsDictionary, constraintsDictionary, dataTokens);
|
||||||
return routeBuilder;
|
return routeBuilder;
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MapAreaRoute_ReplacesValuesForArea()
|
public void MapAreaRoute_DoesNotReplaceValuesForAreaIfAlreadyPresentInConstraintsOrDefaults()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var builder = CreateRouteBuilder();
|
var builder = CreateRouteBuilder();
|
||||||
|
|
@ -209,7 +209,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
kvp =>
|
kvp =>
|
||||||
{
|
{
|
||||||
Assert.Equal(kvp.Key, "area");
|
Assert.Equal(kvp.Key, "area");
|
||||||
Assert.IsType<RegexRouteConstraint>(kvp.Value);
|
Assert.IsType<IntRouteConstraint>(kvp.Value);
|
||||||
});
|
});
|
||||||
Assert.Collection(
|
Assert.Collection(
|
||||||
route.DataTokens.OrderBy(kvp => kvp.Key),
|
route.DataTokens.OrderBy(kvp => kvp.Key),
|
||||||
|
|
@ -223,7 +223,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
kvp =>
|
kvp =>
|
||||||
{
|
{
|
||||||
Assert.Equal(kvp.Key, "area");
|
Assert.Equal(kvp.Key, "area");
|
||||||
Assert.Equal(kvp.Value, "admin");
|
Assert.Equal(kvp.Value, "Home");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,13 @@ namespace RoutingWebSite
|
||||||
|
|
||||||
app.UseMvc(routes =>
|
app.UseMvc(routes =>
|
||||||
{
|
{
|
||||||
routes.MapRoute(
|
routes.MapAreaRoute(
|
||||||
"areaRoute",
|
"flightRoute",
|
||||||
"{area:exists}/{controller}/{action}",
|
"adminRoute",
|
||||||
new { controller = "Home", action = "Index" });
|
"{area:exists}/{controller}/{action}",
|
||||||
|
new { controller = "Home", action = "Index" },
|
||||||
|
new { area = "Travel" }
|
||||||
|
);
|
||||||
|
|
||||||
routes.MapRoute(
|
routes.MapRoute(
|
||||||
"ActionAsMethod",
|
"ActionAsMethod",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue