React to routing changes (#8303)

This commit is contained in:
James Newton-King 2018-08-22 17:15:09 +12:00 committed by GitHub
parent 5bd818bd64
commit cbe1526763
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 79 additions and 74 deletions

View File

@ -48,8 +48,8 @@
<MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion> <MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreRazorTagHelpersTestingSourcesPackageVersion>
<MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion> <MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreResponseCachingAbstractionsPackageVersion>
<MicrosoftAspNetCoreResponseCachingPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreResponseCachingPackageVersion> <MicrosoftAspNetCoreResponseCachingPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreResponseCachingPackageVersion>
<MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreRoutingAbstractionsPackageVersion> <MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>2.2.0-a-preview2-matcherendpoint-rename-16892</MicrosoftAspNetCoreRoutingAbstractionsPackageVersion>
<MicrosoftAspNetCoreRoutingPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreRoutingPackageVersion> <MicrosoftAspNetCoreRoutingPackageVersion>2.2.0-a-preview2-matcherendpoint-rename-16892</MicrosoftAspNetCoreRoutingPackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreServerIISIntegrationPackageVersion> <MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreServerKestrelPackageVersion> <MicrosoftAspNetCoreServerKestrelPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreSessionPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreSessionPackageVersion> <MicrosoftAspNetCoreSessionPackageVersion>2.2.0-preview1-34967</MicrosoftAspNetCoreSessionPackageVersion>

View File

@ -6,11 +6,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Matching;
using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.AspNetCore.Routing.Template; using Microsoft.AspNetCore.Routing.Template;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
@ -262,7 +262,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
return false; return false;
} }
private MatcherEndpoint CreateEndpoint( private RouteEndpoint CreateEndpoint(
ActionDescriptor action, ActionDescriptor action,
string routeName, string routeName,
string template, string template,
@ -271,9 +271,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal
object source, object source,
bool suppressLinkGeneration) bool suppressLinkGeneration)
{ {
RequestDelegate invokerDelegate = (context) => RequestDelegate requestDelegate = (context) =>
{ {
var values = context.Features.Get<IEndpointFeature>().Values; var values = context.Features.Get<IRouteValuesFeature>().RouteValues;
var routeData = new RouteData(); var routeData = new RouteData();
foreach (var kvp in values) foreach (var kvp in values)
{ {
@ -299,9 +299,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal
source, source,
suppressLinkGeneration); suppressLinkGeneration);
var endpoint = new MatcherEndpoint( var endpoint = new RouteEndpoint(
next => invokerDelegate, requestDelegate,
RoutePatternFactory.Parse(template, defaults, constraints: null), RoutePatternFactory.Parse(template, defaults, parameterPolicies: null),
order, order,
metadataCollection, metadataCollection,
action.DisplayName); action.DisplayName);

View File

@ -135,8 +135,8 @@ namespace Microsoft.AspNetCore.Mvc.Routing
private Endpoint CreateRejectionEndpoint() private Endpoint CreateRejectionEndpoint()
{ {
return new MatcherEndpoint( return new RouteEndpoint(
(next) => (context) => (context) =>
{ {
context.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType; context.Response.StatusCode = StatusCodes.Status415UnsupportedMediaType;
return Task.CompletedTask; return Task.CompletedTask;

View File

@ -3,6 +3,7 @@
using System; using System;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;

View File

@ -64,7 +64,7 @@ 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<RouteEndpoint>(endpoint);
var routeValuesAddressMetadata = matcherEndpoint.Metadata.GetMetadata<RouteValuesAddressMetadata>(); var routeValuesAddressMetadata = matcherEndpoint.Metadata.GetMetadata<RouteValuesAddressMetadata>();
Assert.NotNull(routeValuesAddressMetadata); Assert.NotNull(routeValuesAddressMetadata);
@ -77,14 +77,17 @@ namespace Microsoft.AspNetCore.Mvc.Internal
} }
[Fact] [Fact]
public void Endpoints_InvokeReturnedEndpoint_ActionInvokerProviderCalled() public async Task Endpoints_InvokeReturnedEndpoint_ActionInvokerProviderCalled()
{ {
// Arrange // Arrange
var featureCollection = new FeatureCollection(); var endpointFeature = new EndpointFeature
featureCollection.Set<IEndpointFeature>(new EndpointFeature
{ {
Values = new RouteValueDictionary() RouteValues = new RouteValueDictionary()
}); };
var featureCollection = new FeatureCollection();
featureCollection.Set<IEndpointFeature>(endpointFeature);
featureCollection.Set<IRouteValuesFeature>(endpointFeature);
var httpContextMock = new Mock<HttpContext>(); var httpContextMock = new Mock<HttpContext>();
httpContextMock.Setup(m => m.Features).Returns(featureCollection); httpContextMock.Setup(m => m.Features).Returns(featureCollection);
@ -122,11 +125,9 @@ 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<RouteEndpoint>(endpoint);
var invokerDelegate = matcherEndpoint.Invoker((next) => Task.CompletedTask); await matcherEndpoint.RequestDelegate(httpContextMock.Object);
invokerDelegate(httpContextMock.Object);
Assert.True(actionInvokerCalled); Assert.True(actionInvokerCalled);
} }
@ -138,7 +139,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var featureCollection = new FeatureCollection(); var featureCollection = new FeatureCollection();
featureCollection.Set<IEndpointFeature>(new EndpointFeature featureCollection.Set<IEndpointFeature>(new EndpointFeature
{ {
Values = new RouteValueDictionary() RouteValues = new RouteValueDictionary()
}); });
var httpContextMock = new Mock<HttpContext>(); var httpContextMock = new Mock<HttpContext>();
@ -199,7 +200,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).RoutePattern.RawText))) .Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText)))
.ToArray(); .ToArray();
// Assert // Assert
@ -226,7 +227,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).RoutePattern.RawText))) .Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText)))
.ToArray(); .ToArray();
// Assert // Assert
@ -250,8 +251,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
Assert.Collection(endpoints, Assert.Collection(endpoints,
(e) => Assert.Equal("TestController", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText), (e) => Assert.Equal("TestController", Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText),
(e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText)); (e) => Assert.Equal("TestController/TestAction", Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText));
} }
[Fact] [Fact]
@ -278,8 +279,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
Assert.Collection(endpoints1, Assert.Collection(endpoints1,
(e) => Assert.Equal("TestController", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText), (e) => Assert.Equal("TestController", Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText),
(e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText)); (e) => Assert.Equal("TestController/TestAction", Assert.IsType<RouteEndpoint>(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);
@ -320,8 +321,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).RoutePattern.RawText), (e) => Assert.Equal("TestController", Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText),
(e) => Assert.Equal("TestController/TestAction", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText)); (e) => Assert.Equal("TestController/TestAction", Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText));
actionDescriptorCollectionProviderMock actionDescriptorCollectionProviderMock
.Setup(m => m.ActionDescriptors) .Setup(m => m.ActionDescriptors)
@ -337,7 +338,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).RoutePattern.RawText)); (e) => Assert.Equal("NewTestController/NewTestAction", Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText));
} }
[Fact] [Fact]
@ -359,8 +360,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
// Assert // Assert
Assert.Collection(endpoints, Assert.Collection(endpoints,
(e) => Assert.Equal("TestController/TestAction1", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText), (e) => Assert.Equal("TestController/TestAction1", Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText),
(e) => Assert.Equal("TestController/TestAction2", Assert.IsType<MatcherEndpoint>(e).RoutePattern.RawText)); (e) => Assert.Equal("TestController/TestAction2", Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText));
} }
[Theory] [Theory]
@ -383,7 +384,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).RoutePattern.RawText))) .Select(t => new Action<Endpoint>(e => Assert.Equal(t, Assert.IsType<RouteEndpoint>(e).RoutePattern.RawText)))
.ToArray(); .ToArray();
// Assert // Assert
@ -405,7 +406,7 @@ 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<RouteEndpoint>(endpoint);
var routeValuesAddressNameMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteValuesAddressMetadata>(); var routeValuesAddressNameMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteValuesAddressMetadata>();
Assert.NotNull(routeValuesAddressNameMetadata); Assert.NotNull(routeValuesAddressNameMetadata);
Assert.Equal(string.Empty, routeValuesAddressNameMetadata.Name); Assert.Equal(string.Empty, routeValuesAddressNameMetadata.Name);
@ -430,7 +431,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
endpoints, endpoints,
(ep) => (ep) =>
{ {
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep); var matcherEndpoint = Assert.IsType<RouteEndpoint>(ep);
var routeValuesAddressMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteValuesAddressMetadata>(); var routeValuesAddressMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteValuesAddressMetadata>();
Assert.NotNull(routeValuesAddressMetadata); Assert.NotNull(routeValuesAddressMetadata);
Assert.Equal("namedRoute", routeValuesAddressMetadata.Name); Assert.Equal("namedRoute", routeValuesAddressMetadata.Name);
@ -438,7 +439,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
}, },
(ep) => (ep) =>
{ {
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep); var matcherEndpoint = Assert.IsType<RouteEndpoint>(ep);
var routeValuesAddressMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteValuesAddressMetadata>(); var routeValuesAddressMetadata = matcherEndpoint.Metadata.GetMetadata<IRouteValuesAddressMetadata>();
Assert.NotNull(routeValuesAddressMetadata); Assert.NotNull(routeValuesAddressMetadata);
Assert.Equal("namedRoute", routeValuesAddressMetadata.Name); Assert.Equal("namedRoute", routeValuesAddressMetadata.Name);
@ -469,25 +470,25 @@ namespace Microsoft.AspNetCore.Mvc.Internal
endpoints, endpoints,
(ep) => (ep) =>
{ {
var matcherEndpoint = Assert.IsType<MatcherEndpoint>(ep); var matcherEndpoint = Assert.IsType<RouteEndpoint>(ep);
Assert.Equal("Home/Index/{id?}", matcherEndpoint.RoutePattern.RawText); 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<RouteEndpoint>(ep);
Assert.Equal("named/Home/Index/{id?}", matcherEndpoint.RoutePattern.RawText); 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<RouteEndpoint>(ep);
Assert.Equal("Products/Details/{id?}", matcherEndpoint.RoutePattern.RawText); 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<RouteEndpoint>(ep);
Assert.Equal("named/Products/Details/{id?}", matcherEndpoint.RoutePattern.RawText); Assert.Equal("named/Products/Details/{id?}", matcherEndpoint.RoutePattern.RawText);
Assert.Equal(2, matcherEndpoint.Order); Assert.Equal(2, matcherEndpoint.Order);
}); });
@ -589,7 +590,7 @@ 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<RouteEndpoint>(endpoint);
Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText); Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText);
AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults); AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults);
} }
@ -611,7 +612,7 @@ 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<RouteEndpoint>(endpoint);
Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText); Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText);
AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults); AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults);
} }
@ -634,7 +635,7 @@ 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<RouteEndpoint>(endpoint);
Assert.Equal("Foo/Bar/{subscription=general}", matcherEndpoint.RoutePattern.RawText); Assert.Equal("Foo/Bar/{subscription=general}", matcherEndpoint.RoutePattern.RawText);
AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults); AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults);
} }
@ -656,7 +657,7 @@ 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<RouteEndpoint>(endpoint);
Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText); Assert.Equal("Foo/Bar", matcherEndpoint.RoutePattern.RawText);
AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults); AssertIsSubset(expectedDefaults, matcherEndpoint.RoutePattern.Defaults);
} }

View File

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.ActionConstraints;
@ -369,11 +370,11 @@ namespace Microsoft.AspNetCore.Mvc.Routing
return httpContext; return httpContext;
} }
private static MatcherEndpoint CreateEndpoint(ActionDescriptor action) private static RouteEndpoint CreateEndpoint(ActionDescriptor action)
{ {
var metadata = new List<object>() { action, }; var metadata = new List<object>() { action, };
return new MatcherEndpoint( return new RouteEndpoint(
(r) => null, (context) => Task.CompletedTask,
RoutePatternFactory.Parse("/"), RoutePatternFactory.Parse("/"),
0, 0,
new EndpointMetadataCollection(metadata), new EndpointMetadataCollection(metadata),

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Matching; using Microsoft.AspNetCore.Routing.Matching;
@ -212,7 +213,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
} }
private static MatcherEndpoint CreateEndpoint(string template, ConsumesMetadata consumesMetadata) private static RouteEndpoint CreateEndpoint(string template, ConsumesMetadata consumesMetadata)
{ {
var metadata = new List<object>(); var metadata = new List<object>();
if (consumesMetadata != null) if (consumesMetadata != null)
@ -220,8 +221,8 @@ namespace Microsoft.AspNetCore.Mvc.Routing
metadata.Add(consumesMetadata); metadata.Add(consumesMetadata);
} }
return new MatcherEndpoint( return new RouteEndpoint(
(next) => null, (context) => Task.CompletedTask,
RoutePatternFactory.Parse(template), RoutePatternFactory.Parse(template),
0, 0,
new EndpointMetadataCollection(metadata), new EndpointMetadataCollection(metadata),

View File

@ -5,6 +5,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Matching; using Microsoft.AspNetCore.Routing.Matching;
using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.AspNetCore.Routing.Patterns;
@ -60,8 +62,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing
// Set the endpoint feature and current context just as a normal request to MVC app would be // Set the endpoint feature and current context just as a normal request to MVC app would be
var endpointFeature = new EndpointFeature(); var endpointFeature = new EndpointFeature();
urlHelper.ActionContext.HttpContext.Features.Set<IEndpointFeature>(endpointFeature); urlHelper.ActionContext.HttpContext.Features.Set<IEndpointFeature>(endpointFeature);
urlHelper.ActionContext.HttpContext.Features.Set<IRouteValuesFeature>(endpointFeature);
endpointFeature.Endpoint = endpoint1; endpointFeature.Endpoint = endpoint1;
endpointFeature.Values = new RouteValueDictionary endpointFeature.RouteValues = new RouteValueDictionary
{ {
["controller"] = "Orders", ["controller"] = "Orders",
["action"] = "GetById", ["action"] = "GetById",
@ -123,7 +126,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
protected override IUrlHelper CreateUrlHelper(string appRoot, string host, string protocol) protected override IUrlHelper CreateUrlHelper(string appRoot, string host, string protocol)
{ {
return CreateUrlHelper(Enumerable.Empty<MatcherEndpoint>(), appRoot, host, protocol); return CreateUrlHelper(Enumerable.Empty<RouteEndpoint>(), appRoot, host, protocol);
} }
protected override IUrlHelper CreateUrlHelperWithDefaultRoutes(string appRoot, string host, string protocol) protected override IUrlHelper CreateUrlHelperWithDefaultRoutes(string appRoot, string host, string protocol)
@ -139,8 +142,8 @@ namespace Microsoft.AspNetCore.Mvc.Routing
string template) string template)
{ {
var endpoints = GetDefaultEndpoints(); var endpoints = GetDefaultEndpoints();
endpoints.Add(new MatcherEndpoint( endpoints.Add(new RouteEndpoint(
next => httpContext => Task.CompletedTask, httpContext => Task.CompletedTask,
RoutePatternFactory.Parse(template), RoutePatternFactory.Parse(template),
0, 0,
EndpointMetadataCollection.Empty, EndpointMetadataCollection.Empty,
@ -153,10 +156,8 @@ namespace Microsoft.AspNetCore.Mvc.Routing
var httpContext = actionContext.HttpContext; var httpContext = actionContext.HttpContext;
httpContext.Features.Set<IEndpointFeature>(new EndpointFeature() httpContext.Features.Set<IEndpointFeature>(new EndpointFeature()
{ {
Endpoint = new MatcherEndpoint( Endpoint = new Endpoint(
next => cntxt => Task.CompletedTask, context => Task.CompletedTask,
RoutePatternFactory.Parse("/"),
0,
EndpointMetadataCollection.Empty, EndpointMetadataCollection.Empty,
null) null)
}); });
@ -187,7 +188,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
return CreateUrlHelper(actionContext); return CreateUrlHelper(actionContext);
} }
private IUrlHelper CreateUrlHelper(IEnumerable<MatcherEndpoint> endpoints, ActionContext actionContext = null) private IUrlHelper CreateUrlHelper(IEnumerable<RouteEndpoint> endpoints, ActionContext actionContext = null)
{ {
var serviceProvider = CreateServices(endpoints); var serviceProvider = CreateServices(endpoints);
var httpContext = CreateHttpContext(serviceProvider, null, null, "http"); var httpContext = CreateHttpContext(serviceProvider, null, null, "http");
@ -196,7 +197,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
} }
private IUrlHelper CreateUrlHelper( private IUrlHelper CreateUrlHelper(
IEnumerable<MatcherEndpoint> endpoints, IEnumerable<RouteEndpoint> endpoints,
string appRoot, string appRoot,
string host, string host,
string protocol) string protocol)
@ -207,9 +208,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing
return CreateUrlHelper(actionContext); return CreateUrlHelper(actionContext);
} }
private List<MatcherEndpoint> GetDefaultEndpoints() private List<RouteEndpoint> GetDefaultEndpoints()
{ {
var endpoints = new List<MatcherEndpoint>(); var endpoints = new List<RouteEndpoint>();
endpoints.Add( endpoints.Add(
CreateEndpoint( CreateEndpoint(
"home/newaction/{id}", "home/newaction/{id}",
@ -278,7 +279,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
return endpoints; return endpoints;
} }
private MatcherEndpoint CreateEndpoint( private RouteEndpoint CreateEndpoint(
string template, string template,
object defaults = null, object defaults = null,
object requiredValues = null, object requiredValues = null,
@ -292,9 +293,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing
new RouteValuesAddressMetadata(routeName, new RouteValueDictionary(requiredValues))); new RouteValuesAddressMetadata(routeName, new RouteValueDictionary(requiredValues)));
} }
return new MatcherEndpoint( return new RouteEndpoint(
next => (httpContext) => Task.CompletedTask, (httpContext) => Task.CompletedTask,
RoutePatternFactory.Parse(template, defaults, constraints: null), RoutePatternFactory.Parse(template, defaults, parameterPolicies: null),
order, order,
metadataCollection, metadataCollection,
null); null);
@ -315,11 +316,11 @@ namespace Microsoft.AspNetCore.Mvc.Routing
return services.BuildServiceProvider(); return services.BuildServiceProvider();
} }
private MatcherEndpoint GetEndpoint(string name, string template, RouteValueDictionary defaults) private RouteEndpoint GetEndpoint(string name, string template, RouteValueDictionary defaults)
{ {
return new MatcherEndpoint( return new RouteEndpoint(
next => c => Task.CompletedTask, c => Task.CompletedTask,
RoutePatternFactory.Parse(template, defaults, constraints: null), RoutePatternFactory.Parse(template, defaults, parameterPolicies: null),
0, 0,
EndpointMetadataCollection.Empty, EndpointMetadataCollection.Empty,
null); null);

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
namespace BasicWebSite namespace BasicWebSite
{ {

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
namespace RoutingWebSite namespace RoutingWebSite
{ {

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
namespace VersioningWebSite namespace VersioningWebSite
{ {