Merge remote-tracking branch 'origin/release/2.2'

This commit is contained in:
Ryan Nowak 2018-07-20 13:09:18 -07:00
commit 56a67b92a6
10 changed files with 105 additions and 75 deletions

View File

@ -18,6 +18,7 @@
<PackageSigningCertName>MicrosoftNuGet</PackageSigningCertName> <PackageSigningCertName>MicrosoftNuGet</PackageSigningCertName>
<PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign> <PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseRoutingFromFeatureBranch>true</UseRoutingFromFeatureBranch>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -4,17 +4,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging.Abstractions;
namespace Microsoft.AspNetCore.Mvc.Performance namespace Microsoft.AspNetCore.Mvc.Performance
{ {
@ -22,6 +18,11 @@ namespace Microsoft.AspNetCore.Mvc.Performance
{ {
private const string DefaultRoute = "{Controller=Home}/{Action=Index}/{id?}"; private const string DefaultRoute = "{Controller=Home}/{Action=Index}/{id?}";
// Attribute routes can't have controller and action as parameters, so we edit the
// route template in the test to make it more realistic.
private const string ControllerReplacementToken = "{Controller=Home}";
private const string ActionReplacementToken = "{Action=Index}";
private MockActionDescriptorCollectionProvider _conventionalActionProvider; private MockActionDescriptorCollectionProvider _conventionalActionProvider;
private MockActionDescriptorCollectionProvider _attributeActionProvider; private MockActionDescriptorCollectionProvider _attributeActionProvider;
private List<MvcEndpointInfo> _conventionalEndpointInfos; private List<MvcEndpointInfo> _conventionalEndpointInfos;
@ -33,11 +34,11 @@ namespace Microsoft.AspNetCore.Mvc.Performance
public void Setup() public void Setup()
{ {
_conventionalActionProvider = new MockActionDescriptorCollectionProvider( _conventionalActionProvider = new MockActionDescriptorCollectionProvider(
Enumerable.Range(0, ActionCount).Select(i => CreateActionDescriptor(i, false)).ToList() Enumerable.Range(0, ActionCount).Select(i => CreateConventionalRoutedAction(i)).ToList()
); );
_attributeActionProvider = new MockActionDescriptorCollectionProvider( _attributeActionProvider = new MockActionDescriptorCollectionProvider(
Enumerable.Range(0, ActionCount).Select(i => CreateActionDescriptor(i, true)).ToList() Enumerable.Range(0, ActionCount).Select(i => CreateAttributeRoutedAction(i)).ToList()
); );
_conventionalEndpointInfos = new List<MvcEndpointInfo> _conventionalEndpointInfos = new List<MvcEndpointInfo>
@ -67,27 +68,40 @@ namespace Microsoft.AspNetCore.Mvc.Performance
var endpoints = endpointDataSource.Endpoints; var endpoints = endpointDataSource.Endpoints;
} }
private ActionDescriptor CreateActionDescriptor(int id, bool attributeRoute) private ActionDescriptor CreateAttributeRoutedAction(int id)
{ {
var actionDescriptor = new ActionDescriptor var routeValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{ {
RouteValues = new Dictionary<string, string> ["Controller"] = "Controller" + id,
["Action"] = "Index"
};
var template = DefaultRoute
.Replace(ControllerReplacementToken, routeValues["Controller"])
.Replace(ActionReplacementToken, routeValues["Action"]);
return new ActionDescriptor
{
RouteValues = routeValues,
DisplayName = "Action " + id,
AttributeRouteInfo = new AttributeRouteInfo()
{
Template = template,
}
};
}
private ActionDescriptor CreateConventionalRoutedAction(int id)
{
return new ActionDescriptor
{
RouteValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{ {
["Controller"] = "Controller" + id, ["Controller"] = "Controller" + id,
["Action"] = "Index" ["Action"] = "Index"
}, },
DisplayName = "Action " + id DisplayName = "Action " + id
}; };
if (attributeRoute)
{
actionDescriptor.AttributeRouteInfo = new AttributeRouteInfo
{
Template = DefaultRoute
};
}
return actionDescriptor;
} }
private MvcEndpointDataSource CreateMvcEndpointDataSource( private MvcEndpointDataSource CreateMvcEndpointDataSource(

View File

@ -48,8 +48,8 @@
<MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion> <MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion>
<MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion> <MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion>
<MicrosoftAspNetCoreResponseCachingPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreResponseCachingPackageVersion> <MicrosoftAspNetCoreResponseCachingPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreResponseCachingPackageVersion>
<MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreRoutingAbstractionsPackageVersion> <MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>3.0.0-a-alpha1-master-route-pattern-16760</MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>
<MicrosoftAspNetCoreRoutingPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreRoutingPackageVersion> <MicrosoftAspNetCoreRoutingPackageVersion>3.0.0-a-alpha1-master-route-pattern-16760</MicrosoftAspNetCoreRoutingPackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreServerIISIntegrationPackageVersion> <MicrosoftAspNetCoreServerIISIntegrationPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreServerKestrelPackageVersion> <MicrosoftAspNetCoreServerKestrelPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreSessionPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreSessionPackageVersion> <MicrosoftAspNetCoreSessionPackageVersion>3.0.0-alpha1-10099</MicrosoftAspNetCoreSessionPackageVersion>

View File

@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.EndpointConstraints; using Microsoft.AspNetCore.Routing.EndpointConstraints;
using Microsoft.AspNetCore.Routing.Matchers; using Microsoft.AspNetCore.Routing.Matchers;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.AspNetCore.Routing.Template; using Microsoft.AspNetCore.Routing.Template;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
@ -298,20 +299,18 @@ namespace Microsoft.AspNetCore.Mvc.Internal
return invoker.InvokeAsync(); return invoker.InvokeAsync();
}; };
var defaults = new RouteValueDictionary(nonInlineDefaults);
EnsureRequiredValuesInDefaults(action.RouteValues, defaults);
var metadataCollection = BuildEndpointMetadata(action, routeName, source); var metadataCollection = BuildEndpointMetadata(action, routeName, source);
var endpoint = new MatcherEndpoint( var endpoint = new MatcherEndpoint(
next => invokerDelegate, next => invokerDelegate,
template, RoutePatternFactory.Parse(template, defaults, constraints: null),
new RouteValueDictionary(nonInlineDefaults),
new RouteValueDictionary(action.RouteValues), new RouteValueDictionary(action.RouteValues),
order, order,
metadataCollection, metadataCollection,
action.DisplayName); action.DisplayName);
// Use defaults after the endpoint is created as it merges both the inline and
// non-inline defaults into one.
EnsureRequiredValuesInDefaults(endpoint.RequiredValues, endpoint.Defaults);
return endpoint; return endpoint;
} }
@ -373,7 +372,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Required values: controller=foo, action=bar // Required values: controller=foo, action=bar
// Final constructed template: foo/bar/{category}/{id?} // Final constructed template: foo/bar/{category}/{id?}
// Final defaults: controller=foo, action=bar, category=products // Final defaults: controller=foo, action=bar, category=products
private void EnsureRequiredValuesInDefaults(RouteValueDictionary requiredValues, RouteValueDictionary defaults) private void EnsureRequiredValuesInDefaults(IDictionary<string, string> requiredValues, RouteValueDictionary defaults)
{ {
foreach (var kvp in requiredValues) foreach (var kvp in requiredValues)
{ {

View File

@ -25,6 +25,7 @@ Microsoft.AspNetCore.Mvc.RouteAttribute</Description>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="$(MicrosoftAspNetCoreHttpPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Http" Version="$(MicrosoftAspNetCoreHttpPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(MicrosoftAspNetCoreHttpExtensionsPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(MicrosoftAspNetCoreHttpExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCaching.Abstractions" Version="$(MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.ResponseCaching.Abstractions" Version="$(MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="$(MicrosoftAspNetCoreRoutingAbstractionsPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="$(MicrosoftAspNetCoreRoutingPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Routing" Version="$(MicrosoftAspNetCoreRoutingPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelPackageVersion)" />

View File

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.EndpointConstraints; using Microsoft.AspNetCore.Routing.EndpointConstraints;
using Microsoft.AspNetCore.Routing.Matchers; using Microsoft.AspNetCore.Routing.Matchers;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using Moq; using Moq;
using Xunit; using Xunit;
@ -297,12 +298,11 @@ namespace Microsoft.AspNetCore.Mvc
private MatcherEndpoint CreateEndpoint(params IEndpointConstraint[] constraints) private MatcherEndpoint CreateEndpoint(params IEndpointConstraint[] constraints)
{ {
EndpointMetadataCollection endpointMetadata = new EndpointMetadataCollection(constraints); var endpointMetadata = new EndpointMetadataCollection(constraints);
return new MatcherEndpoint( return new MatcherEndpoint(
(r) => null, (r) => null,
"", RoutePatternFactory.Parse("/"),
new RouteValueDictionary(),
new RouteValueDictionary(), new RouteValueDictionary(),
0, 0,
endpointMetadata, endpointMetadata,

View File

@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
Assert.Equal(displayName, matcherEndpoint.DisplayName); Assert.Equal(displayName, matcherEndpoint.DisplayName);
Assert.Equal(order, matcherEndpoint.Order); Assert.Equal(order, matcherEndpoint.Order);
Assert.Equal(template, matcherEndpoint.Template); Assert.Equal(template, matcherEndpoint.RoutePattern.RawText);
} }
[Fact] [Fact]
@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
var inspectors = finalEndpointTemplates var inspectors = finalEndpointTemplates
.Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<MatcherEndpoint>(e).Template))) .Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText)))
.ToArray(); .ToArray();
// Assert // Assert
@ -224,7 +224,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
var inspectors = finalEndpointTemplates var inspectors = finalEndpointTemplates
.Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<MatcherEndpoint>(e).Template))) .Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText)))
.ToArray(); .ToArray();
// Assert // Assert
@ -248,8 +248,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
Assert.Collection(endpoints, Assert.Collection(endpoints,
(e) => Assert.Equal("TestController", Assert.IsType<MatcherEndpoint>(e).Template), (e) => Assert.Equal("TestController", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText),
(e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).Template)); (e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText));
} }
[Fact] [Fact]
@ -276,8 +276,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
Assert.Collection(endpoints1, Assert.Collection(endpoints1,
(e) => Assert.Equal("TestController", Assert.IsType<MatcherEndpoint>(e).Template), (e) => Assert.Equal("TestController", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText),
(e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).Template)); (e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText));
Assert.Same(endpoints1, endpoints2); Assert.Same(endpoints1, endpoints2);
actionDescriptorCollectionProviderMock.VerifyGet(m => m.ActionDescriptors, Times.Once); actionDescriptorCollectionProviderMock.VerifyGet(m => m.ActionDescriptors, Times.Once);
@ -318,8 +318,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var endpoints = dataSource.Endpoints; var endpoints = dataSource.Endpoints;
Assert.Collection(endpoints, Assert.Collection(endpoints,
(e) => Assert.Equal("TestController", Assert.IsType<MatcherEndpoint>(e).Template), (e) => Assert.Equal("TestController", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText),
(e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).Template)); (e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText));
actionDescriptorCollectionProviderMock actionDescriptorCollectionProviderMock
.Setup(m => m.ActionDescriptors) .Setup(m => m.ActionDescriptors)
@ -335,7 +335,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
Assert.NotSame(endpoints, newEndpoints); Assert.NotSame(endpoints, newEndpoints);
Assert.Collection(newEndpoints, Assert.Collection(newEndpoints,
(e) => Assert.Equal("NewTestController/NewTestAction", Assert.IsType<MatcherEndpoint>(e).Template)); (e) => Assert.Equal("NewTestController/NewTestAction", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText));
} }
[Fact] [Fact]
@ -357,8 +357,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
Assert.Collection(endpoints, Assert.Collection(endpoints,
(e) => Assert.Equal("TestController/TestAction1", Assert.IsType<MatcherEndpoint>(e).Template), (e) => Assert.Equal("TestController/TestAction1", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText),
(e) => Assert.Equal("TestController/TestAction2", Assert.IsType<MatcherEndpoint>(e).Template)); (e) => Assert.Equal("TestController/TestAction2", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText));
} }
[Theory] [Theory]
@ -381,7 +381,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var endpoints = dataSource.Endpoints; var endpoints = dataSource.Endpoints;
var inspectors = finalEndpointTemplates var inspectors = finalEndpointTemplates
.Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<MatcherEndpoint>(e).Template))) .Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText)))
.ToArray(); .ToArray();
// Assert // Assert
@ -431,7 +431,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var routeNameMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteNameMetadata>(); var routeNameMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteNameMetadata>();
Assert.NotNull(routeNameMetadata); Assert.NotNull(routeNameMetadata);
Assert.Equal("namedRoute", routeNameMetadata.Name); Assert.Equal("namedRoute", routeNameMetadata.Name);
Assert.Equal("named/Home/Index/{id?}", matcherEndpoint.Template); Assert.Equal("named/Home/Index/{id?}", matcherEndpoint.RoutePattern.RawText);
}, },
(ep) => (ep) =>
{ {
@ -439,7 +439,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var routeNameMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteNameMetadata>(); var routeNameMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteNameMetadata>();
Assert.NotNull(routeNameMetadata); Assert.NotNull(routeNameMetadata);
Assert.Equal("namedRoute", routeNameMetadata.Name); Assert.Equal("namedRoute", routeNameMetadata.Name);
Assert.Equal("named/Products/Details/{id?}", matcherEndpoint.Template); Assert.Equal("named/Products/Details/{id?}", matcherEndpoint.RoutePattern.RawText);
}); });
} }
@ -467,25 +467,25 @@ namespace Microsoft.AspNetCore.Mvc.Internal
(ep) => (ep) =>
{ {
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep); var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep);
Assert.Equal("Home/Index/{id?}", matcherEndpoint.Template); Assert.Equal("Home/Index/{id?}", matcherEndpoint.RoutePattern.RawText);
Assert.Equal(1, matcherEndpoint.Order); Assert.Equal(1, matcherEndpoint.Order);
}, },
(ep) => (ep) =>
{ {
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep); var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep);
Assert.Equal("named/Home/Index/{id?}", matcherEndpoint.Template); Assert.Equal("named/Home/Index/{id?}", matcherEndpoint.RoutePattern.RawText);
Assert.Equal(2, matcherEndpoint.Order); Assert.Equal(2, matcherEndpoint.Order);
}, },
(ep) => (ep) =>
{ {
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep); var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep);
Assert.Equal("Products/Details/{id?}", matcherEndpoint.Template); Assert.Equal("Products/Details/{id?}", matcherEndpoint.RoutePattern.RawText);
Assert.Equal(1, matcherEndpoint.Order); Assert.Equal(1, matcherEndpoint.Order);
}, },
(ep) => (ep) =>
{ {
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep); var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep);
Assert.Equal("named/Products/Details/{id?}", matcherEndpoint.Template); Assert.Equal("named/Products/Details/{id?}", matcherEndpoint.RoutePattern.RawText);
Assert.Equal(2, matcherEndpoint.Order); Assert.Equal(2, matcherEndpoint.Order);
}); });
} }
@ -587,8 +587,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
var endpoint = Assert.Single(endpoints); var endpoint = Assert.Single(endpoints);
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(endpoint); var matcherEndpoint = Assert.IsType<MatcherEndpoint>(endpoint);
Assert.Equal("Foo/Bar", matcherEndpoint.Template); Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText);
AssertIsSubset(expectedDefaults, matcherEndpoint.Defaults); AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults);
} }
[Fact] [Fact]
@ -609,8 +609,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
var endpoint = Assert.Single(endpoints); var endpoint = Assert.Single(endpoints);
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(endpoint); var matcherEndpoint = Assert.IsType<MatcherEndpoint>(endpoint);
Assert.Equal("Foo/Bar", matcherEndpoint.Template); Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText);
AssertIsSubset(expectedDefaults, matcherEndpoint.Defaults); AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults);
} }
[Fact] [Fact]
@ -632,8 +632,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
var endpoint = Assert.Single(endpoints); var endpoint = Assert.Single(endpoints);
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(endpoint); var matcherEndpoint = Assert.IsType<MatcherEndpoint>(endpoint);
Assert.Equal("Foo/Bar/{subscription=general}", matcherEndpoint.Template); Assert.Equal("Foo/Bar/{subscription=general}", matcherEndpoint.RoutePattern.RawText);
AssertIsSubset(expectedDefaults, matcherEndpoint.Defaults); AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults);
} }
[Fact] [Fact]
@ -654,8 +654,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
var endpoint = Assert.Single(endpoints); var endpoint = Assert.Single(endpoints);
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(endpoint); var matcherEndpoint = Assert.IsType<MatcherEndpoint>(endpoint);
Assert.Equal("Foo/Bar", matcherEndpoint.Template); Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText);
AssertIsSubset(expectedDefaults, matcherEndpoint.Defaults); AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults);
} }
private MvcEndpointDataSource CreateMvcEndpointDataSource( private MvcEndpointDataSource CreateMvcEndpointDataSource(
@ -729,7 +729,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal
return actionDescriptor; return actionDescriptor;
} }
private void AssertIsSubset(RouteValueDictionary subset, RouteValueDictionary fullSet) private void AssertIsSubset(
IReadOnlyDictionary<string, object> subset,
IReadOnlyDictionary<string, object> fullSet)
{ {
foreach (var subsetPair in subset) foreach (var subsetPair in subset)
{ {

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Matchers; using Microsoft.AspNetCore.Routing.Matchers;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Xunit; using Xunit;
@ -35,8 +36,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
var endpoints = GetDefaultEndpoints(); var endpoints = GetDefaultEndpoints();
endpoints.Add(new MatcherEndpoint( endpoints.Add(new MatcherEndpoint(
next => httpContext => Task.CompletedTask, next => httpContext => Task.CompletedTask,
template, RoutePatternFactory.Parse(template),
new RouteValueDictionary(),
new RouteValueDictionary(), new RouteValueDictionary(),
0, 0,
EndpointMetadataCollection.Empty, EndpointMetadataCollection.Empty,
@ -51,8 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
{ {
Endpoint = new MatcherEndpoint( Endpoint = new MatcherEndpoint(
next => cntxt => Task.CompletedTask, next => cntxt => Task.CompletedTask,
"/", RoutePatternFactory.Parse("/"),
new RouteValueDictionary(),
new RouteValueDictionary(), new RouteValueDictionary(),
0, 0,
EndpointMetadataCollection.Empty, EndpointMetadataCollection.Empty,
@ -100,14 +99,14 @@ namespace Microsoft.AspNetCore.Mvc.Routing
private List<MatcherEndpoint> GetDefaultEndpoints() private List<MatcherEndpoint> GetDefaultEndpoints()
{ {
var endpoints = new List<MatcherEndpoint>(); var endpoints = new List<MatcherEndpoint>();
endpoints.Add(CreateEndpoint(null, "home/newaction/{id?}", new { id = "defaultid", controller = "home", action = "newaction" }, 1)); endpoints.Add(CreateEndpoint(null, "home/newaction/{id}", new { id = "defaultid", controller = "home", action = "newaction" }, 1));
endpoints.Add(CreateEndpoint(null, "home/contact/{id?}", new { id = "defaultid", controller = "home", action = "contact" }, 2)); endpoints.Add(CreateEndpoint(null, "home/contact/{id}", new { id = "defaultid", controller = "home", action = "contact" }, 2));
endpoints.Add(CreateEndpoint(null, "home2/newaction/{id?}", new { id = "defaultid", controller = "home2", action = "newaction" }, 3)); endpoints.Add(CreateEndpoint(null, "home2/newaction/{id}", new { id = "defaultid", controller = "home2", action = "newaction" }, 3));
endpoints.Add(CreateEndpoint(null, "home2/contact/{id?}", new { id = "defaultid", controller = "home2", action = "contact" }, 4)); endpoints.Add(CreateEndpoint(null, "home2/contact/{id}", new { id = "defaultid", controller = "home2", action = "contact" }, 4));
endpoints.Add(CreateEndpoint(null, "home3/contact/{id?}", new { id = "defaultid", controller = "home3", action = "contact" }, 5)); endpoints.Add(CreateEndpoint(null, "home3/contact/{id}", new { id = "defaultid", controller = "home3", action = "contact" }, 5));
endpoints.Add(CreateEndpoint("namedroute", "named/home/newaction/{id?}", new { id = "defaultid", controller = "home", action = "newaction" }, 6)); endpoints.Add(CreateEndpoint("namedroute", "named/home/newaction/{id}", new { id = "defaultid", controller = "home", action = "newaction" }, 6));
endpoints.Add(CreateEndpoint("namedroute", "named/home2/newaction/{id?}", new { id = "defaultid", controller = "home2", action = "newaction" }, 7)); endpoints.Add(CreateEndpoint("namedroute", "named/home2/newaction/{id}", new { id = "defaultid", controller = "home2", action = "newaction" }, 7));
endpoints.Add(CreateEndpoint("namedroute", "named/home/contact/{id?}", new { id = "defaultid", controller = "home", action = "contact" }, 8)); endpoints.Add(CreateEndpoint("namedroute", "named/home/contact/{id}", new { id = "defaultid", controller = "home", action = "contact" }, 8));
endpoints.Add(CreateEndpoint("MyRouteName", "any/url", new { }, 9)); endpoints.Add(CreateEndpoint("MyRouteName", "any/url", new { }, 9));
return endpoints; return endpoints;
} }
@ -122,8 +121,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
return new MatcherEndpoint( return new MatcherEndpoint(
next => (httpContext) => Task.CompletedTask, next => (httpContext) => Task.CompletedTask,
template, RoutePatternFactory.Parse(template, defaults, constraints: null),
new RouteValueDictionary(defaults),
new RouteValueDictionary(), new RouteValueDictionary(),
order, order,
metadata, metadata,
@ -149,8 +147,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
{ {
return new MatcherEndpoint( return new MatcherEndpoint(
next => c => Task.CompletedTask, next => c => Task.CompletedTask,
template, RoutePatternFactory.Parse(template, defaults, constraints: null),
defaults,
new RouteValueDictionary(), new RouteValueDictionary(),
0, 0,
EndpointMetadataCollection.Empty, EndpointMetadataCollection.Empty,

View File

@ -50,6 +50,14 @@
<PackageReference Include="AngleSharp" Version="$(AngleSharpPackageVersion)" /> <PackageReference Include="AngleSharp" Version="$(AngleSharpPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.ChunkingCookieManager.Sources" PrivateAssets="All" Version="$(MicrosoftAspNetCoreChunkingCookieManagerSourcesPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.ChunkingCookieManager.Sources" PrivateAssets="All" Version="$(MicrosoftAspNetCoreChunkingCookieManagerSourcesPackageVersion)" />
<!--
Explicitly referencing routing here to make it easy to integrate breaking changes. Localization.Routing brings in a transitive
reference to routing, which makes it hard to work with builds from a feature branch.
-->
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="$(MicrosoftAspNetCoreRoutingAbstractionsPackageVersion)" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="$(MicrosoftAspNetCoreRoutingPackageVersion)" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(MicrosoftAspNetCoreTestHostPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(MicrosoftAspNetCoreTestHostPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(MicrosoftExtensionsLoggingTestingPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(MicrosoftExtensionsLoggingTestingPackageVersion)" />
</ItemGroup> </ItemGroup>

View File

@ -10,6 +10,14 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="$(MicrosoftAspNetCoreAuthenticationPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Authentication" Version="$(MicrosoftAspNetCoreAuthenticationPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Localization.Routing" Version="$(MicrosoftAspNetCoreLocalizationRoutingPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Localization.Routing" Version="$(MicrosoftAspNetCoreLocalizationRoutingPackageVersion)" />
<!--
Explicitly referencing routing here to make it easy to integrate breaking changes. Localization.Routing brings in a transitive
reference to routing, which makes it hard to work with builds from a feature branch.
-->
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="$(MicrosoftAspNetCoreRoutingAbstractionsPackageVersion)" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="$(MicrosoftAspNetCoreRoutingPackageVersion)" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="$(MicrosoftAspNetCoreServerIISIntegrationPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="$(MicrosoftAspNetCoreServerIISIntegrationPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Session" Version="$(MicrosoftAspNetCoreSessionPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Session" Version="$(MicrosoftAspNetCoreSessionPackageVersion)" />